在我的项目中,有3个人的面孔,我想对他们的面孔进行分类。因此,在我的训练集中,每个人有500个样本,每个人的验证集有500个样本。使用resnet50预训练模型对人脸进行分类。但是,验证损失和准确性都不好。代码如下:
resnet = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
for layer in resnet.layers:
layer.trainable = False
x = Flatten()(resnet.output)
prediction = Dense(len(folders), activation='softmax')(x)
model = Model(inputs=resnet.input, outputs=prediction)
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy']
)
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('drive/My Drive/faces/train',
target_size = (224, 224),
batch_size = 16,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('drive/My Drive/faces/val',
target_size = (224, 224),
batch_size = 16,
class_mode = 'categorical')
# fit the model
r = model.fit_generator(
training_set,
validation_data=test_set,
epochs=5,
steps_per_epoch=len(training_set),
validation_steps=len(test_set)
)
训练准确性,损失,有效性和损失如下:
[![https://i.stack.imgur.com/0P2iW.png][1]][1]
为什么验证损失会增加而验证准确性却没有提高?