README.md in tensor_stream-0.6.1 vs README.md in tensor_stream-0.7.0
- old
+ new
@@ -13,10 +13,11 @@
- Replicates most of the commonly used low-level tensorflow ops (tf.add, tf.constant, tf.placeholder, tf.matmul, tf.sin etc...)
- Supports auto-differentiation via tf.gradients (mostly)
- Provision to use your own opcode evaluator (opencl, sciruby and tensorflow backends planned)
- Goal is to be as close to TensorFlow in behavior but with some freedom to add ruby specific enhancements (with lots of test cases)
- eager execution (experimental)
+- (08-08-2018) Load pbtext files from tensorflow (Graph.parse_from_string)
Since this is a pure ruby implementation for now, performance is not there yet. However it should be a good enough environment to learn about tensorflow and experiment with some models.
## Installation
@@ -67,11 +68,11 @@
# Construct a linear model
pred = X * W + b
# Mean squared error
-cost = tf.reduce_sum(tf.pow(pred - Y, 2)) / ( 2 * n_samples)
+cost = ((pred - Y) ** 2).reduce(:+) / ( 2 * n_samples)
optimizer = TensorStream::Train::GradientDescentOptimizer.new(learning_rate).minimize(cost)
# Initialize the variables (i.e. assign their default value)
init = tf.global_variables_initializer()
@@ -252,9 +253,47 @@
```
Note that the OpenCL evaluator provides speedup if you are using large tensors, tensors that are only using scalars like the linear regression sample will actually be slower.
samples/nearest_neighbor.rb contains a sample that uses opencl.
+
+## Export Import Models from tensorflow
+
+Experimental support for parsing and exporting pbtext files are supported:
+
+Exporting
+
+```ruby
+a = ts.constant([1.0, 1.0])
+b = ts.constant([1.5, 1.5])
+f = a + b
+
+File.write('my_model.pbtext', f.graph.as_graph_def)
+```
+
+Importing (Experimental)
+
+Note that not all tensorflow ops are supported, warnings will be showed
+if a certain operation is not supported yet.
+
+
+```ruby
+ pbtext = File.read(File.join('linear_regression.pbtxt'))
+
+ # create a graph from pbtext file
+ graph = TensorStream::Graph.parse_from_string(pbtext)
+
+ # reference a tensor by name from the created graph,
+ # for example you have a tensor named out
+ tensor = graph.get_tensor_by_name("out")
+
+ # set graph as default and do operations on it
+ graph.as_default do
+ sess = ts.session
+ expect(tr(sess.run(tensor))).to eq([[1.0, 1.0], [1.0, 1.0]])
+ end
+
+```
# Visualization
tensorstream does not support tensorboard yet, but a graphml generator is included: