Keras ValueError:无法将大小为50176的数组重塑为形状(224224,3)

Keras ValueError:无法将大小为50176的数组重塑为形状(224224,3),keras,web-deployment,Keras,Web Deployment,我有一个错误“无法将大小为50176的数组重塑为形状(224224,3)我不明白为什么会发生这种情况可能有人也有同样的问题 def model_predict(img_path,model): size=224 img = cv2.imread(img_path,cv2.IMREAD_GRAYSCALE) img = cv2.resize(img,(size,size)) img=np.array(img).reshape(-1,size,size,3)

我有一个错误“无法将大小为50176的数组重塑为形状(224224,3)我不明白为什么会发生这种情况可能有人也有同样的问题

def model_predict(img_path,model):
    size=224
    img = cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)

    img = cv2.resize(img,(size,size))

    img=np.array(img).reshape(-1,size,size,3)
    img_class = model.predict_classes(img)
    return img_class
您的图像是灰度(单通道),但您尝试将其重塑为RGB(3通道),这将不起作用

试着换第三行

img = cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)
进入


在上传preds=model\u predict(file\u path,model)文件“C:\Users\bibibisha\Desktop\New folder\app.py”,model\predict img=np.array(img)第87行中的第112行提供完整的错误消息文件“C:\Users\bibibisha\Desktop\New folder\app.py”。重塑(-1,size,size,size,3)值错误:无法将大小为50176的数组重塑为形状(224224,3)编辑并添加您的问题,不要将其作为注释文件“C:\Users\bibisha\Desktop\New folder\app.py”发布,第87行,在model\u predict img=np.array(img)中。重塑(-1,size,size,3)值错误:无法将大小为50176的数组重塑为形状(224224,3)
img = cv2.imread(img_path,cv2.IMREAD_COLOR)