【发布时间】:2020-04-09 19:32:03
【问题描述】:
我不太会英文,所以可能写得很笨拙。 我的自定义代码在识别时出错。我试图改变分析方法和文件位置。但没有任何帮助。我不是超级程序员,所以我不太了解代码深处发生了什么。我也不太明白输出图像应该保存在哪里以及它将被称为什么。 程序代码:
from imageai.Prediction.Custom import CustomImagePrediction
import os
execution_path = os.getcwd()
prediction = CustomImagePrediction()
prediction.setModelTypeAsSqueezeNet()
prediction.setModelPath(os.path.join(execution_path, "model_ex-065_acc-0.875000.h5"))
prediction.setJsonPath(os.path.join(execution_path, "model_class.json"))
prediction.loadModel(num_objects=4)
predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "ScreenHack.jpg"), result_count=5)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction , " : " , eachProbability)
错误文本:
ValueError: Shapes (1, 1, 512, 4) and (2, 512, 1, 1) are incompatible
【问题讨论】:
-
您必须在重塑的两侧具有相同数量的元素。你正试图将 2048 个元素塞进 1024 个元素中。我们无能为力,因为你忽略了给我们预期的 MRE。
-
您的图像“ScreenHack.jpg”的尺寸与您的模型所需的尺寸不匹配,很可能。您应该会在该行中看到错误。
标签: python tensorflow