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

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


原因:预测的时候给的是数组,需要转成array,np.asarray(imagelist)

下面是正确代码:

path = '../../white_mouse_data/test/1/'
# path=r"D:\git_project\mouse_detect_demo\mouse_data\0_test\\"
files = os.listdir(path)

aaa = 0
index = 0
imagelist = []
for file in files:
    a = cv2.imread(path + file)
    a=cv2.resize(a,(IMG_SIZE,IMG_SIZE),interpolation=cv2.INTER_CUBIC)
    imagelist.append(a)
t0 = time.time()
result = model.predict(np.asarray(imagelist))

你可能感兴趣的:(keras,深度学习)