我的深度学习模型不是培训.我该如何训练? [英] My deep learning model is not training. How do I make it train?

查看:71
本文介绍了我的深度学习模型不是培训.我该如何训练?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Keras相当陌生,如果我犯了一个基本错误,请原谅.因此,我的模型具有3个卷积(2D)层和4个密集层,并散布有Dropout层.我正在尝试使用图像训练回归模型.

I'm fairly new to Keras, please excuse me if I made a fundamental error. So, my model has 3 Convolutional (2D) layers and 4 Dense Layers, interspersed with Dropout Layers. I am trying to train a Regression Model using images.

X_train.shape =(5164,160,320,3)

X_train.shape = (5164, 160, 320, 3)

y_train.shape =(5164)

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')

当我尝试运行此模型时,训练损失会按预期减少,验证损失会徘徊在同一区域,并且验证准确性会保持完全.我不是在寻求输入来改进我的模型(我会自己动手做),但是我需要帮助以使模型解开.我想查看验证准确性的变化,即使在小数点后三位,减少或增加也无所谓.我如何才能解开模型?

When I try to run this model, the training loss decreases as expected, the validation loss hovers around the same region, and the validation accuracy stays exactly the same. I'm not asking for inputs to improve my model (I'll do that on my own), but I need help to get the model unstuck. I want to see the validation accuracy change, even in the third decimal place, decrease or increase doesn't matter. How can I get my model unstuck?

这是我尝试训练模型时发生的图像:

Here's an image of what happens when I try to train the model:

任何解决方案将不胜感激.

Any solution would be much appreciated.

推荐答案

此代码中的主要问题是指标.作为回归指标的准确性在回归模型上不起作用.将初始学习率降低到0.0001也有帮助.

The main issue in this code was the metric. Accuracy, being a classification metric doesn't work on Regression models. Decreasing initial learning rate to 0.0001 helped as well.

略有不同的实现得到更明确的答案

A slightly different implementation got a more conclusive answer here

这篇关于我的深度学习模型不是培训.我该如何训练?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆