TensorFlow

From CCN Wiki
Jump to navigation Jump to search

TensorFlow is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them. The flexible architecture allows you to deploy computation to one or more CPUs or GPUs in a desktop, server, or mobile device with a single API. TensorFlow was originally developed by researchers and engineers working on the Google Brain Team within Google's Machine Intelligence research organization for the purposes of conducting machine learning and deep neural networks research, but the system is general enough to be applicable in a wide variety of other domains as well.

TensorFlow was designed for use in Python 3.0, but has been ported to C# and a few other languages. If you don't know any Python 3.0, or are coming from Python 2.0, this website (https://www.learnpython.org/) has some very succinct tutorials that don't take much time to run through.

Installation

You can find information for installing TensorFlow here: https://www.tensorflow.org/install/

Note, Ubuntu has more installation options than those described below. This section is mostly tailored for a Windows installation (which at the time of writing contains a few errors or omissions that you might not catch without some digging).

In short, if you want to utilize GPU multithreading (assuming you have a compatible GPU) you'll need to install NVIDIA CUDA 8.0 libraries, and cuDNN version 6.0 (incorrectly called 6.1 in the above link for Windows). CUDA 8.0 will first require the installation of Visual Studio 2015 (not specified in the link -- this can be found for free, but you need to make an account). The later versions of Visual Studio (e.g. 2017) are not currently supported. You'll also need Python 3 (3.5 or 3.6), of which there are multiple install options. If you already have an older version of Python and you don't want to risk collisions, you may want to install via Anaconda (or virtualenv for Ubuntu). Anaconda creates a virtual environment for Python to operate, and comes with the Spyder IDE, which is very similar to Matlab. However, you would be limited to operating within this environment. You'll want to make sure CUDA 8.0, cuDNN 6.0 (if you haven't dropped these files into the corresponding CUDA DIRs), and your Python scripts are in your path (%path% for Windows, or .bashrc for Ubuntu). Installing on Ubuntu also requires the libcupti-dev library. Now you can install TensorFlow with pip (or conda or virtualenv). The command may vary for doing so depending on your set-up (e.g. py -m pip install tensorflow-gpu OR python -m pip install tensorflow-gpu). If you decided to do a 'native' pip install of Python 3, you'll also want to find an IDE. You could just use Notepad, but it's not 1980 and there are way better and more efficient development tools. Rodeo (developed by yhat) is a good choice, it operates very much like R studio and Matlab (so it should be somewhat familiar if coming from those). Another option is Atom (with the hydrogen package), it's got some interesting tricks, but seems less useful for large data sets.

If you don't care about taking advantage of GPU acceleration, or have a dedicated machine for doing so, you can just skip ahead and install Python 3 (or 2.7, a final update of 2.0 to make it more compatible with 3.0, but isn't compatible with CUDA).

Using TensorFlow

In Progress... Unlike most other programming languages, Python has very few core functions and instead relies on modules selected by the user to perform particular functions. As such, you don't actually need to know a ton about Python except for basic syntax, vectors, how modules work, and how to structure blocks. Most of the functions you'll use for TensorFlow come from the package itself.

https://www.tensorflow.org/get_started/

Toy XOR Network