ValueError:形状(1,1,512,4)和(2,512,1,1)不兼容如何修复此错误?

2024-05-28 18:40:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我不太懂英语,所以可能写得很笨拙。 我的自定义代码在识别时出错。我试图更改分析方法和文件位置。但没有任何帮助。我不是一个超级程序员,所以我真的不明白代码深处发生了什么。我也不太明白输出图像应该保存在哪里,它将被称为什么。 程序代码:

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

Tags: 文件path代码importmodelos分析方法join

热门问题