Skip to content
tensorflow for ruby
Branch: master
Clone or download
Pull request Compare This branch is 1 commit ahead, 39 commits behind somaticio:master.



This repository contains a Ruby API for utilizing TensorFlow.

| Linux CPU | Linux GPU PIP | Mac OS CPU | |-------------------|----------------------|------------------|----------------| | Build Status | Not Configured | Not Configured |

Code Climate Join the chat at Inline docs


Everything is at RubyDoc. You can also generate docs by bundle exec rake doc.

Blog Posts

  1. Introductory blog post
  2. Developers blog post
  3. Image Recognition Tutorial



It's easiest to get started using the prebuilt Docker container.


docker run --rm -it nethsix/ruby-tensorflow-ubuntu:0.0.1 /bin/bash


cd /repos/tensorflow.rb/
bundle exec rspec

Image Classification Tutorial:

cd /repos/tensorflow.rb/image/

For more details about all the fun machine-learning stuff already pre-installed, see:

Outside of Docker

Alternatively, you can install outside of a Docker container by following the following steps.

Explicit dependencies


All the dependencies mentioned above must be installed in your system before you proceed further.

Clone and Install TensorFlow

This package depends on the TensorFlow shared libraries, in order to compile these libraries do the following:

git clone --recurse-submodules
cd tensorflow

This command clones the repository and a few sub modules. After this you should do:

bazel build -c opt //

This command takes in the order of 10-15 minutes to run and creates a shared library. When finished, copy the newly generated shared library:

# Linux
sudo cp bazel-bin/tensorflow/ /usr/lib/

sudo cp bazel-bin/tensorflow/ /usr/local/lib
export LIBRARY_PATH=$PATH:/usr/local/lib (may be required)

Install tensorflow.rb

Clone and install this Ruby API:

git clone
cd tensorflow.rb/ext/sciruby/tensorflow_c
ruby extconf.rb
make install # Creates ../lib/ruby/site_ruby/X.X.X/<arch>/tf/Tensorflow.bundle (.so Linux)
cd ./../../..
bundle exec rake install

The last command is for installing the gem.

Run tests and verify install

bundle exec rake spec

This command is to run the tests.

Install Script

I have also made a make shift install script in tools directory. You are free to use it, but it still needs some work and its best if you follow the installation procedure above or use docker. You are welcome to make improvements to the script.


You can run tensorboard on tensorflow.rb too. Just take a look at file.


Copyright (c) 2016, Arafat Dad Khan. somatic

All rights reserved.


You can’t perform that action at this time.