Ruby bindings for Tensorflow.
First you'll need to install Tensorflow 2. You can either do a full installation or just install Tensorflow for C. In both cases, you'll need to make sure the tensorflow library is on the system PATH so the Ruby bindings can load it.
Next install the gem:
gem install 'tensorflow-ruby'
The Ruby bindings are on built on top of TensorFlow's [C API] (https://github.com/tensorflow/docs/blob/master/site/en/r1/guide/extend/bindings.md) which provides access to some, but not all, of TensorFlow's functionality. The Ruby bindings are designed to mimic the Python API. Just like the Python bindings, Ruby defaults to eager execution mode.
Feature | Status |
---|---|
Run a predefined Graph | Implemented |
Graph construction with generated op functions | Implemented |
Gradients | Implemented |
Functions | Implemented |
Trainers | Gradient Descent Implemented |
Data API | 80% Implemented |
Tensorboard Support | Implemented |
Control Flow | Not Implemented |
Gradient Tape | Not Implemented |
Keras | Not Implemented |
To learn how to use the library:
Constants are
a = Tf.constant([1, 2, 3])
b = Tf.constant([4, 5, 6])
a + b
v = Tf::Variable.new(0.0)
w = v + 1
Tf::Math.abs([-1, -2])
Tf::Math.sqrt([1.0, 4.0, 9.0])
# load
train_dataset = Tf::Data::Dataset.from_tensor_slices([train_examples, train_labels])
test_dataset = Tf::Data::Dataset.from_tensor_slices([test_examples, test_labels])
# shuffle and batch
train_dataset = train_dataset.shuffle(100).batch(32)
test_dataset = test_dataset.batch(32)
# iterate
train_dataset.each do |examples, labels|
# ...
end
Everyone is encouraged to help improve this project. Here are a few ways you can help:
To get started with development and testing:
git clone https://github.com/cfis/tensorflow-ruby.git
cd tensorflow-ruby
bundle install
rake test