1. python model traing:
you should add this to your python code when constract the model:
logits = tf.add(tf.matmul(hidden4, weights), biases, name='classify')
out = tf.nn.softmax(logits, name='softmax')
prediction = tf.argmax(out, axis=1, name='prediction')
you shuold add this to you python code when saving the trained model:
if precision > best_model_precision:
best_model_precision = precision
checkpoint_file = os.path.join(FLAGS.log_dir, 'model.ckpt')
saver.save(sess, checkpoint_file, global_step=step)
tf.train.write_graph(sess.graph_def, FLAGS.log_dir, 'graph.pbtxt', true)
specially you must save the graph as text file, otherwise there may occur many errors when you are loading the graph in the follow-up steps
https://www.tensorflow.org/api_docs/python/tf/train/write_graph
2. c++ api for prediction:
you should freeze the graph before loading it . Refering to this site:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite
the commond of build freeze_graph:
bazel build -c opt --copt=-msse4.1 --copt=-msse4.2 tensorflow/python/tools:freeze_graph
About how to use the c++ api for prediction, you can refer to this file:
https://github.com/rockingdingo/tensorflow-tutorial