ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - ankane/tensorflow-ruby: Deep learning for Ruby
Deep learning for Ruby. Contribute to ankane/tensorflow-ruby development by creating an account on GitHub.
Visit Site

GitHub - ankane/tensorflow-ruby: Deep learning for Ruby

GitHub - ankane/tensorflow-ruby: Deep learning for Ruby

TensorFlow Ruby

:fire: TensorFlow - the end-to-end machine learning platform - for Ruby

This gem is currently experimental and only supports basic tensor operations at the moment. Check out Torch.rb for a more complete deep learning library.

To run a TensorFlow model in Ruby, convert it to ONNX and use ONNX Runtime. Check out this tutorial for a full example.

Build Status

Installation

Install TensorFlow. For Homebrew, use:

brew install libtensorflow

Add this line to your application’s Gemfile:

gem "tensorflow"

Getting Started

This library follows the TensorFlow 2 Python API. Many methods and options are missing at the moment. Here’s the current plan. Additional PRs welcome!

Constants

a = Tf.constant([1, 2, 3])
b = Tf.constant([4, 5, 6])
a + b

Variables

v = Tf::Variable.new(0.0)
w = v + 1

Math

Tf::Math.abs([-1, -2])
Tf::Math.sqrt([1.0, 4.0, 9.0])

FizzBuzz

def fizzbuzz(max_num)
  max_num.times do |i|
    num = Tf.constant(i + 1)
    if (num % 3).to_i == 0 && (num % 5).to_i == 0
      puts "FizzBuzz"
    elsif (num % 3).to_i == 0
      puts "Fizz"
    elsif (num % 5).to_i == 0
      puts "Buzz"
    else
      puts num.to_i
    end
  end
end

fizzbuzz(15)

Data::Dataset

# 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

Keras [coming soon]

mnist = Tf::Keras::Datasets::MNIST
(x_train, y_train), (x_test, y_test) = mnist.load_data
x_train = x_train / 255.0
x_test = x_test / 255.0

model = Tf::Keras::Models::Sequential.new([
  Tf::Keras::Layers::Flatten.new(input_shape: [28, 28]),
  Tf::Keras::Layers::Dense.new(128, activation: "relu"),
  Tf::Keras::Layers::Dropout.new(0.2),
  Tf::Keras::Layers::Dense.new(10, activation: "softmax")
])

model.compile(optimizer: "adam", loss: "sparse_categorical_crossentropy", metrics: ["accuracy"])
model.fit(x_train, y_train, epochs: 5)
model.evaluate(x_test, y_test)

TensorFlow Installation

Mac

Run:

brew install tensorflow

Alternatively, download the shared library and move the files in lib to /usr/local/lib.

Linux

Download the shared library and move the files in lib to /usr/local/lib.

Windows

Download the shared library and move tensorflow.dll to C:\Windows\System32.

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/tensorflow-ruby.git
cd tensorflow-ruby
bundle install
bundle exec rake test

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory