【发布时间】:2022-01-19 06:06:55
【问题描述】:
我已将 TF 模型导出为 .h5 格式,以便将其用于我的项目。在 Colab 上运行和测试时,它可以完美预测,但是当我尝试在我的机器(笔记本电脑)中预测 .h5 格式模型时,它没有预测到正确的模型,因此它不像以前在 Colab 中那样工作。我试图在网上浏览,但似乎没有找到答案或线索。有谁知道问题出在哪里?
示例
输入图片:golden_retriever的狗类型
(COLAB) -> 预测golden_retriever(正确)
model = tf.keras.models.load_model("model_mac.h5", custom_objects={"KerasLayer": hub.KerasLayer})
custom_images_paths = ["golde.jpeg"]
custom_data = create_data_batches(custom_images_paths, test_data=True)
custom_preds = model.predict(custom_data)
custom_pred_labels = [get_pred_label(custom_preds[i]) for i in range(len(custom_preds))]
(我的机器/笔记本电脑) -> 预测 norwegian_elkhound(其他看起来不像 golden_retriever 的东西。(错误)
model = tf.keras.models.load_model("model_mac.h5", custom_objects {"KerasLayer":hub.KerasLayer})
img = "golde.jpeg"
custom_data = create_data_batches([img], test_data=True)
custom_preds = model.predict(custom_data)
custom_pred_labels = [get_pred_label(custom_preds[i]) for i in range(len(custom_preds))]
提前致谢。
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning