ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape

原因:预测的时候给的是数组,需要转成array。
【ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape】正确的写法:

emotion_classifier=load_model("weights_best_simple_model.h5") t1=time.time() image = cv2.imdecode(np.fromfile('0.jpg', dtype=np.uint8), -1) # load the image, pre-process it, and store it in the data list image = cv2.resize(image, (norm_size, norm_size), interpolation=cv2.INTER_LANCZOS4) image = img_to_array(image) imagelist.append(image) imageList = np.array(imagelist, dtype="float") / 255.0 pre=np.argmax(emotion_classifier.predict(imageList))

    推荐阅读