我是Keras的新手,如果我犯了一个基本错误,请原谅。因此,我的模型具有3个卷积(2D)层和4个密集层,并散布有Dropout层。我正在尝试使用图像训练回归模型。
X_train.shape =(5164、160、320、3)
y_train.shape =(5164)
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, Activation, MaxPooling2D, Dropout
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.losses import Huber
from tensorflow.keras.optimizers.schedules import ExponentialDecay
model = Sequential()
model.add(Conv2D(input_shape=(160, 320, 3), filters=32, kernel_size=3, padding="valid"))
model.add(MaxPooling2D(pool_size=(3,3)))
model.add(Activation('relu'))
model.add(Conv2D(filters=256, kernel_size=3, padding="valid"))
model.add(MaxPooling2D(pool_size=(3,3)))
model.add(Activation('relu'))
model.add(Conv2D(filters=512, kernel_size=3, padding="valid"))
model.add(MaxPooling2D(pool_size=(3,3)))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(256))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(1))
checkpoint = ModelCheckpoint(filepath="./ckpts/model.ckpt", monitor='val_loss', save_best_only=True)
stopper = EarlyStopping(monitor='val_acc', min_delta=0.0003, patience = 10)
lr_schedule = ExponentialDecay(initial_learning_rate=0.1, decay_steps=10000, decay_rate=0.9)
optimizer = Adam(learning_rate=lr_schedule)
loss = Huber(delta=0.5, reduction="auto", name="huber_loss")
model.compile(loss = loss, optimizer = optimizer, metrics=['accuracy'])
model.fit(X_train, y_train, validation_split = 0.2, shuffle = True, epochs = 100,
callbacks=[checkpoint, stopper])
model.save('model.h5')
当我尝试运行该模型时,训练损失按预期减少,验证损失在相同区域附近徘徊,并且验证准确性保持完全相同。我不是在寻求输入来改进我的模型(我会自己动手做),但是我需要帮助以使模型解开。我想查看验证准确性的变化,即使在小数点后三位,减少或增加也无所谓。我如何才能解开模型?
任何解决方案将不胜感激。
这段代码中的主要问题是度量。作为回归指标的准确性在回归模型上不起作用。将初始学习率降低到0.0001也有帮助。
稍有不同的实现在这里得到了更确定的答案