您好,我训练了一个模型,并且加载了图像:batch_size = 16# Data augmentation and preprocesstrain_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, validation_split=0.20) # set validation split# Train datasettrain_generator = train_datagen.flow_from_directory( 'PetImages/train', target_size=(244, 244), batch_size=batch_size, class_mode='binary', subset='training') # set as training data# Validation datasetvalidation_generator = train_datagen.flow_from_directory( 'PetImages/train', target_size=(244, 244), batch_size=batch_size, class_mode='binary', subset='validation') # set as validation datatest_datagen = ImageDataGenerator(rescale=1./255)# Test datasettest_datagen = test_datagen.flow_from_directory( 'PetImages/test')问题是如何使用 test_datagen 评估模型?我尝试了以下但没有工作:x=[]y=[]test_datagen.reset()for i in range(test_datagen.__len__()): a,b=test_datagen.next() x.append(a) y.append(b)x=np.array(x)y=np.array(y)print(x.shape)print(y.shape)score = model.evaluate(x, y)print(f'Test loss: {score[0]} / Test accuracy: {score[1]}')我收到此错误:无法将 NumPy 数组转换为张量(不支持的对象类型 numpy.ndarray)。
1 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
最后我用:
score = model.evaluate_generator(test_datagen, steps=STEP_SIZE_VALID)
print(f'Test loss: {score[0]} / Test accuracy: {score[1]}')
添加回答
举报
0/150
提交
取消