Some tips of using tensorflow C++ API for model prediction

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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值