anshuman23 / tensorflex

Tensorflow bindings for the Elixir programming language :muscle:
https://hexdocs.pm/tensorflex/Tensorflex.html
Apache License 2.0
308 stars 14 forks source link

Merged all support functions into read_graph; returning atoms #4

Closed anshuman23 closed 6 years ago

anshuman23 commented 6 years ago

@josevalim as discussed in #3 , merged all graph reading capabilities into the read_graph function. This function returns a TF_Graph on successful loading of graph and an {:error,"Unable to load graph"} tuple on an unsuccessful attempt.

Example is as follows (classify_image_graph_def.pb is from Google's Imagenet model):

iex(1)> graph = Tensorflex.read_graph("classify_image_graph_def.pb")
2018-05-17 23:36:16.488469: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2018-05-17 23:36:16.774442: W tensorflow/core/framework/op_def_util.cc:334] OpBatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
Successfully imported graph
#Reference<0.1610607974.1988231169.250293>

iex(2)> graph2 = Tensorflex.read_graph("Makefile")                   
{:error, 'Unable to import graph'}

I have an idea for the "story" around the graph loading we had talked about, so I'll be merging this PR as already discussed and adding the details of that in the next PR for your review.

josevalim commented 6 years ago

I love the return types. Great job!

Note though that you are returning a charlist (single-quoted) in the error message while a string/binary (double-quoted) would be preferred:

iex(2)> graph2 = Tensorflex.read_graph("Makefile")                   
{:error, "Unable to import graph"}