我也试过这两个 loss='binary_crossentropy' activation='sigmoid' 但没有任何效果。我该如何解决这个错误?
batch_size = 2
datagen_train = ImageDataGenerator(rescale=1./255)
datagen_test = ImageDataGenerator(rescale=1./255)
generator_train = datagen_train.flow_from_directory(directory=train_dir,
batch_size=batch_size,
target_size=(256,256),
shuffle = True,
class_mode = 'binary',
color_mode = 'grayscale')
generator_test = datagen_test.flow_from_directory(directory=test_dir,
batch_size=batch_size,
target_size=(256,256),
color_mode = 'grayscale',
class_mode = 'binary',
shuffle = False)
steps_test = generator_test.n // batch_size
print(steps_test)
epochs = 10
steps_per_epoch = generator_train.n // batch_size
print(steps_per_epoch)
model = ResNet50(include_top=True)
model.summary()
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
hist = model.fit(generator_train,
epochs=epochs,
steps_per_epoch=steps_per_epoch,
validation_data = generator_test,
validation_steps = steps_test)