I built an environment for machine learning from scratch (windows10 + Anaconda + VSCode + Tensorflow + GPU version)

After a while, I had to reinstall the OS, so I rebuilt the environment. It is a memorandum at that time.

Overview

Preparing to use Tensorflow GPU version

The items are as follows.

The version is pretty important. If you use an unsupported version, you may need to set it separately or it may not work.

·reference

Check Gravo's Compute Capability and update drivers

It seems that Tensorflow is compatible with those with Compute Capability of 3.5 or higher. The correspondence table can be found here [https://developer.nvidia.com/cuda-gpus#compute). The grabber of this PC is NVIDIA GeForce GTX 1060, so it's 6.1.

If you can confirm it, keep the driver up to date. Driver page: https://www.nvidia.co.jp/Download/index.aspx?lang=jp

Installation of CUDA v10.0

Download page for CUDA v10.0: https://developer.nvidia.com/cuda-10.0-download-archive When selecting the installer, select "High speed (recommended)" and install by default.

By the way, at the time of writing (2019/11), v10.2 is the latest. However, when I insert v10.2, Tensorflow seems to refer to the path of v10.0, and I get the following error later.

> python -c "import tensorflow as tf; print(tf.__version__)"
2019-11-28 19:22:20.012829: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2.0.0

There seems to be a workaround, but I haven't tried it with priority on operation for the time being. Workaround: Additional procedure when you want to use with CUDA 10.1

Installing CuDNN

CuDNN download page: https://developer.nvidia.com/rdp/cudnn-download It's free, but membership registration is required. After logging in, download the following version corresponding to CUDA.

Download cuDNN v7.6.5 (November 5th, 2019), for CUDA 10.0

CuDNN is a zip file, so unzip it and poke it into the CUDA folder. By default, the CUDA folder is:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\

Install Anaconda

I've included Anaconda because I wanted to separate the environment for CPU and GPU. DL page: https://www.anaconda.com/distribution/

The installed Anaconda is as follows. (You don't have to worry about the version)

Anaconda 2019.10 for Windows Installer
Python 3.7 version

Add environment variables when installing. (The default is unchecked) Check ʻAdd Anaconda to my PATH environment variable in ʻAdvanced Options.

Since I have added environment variables, it may be better to restart after installation.

Creating an execution environment (python3.7)

Start Anaconda Navigator.

Program list → Anaconda3(64-bit) → Anaconda Navigater (Anaconda3)

Once launched, select Environments from the menu on the left and press Create. Here, we will build the environment for actual operation.

--Set value --Name: Feel free (here, py37-gpu) --Select python 3.7 for Package. (About half a year ago, Tensorflow didn't work in 3.7, but it seems to have been supported.)

Press Create to create the environment.

When the environment is created, click (py37-gpu), then click ▶ → select ʻOpen Terminal`. Then Terminal will start.

If you want to add a package with pip etc. in the future, follow this procedure. (There seems to be an easier way ...)

Install Tensorflow

・ When using CPU

> pip install tensorflow

・ When using GPU

> pip install tensorflow-gpu

Verification

Check Tensorflow

Enter the following command in Terminal. (One liner)

> python -c "import tensorflow as tf; print(tf.__version__)"

・ CPU version display result

>python -c "import tensorflow as tf; print(tf.__version__)"
2.0.0

-GPU version display result (dll must be Successfully)

> python -c "import tensorflow as tf; print(tf.__version__)"
2019-11-28 19:59:12.696817: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2.0.0

Check GPU device (GPU version only)

Enter the following command in Terminal.

> python
>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()

This is the execution result.

(py37-gpu) C:\Users\poco> python
Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> from tensorflow.python.client import device_lib
2019-11-28 21:33:00.714942: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
>>>
>>>
>>> device_lib.list_local_devices()
2019-11-28 21:33:05.777537: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-11-28 21:33:05.790386: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2019-11-28 21:33:05.813090: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1060 3GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085
pciBusID: 0000:01:00.0
2019-11-28 21:33:05.818802: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-11-28 21:33:05.823869: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-11-28 21:33:06.275014: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-11-28 21:33:06.279606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0
2019-11-28 21:33:06.282091: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N
2019-11-28 21:33:06.285366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 2108 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 15688037898080382701
, name: "/device:GPU:0"
device_type: "GPU"          #If the GPU is displayed, k
memory_limit: 2210712780
locality {
  bus_id: 1
  links {
  }
}
incarnation: 506641733629436041
physical_device_desc: "device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1"
]

VSCode installation and configuration

I'm using VSCode as my IDE. DL page: https://code.visualstudio.com/

Extentions

After launching VSCode, you can add it by searching for each name from Extensions on the left menu.

name Remarks
Japanese Language Pack for Visual Studio Code I'm Japanese
Python For python

Other than this, please do as you like.

Anaconda and VSCode integration

There are many ways to do this, so this is just an example.

1. Create a folder

Create a working folder. In VSCode, specify a working folder with "File-> Open Folder".

2. Create a test file

Next, create an appropriate python file under the working folder. Describe hello world as a test file.

hello.py


import tensorflow as tf
msg = tf.constant('TensorFlow 2.0 Hello World')
tf.print(msg)

Then open this file in VSCode.

3. Description of configuration file

Execute "Menu-> Debug-> Add Configuration-> Python File". Then launch.json will open, so edit it.

However, I need to check the python path before editing, so check it with Anaconda. Open Anaconda's Terminal and run the conda info -e command.

(py37-gpu) C:\Users\poco> conda info -e
# conda environments:
#
base                     C:\Users\poco\Anaconda3
py37-cpu                 C:\Users\poco\Anaconda3\envs\py37-cpu
py37-gpu              *  C:\Users\poco\Anaconda3\envs\py37-gpu

I want to run python in the environment of the path specified here, so After checking, add " pythonPath " to launch.json as follows.

launch.json


{
    //You can use IntelliSense to learn the available attributes.
    //Hover and display the description of existing attributes.
    //Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",

            // ↓ python.Add and add exe
            "pythonPath": "C:\\Users\\poco\\Anaconda3\\envs\\py37-gpu\\python.exe"
        }
    ]
}

After adding it, save it and press F5 or "Debug-> Start Debugging" to see if hello world can be executed.

ChainerRL

This time I'll use ChainerRL instead of Keras-RL. The library of reinforcement learning seemed to be more complete here.

pip installation

Drop the required packages from Anaconda's Terminal. It is a package written before ([Reinforcement learning] OpenAI Gym x Keras-rl will implement reinforcement learning algorithm (preparation)). ..

# ChainerRL
> pip install chainerrl
> pip install cupy-cuda100  //For GPU, 100 is the version, so please match it with the version of CUDE.

# gym
> pip install gym
> pip install --no-index -f https://github.com/Kojoley/atari-py/releases atari_py

#Image system
> pip install matplotlib
> pip install pillow
> pip install opencv-python

#statistics
> pip install pandas

Afterword

For the time being, the environment construction has been completed. Next time I would like to do a tutorial on ChainerRL.

Recommended Posts

I built an environment for machine learning from scratch (windows10 + Anaconda + VSCode + Tensorflow + GPU version)
Rebuilding an environment for machine learning with Miniconda (Windows version)
Study method for learning machine learning from scratch (March 2020 version)
Create an environment for "Deep Learning from scratch" with Docker
I built a TensorFlow environment on windows10
[Windows 10] "Deep Learning from scratch" environment construction
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Build an interactive environment for machine learning in Python
Create a machine learning environment from scratch with Winsows 10
I tried to build an environment for machine learning with Python (Mac OS X)
Build an environment for machine learning using Python on MacOSX
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)
Created an environment for Anaconda & Jupyter
I easily built an operating environment for Python3 + Tornado on AWS EC2.
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Realize environment construction for "Deep Learning from scratch" with docker and Vagrant
Until the Deep Learning environment (TensorFlow) using GPU is prepared for Ubuntu 14.04
An introduction to OpenCV for machine learning
I created an Anaconda environment using Docker!
I installed TensorFlow (GPU version) on Ubuntu
An introduction to Python for machine learning
Creating a development environment for machine learning
Building an environment for "Tello_Video" on Windows
Prepare the environment for O'Reilly's book "Deep Learning from scratch" with apt-get (Debian 8)
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
How to install the deep learning framework Tensorflow 1.0 in the Anaconda environment of Windows
An introduction to machine learning for bot developers
For beginners to build an Anaconda environment. (Memo)
Machine learning starting from 0 for theoretical physics students # 1
Building an Anaconda environment for Python with pyenv
Machine learning starting from scratch (machine learning learned with Kaggle)
Machine learning starting from 0 for theoretical physics students # 2
[CodeIQ] I wrote the probability distribution of dice (from CodeIQ math course for machine learning [probability distribution])