您好,我训练了一个模型,并且加载了图像:
batch_size = 16
# Data augmentation and preprocess
train_datagen = ImageDataGenerator(rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
validation_split=0.20) # set validation split
# Train dataset
train_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 dataset
validation_generator = train_datagen.flow_from_directory(
'PetImages/train',
target_size=(244, 244),
batch_size=batch_size,
class_mode='binary',
subset='validation') # set as validation data
test_datagen = ImageDataGenerator(rescale=1./255)
# Test dataset
test_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)。
胡子哥哥
相关分类