Skip to content

Latest commit

 

History

History
83 lines (79 loc) · 7.35 KB

File metadata and controls

83 lines (79 loc) · 7.35 KB

Set up Tensorflow

Most of the projects in this Git will use Tensorflow with Keras as a tool to implement various Deep Neural Networks. In this project, I will guide you how to set up the environment for Python on Windows.

TensorFlow™ is an open source software library for high performance numerical computation. Its flexible architecture allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters of servers to mobile and edge devices. Originally developed by researchers and engineers from the Google Brain team within Google’s AI organization, it comes with strong support for machine learning and deep learning and the flexible numerical computation core is used across many other scientific domains.

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano. It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.

References

Steps

Step 1. Install Anaconda and Python 3.6

  • If you want Microsoft Visual Studio to handle Anaconda and Python components, you can use Visual Studio Installer and install this component:

    • Anaconda3 32/64-bit (5.1.0)
  • Otherwise, you can just download Anaconda (Python 3.6 version)

Step 2. Install Tensorflow

  1. Open Anaconda Prompt
    Just search in the Start menu. Note: This prompt is different from normal Command Prompt (cmd)
  2. (Optional) Create an environment for Tensorflow
    A conda environment is a directory that contains a specific collection of conda packages that you have installed. If you change one environment, your other environments are not affected. You can easily switch between environments. You can also share your environment with someone by giving them a copy of yours.
    • Enter the command below to create an environment with the name tensorflow.
      conda create -n tensorflow python=3.6 numpy scipy matplotlib spyder cython
    • Enter the command below to activate the environment.
      activate tensorflow
  3. Install Tensorflow
    1. CPU Version
      • Enter the command below to install. This will automatically select an official version from Google and install it for you.
        pip install --ignore-installed --upgrade tensorflow
    2. GPU Version
      1. Check for supported GPU in NVIDIA CUDA GPUs
        Make sure you find your GPU model in the lists and the Compute Capability must be at least 3.0 or else you're out of luck.
      2. Download and install CUDA Toolkit
        Current Tensorflow only supports CUDA Toolkit 9.0. For different version, you will need to re-compile Tensorflow from the source. I currently use version 9.2.
      3. Download and extract cuDNN
        Membership registration is required. Choose the version that suits your OS and CUDA Toolkit version. When extracting the files, remeber the cuDNN path to which you're extracting.
      4. Add the cuDNN path to Environment PATH
        The path to add is as follow (extract_path)\cuda\bin. Tutorials can be found online, you can follow this one. To check if PATH is added, close all prompts then open a new Anaconda Prompt and enter the command below and see if the path is in the output result.
        echo %PATH%
      5. Install Tensorflow with GPU support.
        • If you installed CUDA Toolkit 9.0, enter the command below
          pip install --ignore-installed --upgrade tensorflow-gpu
        • Otherwise, you have to re-compile Tensorflow from the source OR follow this step.
  4. Wait for the installation to finish.

Step 3. Verify Tensorflow installation

  1. From the current Anaconda Prompt, enter the command below to invoke Python:
    python
  2. Enter the commands below to verify Tensorflow:
    import tensorflow as tf
    hello = tf.constant('Hello, TensorFlow!')
    sess = tf.Session()
    print(sess.run(hello))
    
    • The import tensorflow as tf is to import Tensorflow. This line can take some time to complete. If everything is correct, nothing will show up and the prompt will wait for another command.
      • If there's a warning Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2. That means your CPU supports AVX but you've picked the wrong Tensorflow binary of which it was compiled to make use. You should run normally without any problems, but I recommend you use the correct one.
      • If there's an error ImportError: DLL load failed, you've installed the wrong version of Tensorflow. For the right one, you have to re-compile Tensorflow from the source OR follow this step.
    • The hello = tf.constant('Hello, TensorFlow!') will create a simple variable using Tensorflow.
    • The sess = tf.Session() will create a session upon which Tensorflow will operate. If everything is correct, the prompt will tell you about the info of the CPU/GPU it will use. This will take some time to complete.
    • The print(sess.run(hello)) will print out the value of hello which is supposed to be b'Hello, TensorFlow!'.
  3. Enter the command below to exit python from shell.
    exit()

Step 4. Install Keras

  1. Make sure you are on Anaconda Prompt with tensorflow environment activated. Enter the command below to install Keras:
    pip install keras
  2. Wait for the installation to complete.

Sub-Steps

  1. Find a suitable .whl file in the git.
  2. Copy the link of the file and replace /blob from the link to /raw. The link should end with .whl file extenstion and contains no /blob.
  3. Open Anaconda Prompt and activate the environment if neccessary.
  4. Enter the command below to install. Remember to replace [the link] with the modified link.
    pip install --ignore-installed --upgrade [the link]

Add to Environment Path

  1. Search for environment variables on Start menu.
  2. On System Properties popup, click the last button Environment Variables.
  3. On Environment Variables popup, in System variables combobox, select Path and hit the Edit button.
  4. On Edit environment variables popup, hit the New button and copy/paste in the path.
  5. Click OK for any popups showing up to complete. Note: If you hit Cancel then you have to redo the steps.

Please cite this repository if you find this helpful in your work. Thank you.