[英]How to load a Tensorflow model saved with make_image_classifier tool
I've made a custom image classifier model using a Tensorflow tool called make_image_classifier https://github.com/tensorflow/hub/tree/master/tensorflow_hub/tools/make_image_classifier我使用名为 make_image_classifier https://github.com/tensorflow/hub/tree/master/tensorflow_hub/tools/make_image_classifier的 Tensorflow 工具制作了一个自定义图像分类器模型
Now the model is exported into a .pb file and also 2 folders, assets and variables.现在模型导出为 .pb 文件以及 2 个文件夹、资产和变量。
The question is how can I use this custom model to make predictions?问题是如何使用此自定义模型进行预测? I've gone through all TF documentation and have tried many different things over these days but found no solution.
这些天我浏览了所有 TF 文档,并尝试了许多不同的方法,但没有找到解决方案。
Someone wrote about it when he found no clear information, so he created a guide but it also doesn't work for me.有人在找不到明确的信息时写了它,所以他创建了一个指南,但它对我也不起作用。 In "step 3" its all the code required to load the module and classify an image using the custom model.
在“步骤 3”中,它包含加载模块和使用自定义模型对图像进行分类所需的所有代码。 The problem with this is I need to know the name of the input and output node, and I don't have them.
问题是我需要知道输入和输出节点的名称,而我没有。 I've tried to find them using Netron but it didn't work.
我尝试使用 Netron 找到它们,但是没有用。 https://heartbeat.fritz.ai/automl-vision-edge-exporting-and-loading-tensorflow-saved-models-with-python-f4e8ce1b943a
https://heartbeat.fritz.ai/automl-vision-edge-exporting-and-loading-tensorflow-saved-models-with-python-f4e8ce1b943a
import tensorflow as tf
export_path = '/Users/aayusharora/Aftershoot/backend/loadmodel/models/'
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, ['serve'], export_path)
path = '/Users/aayusharora/Aftershoot/backend/sampleImage.jpg'
with open(path, "rb") as img_file:
y_pred = sess.run('tile:0', feed_dict={'normalised_input_image_tensor': [img_file.read()] })
print(y_pred)
Can someone please give me a clue about how to load a saved model and use it to make predictions?有人可以给我一个关于如何加载保存的模型并使用它进行预测的线索吗?
From Save and load models |从保存和加载模型 | Tensorflow Core :
张量流核心:
You can reload using a saved model:您可以使用保存的模型重新加载:
new_model = tf.keras.models.load_model('<path-to-export-path>/my_model')
Assuming you have these files together ( assets
, variables
, the .pb
file) which you did seem to have:假设您将这些文件(
assets
、 variables
、 .pb
文件)放在一起,您似乎确实拥有这些文件:
ls <path-to-export-path>/my_model
my_model
assets saved_model.pb variables
The new_model
should be like the original. new_model
应该和原来的一样。 To check its architecture:要检查其架构:
new_model.summary()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.