(general) deep learning environment construction: tensorflow installation tutorial and common error resolution

Time:2020-1-17

Different from the “handgrip” of other introductory tutorials, this article emphasizes “cause” rather than “effect”. The reason why I add “general” is that after you understand the development environment, you will not make those very low mistakes.
We all know that deep learning involves a large number of models and algorithms. Looking at those messy formula symbols, we must have “WTF” in mind. What I want to say is that you don’t have to worry about all these things. It’s said that there must be a way for a car to get to the front of the mountain.

Installation package required

Usually, my habit is to contact a new technology in the simplest way, and try to get rid of the involvement of new (edge) technology. If the learning tree continues to expand due to some other factors, it will become very inefficient, so we go straight to the core. Take the most commonly used Windows environment as an example.
Here towindows7+TensorFlow-gpu1.5+cuda8+cudnn6+anaconda5+python3.6For example. The GPU version is highly recommended here, because deep learning can run in 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 versionLegacy Releases。 The CUDA library referenced by tensorflow code mustAbsolute matchingFor example, tensorflow1.3-1.5 all use cuda8 libraries. Currently (2017-10-24 20:40:53) cuda9 libraries are not supported.
    Here is a patch about cuda8, which fixes some bugs of 8.0 http://developer2.download.nvidia.com/compute/cuda/8.0/secure/prod2/patches/2/cuda_.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:
    As for the above reasons, please match version 6.0.
  3. tensorflow https://github.com/tensorflow/tensorflow:
    The reason why I give the address of GitHub is that tensorflow team builds GitHub at 12:34 every day, and GitHub is not affected by “various” network factors. Find the GPU build history corresponding to Python 3.6 in tensorflow, and find the address of the what 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 convenient to install various Python libraries.

Installation package relationship

Anaconda is the container that tensorflow runs in. Anaconda can create multiple “boxes” (environments), and the environments in each box do not interfere with each other, so using Anaconda can install Python 3.5 / 3.6 and tensorflow 1.3 / 1.5 at the same time.
CUDA and cudnn are the necessary libraries for tensorflow to call GPU. That is to say, tensorflow must call GPU of computer through CUDA and cudnn.
(general) deep learning environment construction: tensorflow installation tutorial and common error resolution

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 CUDA’s development directory toCUDA_HOMEMedium.
  3. After extracting the cudnn, copy the file to the CUDA directory.

Install tensorflow

  1. Start anaconda, clickenvironments(environment), clickcreate(New), namingtensorflow-gpuSelect3.6Edition.
  2. Click tensorflow GPU to startOpen TerminalInputactivate tensorflow-gpu。 Now, AnacondaEnvironment called tensorflow GPUIt’s already started. Now we are really starting to install tensorflow.
  3. input
    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

After a while, tensorflow is installed successfully.

Test tensorflow environment

  1. Click the environment we created under Anacondatensorflow-gpustart-upOpen With Python
  2. inputimport tensorflowIf no error is reported, the installation is successful.

Common mistakes

  1. Importerror: DLL load failed: the specified module could not be found. This error is usually the version of CUDA or cudnn corresponding to tensorflow. 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 and search within the projectTF_CUDA_VERSIONandTF_CUDNN_VERSIONYou will see which CUDA and cudnn version the current tensorflow corresponds to.
  2. Other errors.
    I haven’t encountered any other errors except 1. If there is a troubleshooting idea, confirm that the version > confirms whether the library is included in the path. If it still can’t be solved, you can add my wechattakeurhandDiscussion.

Running the MNIST example

  1. When running the MNIST example, you need to install the Matplotlib library. At this time, the convenience of anaconda is reflected. Click under Anacondatensorflow-gpuEnvironment, search 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 extract it.
  3. Start under Anacondatensorflow-gpuEnvironmental ScienceOpen TerminalInputactivate tensorflow-gpu, CD to step 2 extract the directory.
  4. implementpython mnist_xx.py
    (general) deep learning environment construction: tensorflow installation tutorial and common error resolution

Recommended Today

Summary: NPM common commands and operations

The full name of NPM is (node package manager), which is a package management and distribution tool installed with nodejs. It is very convenient for JavaScript developersDownload, install, upload and manage installed packages。 First of all, the following variables will be used: < name > | < PKG > module name < version > version […]