(General) Deep learning environment construction: tensorflow installation tutorial and common error resolution

Different from the "hand-in-hand" approach of other introductory tutorials, this article emphasizes "cause" rather than "effect". I added the word "universal" because after you understand the development environment, you won't make those very low mistakes.
Everyone knows that deep learning involves a large number of models and algorithms. Looking at those messy formula symbols, I must be "WTF" in my heart. What I want to say is that you don't care about these, the so-called car must have a way to the front of the mountain.

Required installation package

Usually in my habit, it is the easiest way to contact a new technology, and try to abandon the intervention of new (edge) technology. If the learning tree is continuously expanded due to some other factors, it will become inefficient. , so we hit the core. Take the most commonly used Windows environment as an example.
Here is an example of windows7+TensorFlow-gpu1.5+cuda8+cudnn6+anaconda5+python3.6 . The GPU version is highly recommended here, because deep learning runs the market for hours, days, and weeks, and GPU acceleration will save you a lot of time (even electricity).
1. cuda_8.0.61_windows.exe http://developer2.download.nvidia.com/compute/cuda/8.0/secure/Prod2/local_installers/cuda_8.0.61_windows.exe :
To download from NIVDIA official website, you need to find the historical version Legacy Releases .
The cuda library referenced by the tensorflow code must absolutely match . For example, tensorflow 1.3-1.5 all use the cuda8 library. Currently (2017-10-24 20:40:53) the cuda9 library is not supported.
Here is a patch for cuda8 that fixes some bugs in 8.0 http://developer2.download.nvidia.com/compute/cuda/8.0/secure/Prod2/patches/2/cuda_8.0.61.2_windows.exe
2. cudnn-8.0-windows7-x64-v6.0.zip http://developer2.download.nvidia.com/compute/machine-learning/cudnn/secure/v6/prod/8.0_20170427/cudnn-8.0-windows7- x64-v6.0.zip :
For the same reason as above, please match the 6.0 version.
3. tensorflow https://github.com/tensorflow/tensorflow :
The reason I gave the address of github is because the tensorflow team has a build every day at 12:34 on github, and github is not affected by "various" network factors . Find the build history of the gpu version corresponding to python3.6 in tensorflow , and find the address of the whl file.
4. Anaconda3-5.0.0-Windows-x86_64.exe https://www.anaconda.com/download/ :
One of the biggest advantages of anaconda is that it is more convenient to install various python libraries.

installation package relationship

Anaconda is equivalent to the container that tensorflow runs. Anaconda can create multiple "boxes" (environments), and the environments in each box do not interfere with each other, so using anaconda, you can install python3.5/3.6 and tensorflow1.3/1.5 at the same time.
cuda and cudnn are the libraries required by tensorflow to call the gpu. That is to say, tensorflow must call the computer's gpu through cuda and cudnn.
write picture description here

Install

Install anaconda, anaconda, cuda, cudnn

  1. Anaconda, cuda, and cudnn can be installed. Environment variables are automatically configured during installation.
  2. However, you need to manually configure the development directory of cuda into CUDA_HOMEit.
  3. After decompressing cudnn, copy the files to the corresponding directory of cuda.

Install tensorflow

  1. Start anaconda, click environments , click create , name it tensorflow-gpu, and select a 3.6version.
  2. Click on tensorflow-gpu to start Open Terminal and enter activate tensorflow-gpu. At this time, the environment named tensorflow-gpu under anaconda has been started. Now we actually start installing tensorflow.
  3. Enter
    pip install --ignore-installed --upgrade http://ci.tensorflow.org/view/tf-nightly/job/tf-nightly-windows/M=windows-gpu,PY=36/lastSuccessfulBuild/artifact/cmake_build/tf_python/dist/tf_nightly_gpu-1.5.0.dev20171024-cp36-cp36m-win_amd64.whl
    Wait a moment for tensorflow to be installed successfully.

Test the tensorflow environment

  1. Click on the environment we created under anaconda to tensorflow-gpustart Open With Python
  2. If no error is reported, the import tensorflowinstallation is successful.

Common mistakes

  1. ImportError: DLL load failed: The specified module could not be found.
    This error is usually cuda or cudnn and tensorflow version corresponding error. It is recommended to download cuda8+cudnn6.
    Of course, these versions will be phased out over time, but this tutorial still applies. Find the tensorflow project on github, search in the project TF_CUDA_VERSIONand TF_CUDNN_VERSIONyou will see which cuda and cudnn versions correspond to the current tensorflow.
  2. other errors.
    Except for the error of 1, I have not encountered other errors for the time being. If there is an error, the idea is to confirm the version -> confirm whether the library is included in the path. If you still can't solve it, you can add me on WeChat to takeurhanddiscuss.

run the mnist example

  1. The matplotlib library needs to be installed to run the mnist example. At this time, the convenience of anaconda is reflected. Click the environment under anaconda tensorflow-gpu, then search for matplotlib on the right, check it and click apply.
  2. Download the mnist tutorial example on github https://github.com/martin-gorner/tensorflow-mnist-tutorial and unzip it.
  3. Start the Open Terminaltensorflow-gpu environment under anaconda , enter , and cd to the decompressed directory in step 2.activate tensorflow-gpu
  4. implementpython mnist_xx.py
    write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325436260&siteId=291194637