Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:形状(1,1,512,4)和(2,512,1,1)不兼容如何修复此错误?_Python_Tensorflow - Fatal编程技术网

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

Python ValueError:形状(1,1,512,4)和(2,512,1,1)不兼容如何修复此错误?,python,tensorflow,Python,Tensorflow,我不太懂英语,所以可能写得很笨拙。 我的自定义代码在识别时出错。我试图更改分析方法和文件位置。但没有任何帮助。我不是一个超级程序员,所以我真的不明白代码深处发生了什么。我也不太明白输出图像应该保存在哪里,它将被称为什么。 程序代码: from imageai.Prediction.Custom import CustomImagePrediction import os execution_path = os.getcwd() prediction = CustomImagePredicti

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

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。这就是为什么不能对其进行整形。

整形两侧的元素数量必须相同。您正试图将2048个元素填充到1024个元素中。我们帮不上什么忙,因为你忽略了给我们预期的。你的图片“ScreenHack.jpg”的尺寸很可能与你的模型不匹配。你应该看到那一行的错误。谢谢你这么快的回复。你能更详细地描述一下我的问题吗?培训文件、输入图像或其他内容出错?什么元素有问题?我更改了文件大小(这对我来说不是很好),错误消失了,但出现了另一个错误:OSError:无法打开文件(无法打开文件:名称='C:\Users\Doctor\PycharmProjects\FAKE44Type\venv\model_ex-065_acc-0.875000.h5',错误消息='No-the-file或directory',flags=0,o_-flags=0)我仍然不知道输出图像是如何保存的。但是没有…在更改h5文件所在的目录后,出现了相同的错误:ValueError:Shapes(1,1,512,4)和(2,512,1,1)是不兼容的很难理解为什么它不同。可能是图像大小不适合该模型。或者例如,模型等待灰度图像,然后尝试传递rgb图像