报错:

ValueError: cannot reshape array of size 149184 into shape (28,28,1)

报错原因:

由于图片的w,h,c相乘等于149184所导致的。无法将大小为149184的数组重塑为形状(28,28,1)

解决方法:

我输入的图片shape为(224, 222, 3) 所以224 * 222 * 3 = 149184

通过opencv去改变图片的size

    #resize图片大小 先将原本的(224,222,3) ---> (28,28,3)
    pred_img = cv2.resize(pred_img,(28,28))                          
    #转换np数组格式
    pred_img = np.array(pred_img)   
    #重新reshape图片                      
    pred_img = pred_img.reshape(-1,28,28,1)
    #查看reshape后的图片shape                       
    print(pred_img.shape)