我正在研究一个问题,根据奶牛的图像预测奶牛的肥胖程度。我应用了 CNN 来估计 0-5 之间的值(我拥有的数据集仅包含 2.25 到 4 之间的值)我使用了 4 个 CNN 层和 3 个隐藏层。
我实际上有两个问题:1/ 我的训练误差为 0.05,但经过 3-5 个时期后,验证误差仍然约为 0.33。2/ 我的 NN 预测的值介于 2.9 和 3.3 之间,与数据集范围相比太窄了。这是正常的吗?
我怎样才能改进我的模型?
model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(512, 424,1)), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(32, (3,3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(32, (3,3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(64, (3,3), activation='relu'), tf.keras.layers.MaxPooling2D(2,2), tf.keras.layers.Flatten(input_shape=(512, 424)), tf.keras.layers.Dense(256, activation=tf.nn.relu), tf.keras.layers.Dense(128, activation=tf.nn.relu), tf.keras.layers.Dense(64, activation=tf.nn.relu), tf.keras.layers.Dense(1, activation='linear') ])
学习曲线:
预言:
这似乎是过度拟合的情况。你可以
Shuffle``Data
shuffle=True
cnn_model.fit
history = cnn_model.fit(x = X_train_reshaped, y = y_train, batch_size = 512, epochs = epochs, callbacks=[callback], verbose = 1, validation_data = (X_test_reshaped, y_test), validation_steps = 10, steps_per_epoch=steps_per_epoch, shuffle = True)
Early Stopping
callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=15)
from tensorflow.keras.regularizers import l2 Regularizer = l2(0.001) cnn_model.add(Conv2D(64,3, 3, input_shape = (28,28,1), activation='relu', data_format='channels_last', activity_regularizer=Regularizer, kernel_regularizer=Regularizer)) cnn_model.add(Dense(units = 10, activation = 'sigmoid', activity_regularizer=Regularizer, kernel_regularizer=Regularizer))
BatchNormalization
ImageDataGenerator
Normalized
255
Pre-Trained Models
ResNet
VGG Net