Hello I trained a model and the images were loading with:
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')
The question is how can I evaluate the model with test_datagen?
I triyed the following but dosent' work:
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]}')
I get this error:
Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).