somaticio / tensorflow.rb

tensorflow for ruby
BSD 3-Clause "New" or "Revised" License
829 stars 63 forks source link

Only latest constant defined was retrievable, make constants hash again #43

Closed chrhansen closed 8 years ago

chrhansen commented 8 years ago

@Arafatk It seemed to me that self.constants = was just set to latest constant. But please check.

Btw. should we even have special getters like .constants, .variables, this was not something I could find in the TensorFlow Python interface, https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python

chrhansen commented 8 years ago

@nethsix did something change in the Circle-CI build or the Docker image, I get the error

docker run -it nethsix/ruby-tensorflow-ubuntu:0.0.1.a /bin/bash -l -c "mkdir -p /repos/ruby-tensorflow/circle-ci && cd /repos/ruby-tensorflow/circle-ci && git clone $CIRCLE_REPOSITORY_URL && cd /repos/ruby-tensorflow/circle-ci/$CIRCLE_PROJECT_REPONAME && git fetch && git checkout $CIRCLE_BRANCH && git pull && bundle install && cd /repos/ruby-tensorflow/circle-ci/$CIRCLE_PROJECT_REPONAME/ext/sciruby/tensorflow_c && ruby extconf.rb && make && make install && cd /repos/ruby-tensorflow/circle-ci/$CIRCLE_PROJECT_REPONAME && bundle exec rake install && bundle exec rspec"

Unable to find image 'nethsix/ruby-tensorflow-ubuntu:0.0.1.a' locally
...
...
nethsix commented 8 years ago

@chrhansen The error message "Unable to find image 'nethsix/ruby-tensorflow-ubuntu:0.0.1.a' locally" is normal. It just means docker is trying to start a container based on the image but it could not find it locally, so it will download from the docker hub (takes ~1-2 minutes).

The actual error is usually the last few lines. For this case, it is 'error: pathspec 'pull/43' did not match any file(s) known to git.' It seems that CircleCI wanted to pull from a branch called 'pull/43' from 'https://github.com/Arafatk/tensorflow.rb'. You can check all these variables from CircleCI dashboard by expanding 'Start container'.

I think it works for me and Arafat because we setup CircleCI to run CI on our own repos (duh!). Thanks for reporting this.

nethsix commented 8 years ago

@chrhansen The problem should be fixed (https://github.com/Arafatk/tensorflow.rb/pull/46). Please try it out by merging the master into this branch and re-push.

nethsix commented 8 years ago

Regarding accessors for constants, and variables, I believe @chrhansen you are right. Sample code and output from python below. Note that accessing the constant never returns the actual value but rather just the shape. The values are only accessible in a InteractiveSession or Session.

>>> import tensorflow as tf
>>> a = tf.constant(5)
>>> a
<tf.Tensor 'Const:0' shape=() dtype=int32>
>>> b = tf.constant(10)
>>> y = a + b
>>> y
<tf.Tensor 'add:0' shape=() dtype=int32>
>>> sess = tf.InteractiveSession()
>>> sess.run(y)
15
>>> 
arafatkatze commented 8 years ago

@chrhansen @nethsix Thanks for this. Actually after defining the constant or variable the definition is pushed to the graph definition and can be seen in protobuf.txt(This is the protobuf file for this spec . Take a look at tensor content). By creating a hash with key(name) and value(tensor) we can access the tensor which was used to make the constant/ variable. I making a blog on this so that its easy to generate human readable protobuf file. Thanks for the pr.