ValueError:形状(1、1、512、4)和(2、512、1、1)不兼容如何解决此错误?

时间:2020-04-09 19:32:03

标签: python tensorflow

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

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

1 个答案:

答案 0 :(得分:0)

您可以通过将所有值相乘得到实际的元素数,首先是2048,第二是1024。这就是为什么无法重塑的原因。