訓練后,我注意到 - 如下所示 - 驗證損失正在增加。這是正常的嗎?此外,它的上面一個。

下面是我的代碼:
# I omit data loading
from sklearn.utils import shuffle
# shuffle input
class_image, class_label = shuffle(class_image, class_label , random_state=0)
inputs = tf.keras.layers.Input(shape=(IMAGE_SIZE_X, IMAGE_SIZE_Y, 3), name="input_image")
x = keras.applications.resnet50.preprocess_input(inputs)
base_model = tf.keras.applications.ResNet50(input_tensor=x, weights=None, include_top=False,
input_shape=(IMAGE_SIZE_X, IMAGE_SIZE_Y, 3) )
x=base_model.output
x = tf.keras.layers.GlobalAveragePooling2D( name="avg_pool")(x)
x = tf.keras.layers.Dense(2, activation='softmax', name="predications")(x)
model = keras.models.Model(inputs=base_model.input, outputs=x)
base_learning_rate = 0.0001
loss = tf.keras.losses.SparseCategoricalCrossentropy()
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=base_learning_rate),
loss=loss,
metrics=[ 'accuracy'])
history = model.fit(x=class_image ,
y=class_label,
epochs=30
,batch_size=1
, validation_split=0.2
)
# evlaute
import matplotlib.pyplot as plt
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs, acc, 'r', label='Training accuracy')
plt.plot(epochs, val_acc, 'b', label='Validation accuracy')
plt.plot(epochs,loss, 'y', label='Training loss')
plt.plot(epochs, val_loss, 'g', label='Validation loss')
plt.title('Training and validation accuracy')
plt.legend(loc=0)
plt.figure()
uj5u.com熱心網友回復:
這通常發生在模型過擬合時。你可能沒有足夠的訓練資料來訓練這么大的模型(ResNet50 很大),導致模型只是簡單地記住你的資料集,而不是真正學習泛化。訓練損失直接為零也很明顯。嘗試更小的模型或更多/不同的訓練資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/434160.html
上一篇:如何在虛線驗證碼影像中找到輪廓
