原因:預測的時候給的是數組,需要轉成array。
正确的寫法:
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))