我需要一个Tensorflow模型来将图像分类为4种不同的类别,我正在对预先训练的InceptionResNetV2模型进行传递学习(权重=‘Imagenet’)。在model.fit()期间,我的准确率为97.4%,损失为0.3,而我的验证精度保持在84%,损失为0.4。我是否过度适应,如何提高我的验证准确性?
base_model = InceptionResNetV2(input_shape=(299,299,3),weights='imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(2048,activation='relu')(x)
x = Dropout(0.03)(x)
x = LeakyReLU(alpha=0.05)(x)
x = Dense(1024,activation='relu')(x)
x = LeakyReLU(alpha=0.05)(x)
x = Dense(128,activation='relu')(x)
predictions = Dense(4, activation='softmax')(x)发布于 2022-09-05 19:38:18
尝试将数据增强添加到代码中;这将解决过度匹配的问题。如下代码所示:
data_augmentation = tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.RandomRotation(0.01),
tf.keras.layers.experimental.preprocessing.RandomContrast(0.25),
tf.keras.layers.experimental.preprocessing.RandomTranslation(height_factor = (-0.1, 0.1), width_factor = (-0.1, 0.1))])
inp = tf.keras.Input(shape=IMG_SIZE)
x = data_augmentation(inp)
x = base_model(x, training=False)https://stackoverflow.com/questions/60854228
复制相似问题