Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Basic Usage tutorial in Ruby #68

Open
chrhansen opened this issue Aug 28, 2016 · 14 comments
Open

Create Basic Usage tutorial in Ruby #68

chrhansen opened this issue Aug 28, 2016 · 14 comments
Milestone

Comments

@chrhansen
Copy link
Collaborator

Redo the Basic Usage Python tutorial in Ruby. Probably a few of the features from the Python-tutorial will not be available for the 0.1.0 Milestone (e.g. tf.InteractiveSession()), and can be skipped, but the basics of creating ops, evaluating/feeding tensors etc. should be shown.

@chrhansen chrhansen added this to the 0.1.0 milestone Aug 28, 2016
@arbox
Copy link

arbox commented Dec 20, 2016

@chrhansen I'll do that by the mid January.

@chrhansen
Copy link
Collaborator Author

@arbox sounds great!

@arbox
Copy link

arbox commented Jan 9, 2017

Hi @chrhansen I've just started to collect sources for the tutorial and wonder where should I put them in this repository. Some tutorial.md under the root? The doc folder?

@abinashmeher999
Copy link

@arbox An IRuby notebook might be better suited for this.

@arbox
Copy link

arbox commented Jan 9, 2017

@abinashmeher999 but still where? :) Linked throught nbviewer?

@abinashmeher999
Copy link

The maintainers would be better able to answer where to keep it. For symengine.rb we have a folder named notebooks under the root folder where they are kept. And also you can open any publicly available notebook on github through nbviewer. There isn't any explicit procedure to link them.

@arafatkatze
Copy link
Collaborator

Sorry for the late reply guys.
@abinashmeher999 Thanks for the advice, Iruby is certainly very cool and useful for this.
@arbox I think you could do something very similar and make a notebooks folder and send a Pr. An iruby example like this seems very cool and useful.

Also, I just wanted to mention that the latest version of tensorflow does not support tensorflow rb and that is because tensorflow made many changes to the C API to make it very generic. Currently I am making many changes in my own clone of Tensorflow for a much faster version of Tensorflow.rb compatible with the latest tensorflow C API. I will be sending a pr when the whole thing is done and the tests are passing. But if you have time, please do make the tutorial with by downloading release 0.9.0 and then working with it. I will also update your tutorial if needed. Feel free to email me([email protected]) if you face any issues.

Thanks

@Zigngit
Copy link

Zigngit commented Apr 7, 2017

I tried your install.sh on brand new ubuntu 16.04 server, and it works like a charm.
Basically, I should have done every thing the same as that script manually on the previous try. Maybe I need some time to figure out exactly what caused the problem.

But I still get a crash when using image_classify.rb with a retrained pb file from the tensorflow tutorials. I think that should be the "not support" problem you mentioned above.

For the error message below,
No Operation with the name input exists.
No Operation with the name output exists.

I replaced the 'input' with 'Mul' and the 'output' with 'final_result', it worked, but libtensorflow.so still crashed.

BTW, I like the new tensorflow C API, because it is much faster than the previous version.

@arafatkatze
Copy link
Collaborator

arafatkatze commented Apr 7, 2017

@Zigngit Thanks for doing this.
Did you download the pb file from this link https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip ?
I am sorry but the pb file in this link is different from the pb file in the medium tutorial, I just updated the tutorial with the new link.

@Zigngit
Copy link

Zigngit commented Apr 7, 2017

[https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip] this one works perfect.

But I would like to use a retrained one. I followed this tutorial and the generate a output_graph.pb , and it cant work with the image_classify.rb
https://www.tensorflow.org/tutorials/image_retraining

@Zigngit
Copy link

Zigngit commented Apr 7, 2017

I also tried retrained model with an older version libtensorflow.so and tensorflow.rb.
It also crashed.

root@mt4:~/tensorflow.rb/image# ruby retrain.rb
Trying to classify image file: mysore_palace.jpg
/usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:103: [BUG] Segmentation fault at 0x00000000000017
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0007 p:---- s:0044 e:000043 CFUNC :tensor_size
c:0006 p:0016 s:0040 e:000039 METHOD /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:103
c:0005 p:0010 s:0033 e:000032 BLOCK /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:42 [FINISH]
c:0004 p:---- s:0029 e:000028 CFUNC :each
c:0003 p:0138 s:0026 e:000025 METHOD /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:41
c:0002 p:0213 s:0013 E:0024d8 EVAL retrain.rb:40 [FINISH]
c:0001 p:0000 s:0002 E:000540 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
retrain.rb:40:in <main>' /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:41:in run'
/usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:41:in each' /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:42:in block in run'
/usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:103:in convert_value_for_output_array' /usr/local/lib/ruby/gems/2.3.0/gems/tensorflow-0.0.1/lib/tensorflow/session.rb:103:in tensor_size'

-- Machine register context ------------------------------------------------
RIP: 0x00007f961324c414 RBP: 0x00007ffc0bd934e0 RSP: 0x00007ffc0bd934d0
RAX: 0x0000000000000017 RBX: 0x0000000000000000 RCX: 0x0000000000000000
RDX: 0x00007f961985afe0 RDI: 0x0000000000000008 RSI: 0x00007ffc0bd936e8
R8: 0x00007f9619625770 R9: 0x00007f961c5723f8 R10: 0x00007f961bd09e90
R11: 0x00007f961c807a60 R12: 0x00007f961cbe9800 R13: 0x0000000000000000
R14: 0x00007f961c66b840 R15: 0x0000000000000001 EFL: 0x0000000000010216

@joegyoung
Copy link

I have success following --> https://www.tensorflow.org/tutorials/image_retraining
I changed the input to 'Mul' and output to 'final_result'

I also changed the input operations to

input = Const(scope_class, image_file)
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('ReadFile', 'ReadFile', nil, [input]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('DecodeJpeg', 'DecodeJpeg', Hash['channels' => 3], [output.output(0)]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('Cast', 'Cast', Hash['DstT' => 1], [output.output(0)]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('ExpandDims', 'ExpandDims', nil, [output.output(0), Const(scope_class.subscope('make_batch'), 0, :int32)]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('ResizeBilinear', 'ResizeBilinear', nil, [output.output(0), Const(scope_class.subscope('size'), [299, 299], :int32)]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('Sub', 'Sub', nil, [output.output(0), Const(scope_class.subscope('mean'), 117.00, :float)]))
output = input.operation.g.AddOperation(Tensorflow::OpSpec.new('Mul', 'Mul', nil, [output.output(0), Const(scope_class.subscope('scale'), 1.00, :float)])).output(0)
graph = scope_class.graph
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
out_tensor = session.run({}, [output], [])

I changed the input operations by matching the them to the graph in tensorboard.

@arafatkatze
Copy link
Collaborator

@joegyoung Thanks a lot for this.

@LWFlouisa
Copy link

There end up being any usage tutorials?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants