如何在 Python 中将 OpenCV 图像提供给经过训练的 CNN 模型(添加新维度)?

Ars*_*21b 1 python opencv numpy conv-neural-network

我收到此错误Error when checking input: expected conv2d_11_input to have 4 dimensions, but got array with shape (300, 300, 3) 如何将 RGB 图像传递给 CNN?如何枚举样本以创建 4D 图像?

unl*_*lut 5

卷积函数需要一批图像,即使您有单个图像,您也应该将图像传递为:

#  assume img is your RGB image
#  add 4th batch dimension
img = np.expand_dims(img, axis=0)) 

#  now you can pass it to CNN
Run Code Online (Sandbox Code Playgroud)