我想将灰度与 shape(None, 224,224) 转换为 (224,224,3)

问题描述

我试图在将一组图像传递给 CNN 模型之前对其进行预处理,我不得不将其转换为灰度,因为我的模型需要我的模型,问题是当我保存转换后的图像并加载它时,它正常工作没有任何错误,因为形状是 (244,244,3) 但是如果我将它直接传递给模型,图像的形状是 (None,224,224) 并且它产生了这个错误

ValueError: 层序列 5 的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。收到完整形状:(无、224、224)

代码是:

    gray = cv2.cvtColor(crop_img,cv2.COLOR_BGR2GRAY)
    resized_image = cv2.resize(crop_img,(224,224))
    frames.append(resized_image)
    cv2.imwrite("/Users/naimahalaqeel/Documents/graduation project/toarabicText/test2/%d.jpg" % count2,resized_image)
    count2 = count2 +1
    success,image = vidcap.read()
    count+=1

afterPrecceseFrames = np.array(frames)
predicted_classes = model.predict_classes(afterPrecceseFrames)
    

解决方法

我认为您使用 cv2.resize()crop_img 而不是 gray。是不是这个问题。