简体   繁体   English

如何加载使用 make_image_classifier 工具保存的 Tensorflow 模型

[英]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:假设您将这些文件( assetsvariables.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.

相关问题 如何加载已保存的 Tensorflow 模型并对其进行评估 - How to load a saved Tensorflow model and evaluate it 如何加载和测试特定的TensorFlow保存的模型? - How to load and test a specific TensorFlow saved model? Tensorflow:加载保存的模型:UnicodeDecodeError - Tensorflow : load saved model : UnicodeDecodeError 如何保存 model,使用 Tensorflow 上保存的 model 进行加载和预测? - How to save a model, load and predict with the saved model on Tensorflow? 如何使用从 save_weights 保存的张量流模型加载和预测? - How to load and predict with a tensorflow model saved from save_weights? 如何从 Colaboratory 中保存的检查点加载 TensorFlow Keras model? - How to load TensorFlow Keras model from a saved checkpoint in Colaboratory? 如何加载用 saved_model 保存的 tensorflow keras model 以使用预测 function? - How to load a tensorflow keras model saved with saved_model to use the predict function? 如何在 Python 中使用 tensorflow 训练图像分类器模型并在 Java 应用程序中使用训练后的模型? - How can i train a Image classifier model with tensorflow in Python and use the trained model in Java application? 如何在张量流中保存和加载DNN分类器? - How to save and load a DNN classifier in tensorflow? 如何将图像加载到张量流以与模型一起使用? - How to load an image into tensorflow to use with a model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM