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

Added Keras example #21

Merged
merged 1 commit into from
Jul 15, 2018
Merged

Added Keras example #21

merged 1 commit into from
Jul 15, 2018

Conversation

anshuman23
Copy link
Owner

This example shows how to train a MLP model on the MNIST dataset from scratch in the Keras library and then save it as a .pb graph model for using it in Tensorflex. The MNIST dataset comes in built with the Keras library. I have basically modified one of the existing examples present on the Keras Github repository. The generated model can be read into Tensorflex as:

iex(1)> {:ok, graph} = Tensorflex.read_graph("mnist_mlp.pb")
2018-07-15 15:16:26.542596: 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
                               {:ok,
 %Tensorflex.Graph{
   def: #Reference<0.4212261172.582352897.51740>,
   name: "mnist_mlp.pb"
 }}

iex(2)> Tensorflex.get_graph_ops graph
["Variable_5", "Variable_4", "Variable_3", "Variable_2", "Variable_1",
 "Variable", "iterations", "decay", "rho", "lr", "output/bias",
 "output/bias/read", "output/kernel", "output/kernel/read", "dense_1/bias",
 "dense_1/bias/read", "dense_1/kernel", "dense_1/kernel/read",
 "dropout_1/keras_learning_phase", "dropout_2/cond/pred_id",
 "dropout_2/cond/Switch", "dropout_2/cond/switch_t",
 "dropout_2/cond/dropout/random_uniform/max",
 "dropout_2/cond/dropout/random_uniform/min",
 "dropout_2/cond/dropout/random_uniform/sub",
 "dropout_2/cond/dropout/keep_prob", "dropout_2/cond/mul/y",
 "dropout_1/cond/pred_id", "dropout_1/cond/Switch", "dropout_1/cond/switch_t",
 "dropout_1/cond/dropout/random_uniform/max",
 "dropout_1/cond/dropout/random_uniform/min",
 "dropout_1/cond/dropout/random_uniform/sub",
 "dropout_1/cond/dropout/keep_prob", "dropout_1/cond/mul/y", "input/bias",
 "input/bias/read", "input/kernel", "input/kernel/read", "input_input",
 "input/MatMul", "input/BiasAdd", "input/Relu", "dropout_1/cond/Switch_1",
 "dropout_1/cond/mul/Switch", "dropout_1/cond/mul",
 "dropout_1/cond/dropout/Div", "dropout_1/cond/dropout/Shape",
 "dropout_1/cond/dropout/random_uniform/RandomUniform",
 "dropout_1/cond/dropout/random_uniform/mul", ...]

Keras makes some slight changes to our input and output operation names (since it is built on top of TF) but they are still easily decipherable. They are changed from "input" to "input_input" and from "output" to "output/Softmax".

Once CSV support is added, a blog post can be written about the MNIST dataset and using Keras (or TF) models for the same.

@anshuman23 anshuman23 merged commit 1f645ae into master Jul 15, 2018
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

Successfully merging this pull request may close these issues.

None yet

1 participant