1

Tensorflow does not officially support Ruby. I was wondering how one can use tensorflow, full version (Python or JS), in a rails app.

While this is a general question, the answer may be of use to the community. No one has asked this and many people new to using other languages like Python in Rails would benefit.

Another way to state this question is what some of the successful companies using rails are doing to use tensorflow.

6
  • There is the non-official gem tensorflow.rb. Doesn't seem to have updated in a few months, but it is most likely the best approach to using TensorFlow in Ruby. Commented Jul 8, 2019 at 15:49
  • @jdehesa Can one instead call python script from rails to run tensorflow? Commented Jul 8, 2019 at 16:16
  • Well, yes, you can always call a Python script from Ruby. Or you can try with something like pycall.rb - see this issue. Note this requires you to have an available Python environment to run your program. Commented Jul 8, 2019 at 16:29
  • @jdehesa Thank you. So would you say calling python from rails is a better -- perhaps currently the only -- way to use full version of tensorflow with rails? Commented Jul 8, 2019 at 17:20
  • From what I'm seeing of tensorflow.rb, I think it might work with newer versions of the library. You just don't get the nicer functions from Python, and if you want to build a graph you have to do it at op level (e.g. see classify_image.rb). If you just want to load a saved model (see captcha.rb) it should be easy. You may decide what suits you best. Commented Jul 8, 2019 at 17:26

1 Answer 1

0

I'm only going by its readme, but the tensorflow ruby gem appears to be well supported.

This post shows how to use it to classify images

(I take directly from the article here)

Steps:

  • Clone and install tensorflow.rb
  • Go to image directory
  • Download this zip file from google
  • extract the file ‘tensorflow_inception_graph.pb’ in this directory.
  • Do ruby classify_image.rb (This will work on the default image of the Mysore palace).
  • To try this out on your own images you can add the image to this directory and then change file name in line 31 on classify_image.rb .
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.