TFLearn: A Simplified Interface for TensorFlow

Link: http://tflearn.org

TFlearn is a modular and transparent deep learning library built on top of Tensorflow. It was designed to provide a higher-level API to TensorFlow in order to facilitate and speed-up experimentations, while remaining fully transparent and compatible with it.

TFLearn features include:

  • Easy-to-use and understand high-level API for implementing deep neural networks, with tutorial and examples.
  • Fast prototyping through highly modular built-in neural network layers, regularizers, optimizers, metrics…
  • Full transparency over Tensorflow. All functions are built over tensors and can be used independently of TFLearn.
  • Powerful helper functions to train any TensorFlow graph, with support of multiple inputs, outputs and optimizers.
  • Easy and beautiful graph visualization, with details about weights, gradients, activations and more…
  • Effortless device placement for using multiple CPU/GPU.

The high-level API currently supports most of recent deep learning models, such as Convolutions, LSTM, BiRNN, BatchNorm, PReLU, Residual networks, Generative networks… In the future, TFLearn is also intended to stay up-to-date with latest deep learning techniques.

Quick overview

Code Example

# Classification
tflearn.init_graph(num_cores=8, gpu_memory_fraction=0.5)

net = tflearn.input_data(shape=[None, 784])
net = tflearn.fully_connected(net, 64)
net = tflearn.dropout(net, 0.5)
net = tflearn.fully_connected(net, 10, activation=’softmax’)
net = tflearn.regression(net, optimizer=’adam’, loss=’categorical_crossentropy’)

model = tflearn.DNN(net)
model.fit(X, Y)

 

# Sequence Generation
net = tflearn.input_data(shape=[None, 100, 5000])
net = tflearn.lstm(net, 64)
net = tflearn.dropout(net, 0.5)
net = tflearn.fully_connected(net, 5000, activation=’softmax’)
net = tflearn.regression(net, optimizer=’adam’, loss=’categorical_crossentropy’)

model = tflearn.SequenceGenerator(net, dictionary=idx, seq_maxlen=100)
model.fit(X, Y)
model.generate(50, temperature=1.0)

There are many more examples available here.

Where to Start?

To install TFLearn, see: Installation Guide.

If your version of Tensorflow is under 0.7: Upgrade Tensorflow.

For a tutorial: Getting Started with TFLearn.

For more examples: Examples List.

To browse the API, check the API Documentation.

 

Model Visualization

Graph

 

Loss & Accuracy (multiple runs)

Layers

 

Sources

GitHub: https://github.com/tflearn/tflearn

 

Contributions

This is the first release of TFLearn, if you find any bug, please report it in the GitHub issues section.

Improvements and requests for new features are more than welcome! Do not hesitate to twist and tweak TFLearn, and send pull-requests.

 

License

MIT License

Read More

Install Tensorflow with cuda 3.0 compute compatibility devices

This tutorial will explain you how to setup Tensorflow with cuda 3.0 compute compatibility devices (such as NVIDIA Grid K520, GTX580, GTX650, GTX770, GTX780…)

Basically, You need to use that specific build of Tensorflow if you encounter this kind of error message:

tensorflow/core/common_runtime/gpu/gpu_device.cc:611] Ignoring gpu device (device: 0, name: GRID K520, pci bus id: 0000:00:03.0) with Cuda compute capability 3.0. The minimum required Cuda capability is 3.5.

1 – Install Bazel

First, you need to install Bazel. I recommend to use Bazel 0.1.0, because some other builts raise errors when compiling Tensorflow.

1.1 – Setup Java JDK-8
Bazel requires java jdk-7 or 8. Follow the steps to install it:

Ubuntu (14.04)

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

Ubuntu (15.10)

$ sudo apt-get install openjdk-8-jdk

1.2 – Install other dependencies

$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip

1.3 – Download Bazel 0.1.0
https://github.com/bazelbuild/bazel/releases/download/0.1.0/bazel-0.1.0-installer-linux-x86_64.sh

1.4 – Compile Bazel

$ chmod +x bazel-version-installer-os.sh
$ ./bazel-version-installer-os.sh --user

Bazel executable is located at: $HOME/bin/bazel

2 – Install Tensorflow

2.1 – Install dependencies

$ sudo apt-get install python-numpy swig python-dev wheel git

2.2 – Download Tensorflow 0.7.0

$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git -b 0.7.0

2.3 – Compile Tensorflow

Configurate tensorflow built with cuda 3.0 compute capability

$ cd tensorflow
$ TF_UNOFFICIAL_SETTING=1 ./configure

Indicate basic settings according to your config.
For cuda compute compatibility, enter: 3.0

Compile tensorflow

$ $HOME/bin/bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
$ bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu

After compiling, you should get that output:

000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]

3 – Install Python interface

If you are planning to use tensorflow python interface, you first need to create a pip package to install it.

3.1 Create pip package

First step is to use bazel to create pip package

$ $HOME/bin/bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

3.2 Install python tensorflow

We can then use that pip package to install tensorflow in python

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

# The name of the .whl file will depend on your platform.
$ pip install /tmp/tensorflow_pkg/tensorflow-0.6.0-cp27-none-linux_x86_64.whl

3.3 Test it

To check if everything is working well, you can run that example:

$ cd tensorflow/models/image/mnist
$ python convolutional.py
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Initialized!
Epoch 0.00
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Epoch 0.12
Minibatch loss: 3.285, learning rate: 0.010000
Minibatch error: 6.2%
Validation error: 7.0%
...
...

If you meet any difficulty you can leave a comment!

Read More

TensorFlow Tutorial for beginners

Here are some simple tutorial to discover TensorFlow.

Link: https://github.com/aymericdamien/TensorFlow-Examples

This tutorial is designed to easily dive into TensorFlow through examples. Basic calculation examples and famous machine learning algorithms (such as Regression, Nearest Neighbor, Neural Network, Convolutional Neural Network) are implemented, with code explanation.

Tutorial Index:

1 – Introduction

– Hello World
– Basic Operations

2 – Basic Classifiers

– Nearest Neighbor
– Linear Regression
– Logistic Regression

3 – Neural Networks

– Multilayer Perceptron
– Convolutional Neural Network
– AlexNet
– Reccurent Network

4 – Multi GPU

– Basic Operations on multi-GPU

5 – User Interface (Tensorboard)

– Graph Visualization
– Loss Visualization

If you have any question, you can leave a comment or open an issue on github 🙂

Read More