我如何在 DNN 中重用经过训练的模型? [英] How I reuse trained model in DNN?

查看:41
本文介绍了我如何在 DNN 中重用经过训练的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家!

我有一个关于训练模型重用(tensorflow)的问题.

I have a question releate in trained model reusing( tensorflow ).

我有火车模型

我想用训练好的模型预测新数据.

I want predict new data used trained model.

我使用 DNNClassifier.

I use DNNClassifier.

我有一个 model.ckpt-200000.meta、model.ckpt-200000.index、checkpoint 和 eval 文件夹.

I have a model.ckpt-200000.meta, model.ckpt-200000.index, checkpoint, and eval folder.

但我不知道重用这个模型..

but I don't know reuse this model..

请帮帮我.

推荐答案

首先,您需要导入您的图形,

First, you need to import your graph,

with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  new_saver = tf.train.import_meta_graph('model.ckpt-200000.meta')
  new_saver.restore(sess, tf.train.latest_checkpoint('./'))

然后你可以给图形输入并得到输出.

Then you can give input to the graph and get the output.

graph = tf.get_default_graph()
input = graph.get_tensor_by_name("input:0")#input tensor by name    
feed_dict ={input:} #input to the model

#Now, access theoutput operation. 
op_to_restore = graph.get_tensor_by_name("y_:0") #output tensor

print sess.run(op_to_restore,feed_dict) #get output here

注意事项,

  • 您可以用图表的训练部分替换上面的代码(无需训练即可获得输出).
  • 但是,您仍然必须像以前一样构建您的图形,并且只替换训练部分.

  • You can replace the above code with your training part of the graph (i.e you can get the output without training).
  • However, you still have to construct your graph as previously and only replace the training part.

上述方法仅加载构造图的权重.因此,您必须先构建图形.

Above method only loading the weights for the constructed graph. Therefore, you have to construct the graph first.

可以在这里找到一个很好的教程,http://cv-tricks.com/tensorflow-tutorial/save-restore-tensorflow-models-quick-complete-tutorial/

A good tutorial on this can be found here, http://cv-tricks.com/tensorflow-tutorial/save-restore-tensorflow-models-quick-complete-tutorial/

如果您不想再次构建图形,您可以按照本教程进行操作,https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc

If you don't want to construct the graph again you can follow this tutorial, https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc

这篇关于我如何在 DNN 中重用经过训练的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆