训练精度远高于测试精度

时间:2020-06-03 19:12:43

标签: python image-processing deep-learning classification multiclass-classification

我有问题。 我有一个带有标签的20047图像的数据集。我的目标是分类(8类)。 我在imagenet上使用EfficientNet pretrain。我改变了最后一层。 我正在使用10倍交叉验证和生成器来加载图像。

train_generator = train_datagen.flow_from_dataframe(
    dataframe=train_df,
    directory=train_dir,
    x_col="img",
    y_col="label",
    target_size=(224, 224),
    batch_size=16,
    class_mode='sparse')

test_generator = test_datagen.flow_from_dataframe(
    dataframe=test_df,
    directory=test_dir,
    x_col="img",
    y_col="label",
    target_size=(224, 224),
    batch_size=16,
    class_mode='sparse')

epochs=15
batch_size=16
history=model.fit_generator(
    train_generator,
    steps_per_epoch=(18042/batch_size),
    epochs=epochs)

在训练过程中,我得到的准确度> = 0.86,而损失<= 0.88,但是当我预测测试数据集上的标签时,我得到的准确度非常低,约为0.18。

其他信息: (loss ='sparse_categorical_crossentropy',Optimizer ='adam')

train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=False)

test_datagen = ImageDataGenerator(rescale=1./255)

0 个答案:

没有答案