回归模型为何无法学习?

huangapple go评论47阅读模式
英文:

Why regression model doesn't learn?

问题

我必须创建一个模型,该模型返回3个数字 - 3D模型旋转的角度。我使用的所有模型在开始时都以相同的方式旋转。为此,我将每个模型随机旋转-15到15度,并对每个模型重复此操作五次(颜色表示与“相机”的距离)。每个图像的尺寸为[150, 150],包含从0到255的数字:

顶部:
点击此处

侧面:
点击此处

前面:
点击此处

然后,我创建了一个模型:

点击此处

我的训练数据集包括30个模型,对于每个模型,我创建了5个不同的旋转,因此共有150个样本。我使用了105个进行训练,45个用于验证。

然后,当我尝试进行100个时期的拟合时,批量大小为40,Adam优化器,学习率为0.1,误差为平均绝对误差。我使用了自定义指标,即“真实角度 - 预测角度的绝对值之和”。在整个训练过程中,它一直显示类似以下的信息:

第95个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.8082 - metr: 25.7488 - 验证损失: 7.8395 - 验证metr: 16.2496
第96个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.8203 - metr: 28.0160 - 验证损失: 7.8005 - 验证metr: 16.1032
第97个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.7898 - metr: 21.8611 - 验证损失: 7.8166 - 验证metr: 15.6580
第98个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.7806 - metr: 18.9963 - 验证损失: 7.8766 - 验证metr: 15.1825
第99个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.7973 - metr: 21.3751 - 验证损失: 7.8581 - 验证metr: 14.8261
第100个时期/100个时期 3/3 [==============================] - 4秒 1秒/步骤 - 损失: 6.7750 - metr: 19.1987 - 验证损失: 7.8100 - 验证metr: 14.2220

这是模型实际预测的内容(五个预测值与五个真实角度的比较):

[[-2.9442613  -0.54196733  2.4832273 ]
[-4.1728406  -0.60556126  1.6946273 ]
[-4.727777   -1.2003385   0.9080634 ]
[-3.125803    0.2552796   1.7383668 ]
[-5.6989026   0.5544905   1.539639  ]
[-3.6019537   0.29354924  1.2323818 ]]

[[ -4.  -8.   2.]
[-12.  -7.   4.]
[-13.  -4.  -3.]
[ -7.   2.  -4.]
[-13.   8. -12.]
[-15. -11. -11.]]

我多次重建了它,但如您所见,结果始终接近一个数字,并且没有变化。我不知道为什么它们无法达到甚至10。

我尝试在每个Conv2D层后添加SeparableConv2D,更改了损失函数,并将学习率更改为0.01和0.001,但没有任何变化。为什么模型无法拟合?

英文:

I have to create model which returns 3 numbers - the angles by which the 3d model is rotated. All models I use are rotated in the same way in the beginning. For this I rotate every model for a random degree from -15 to 15 and get this five times for each model (the color represents distance from "camera"). Each of these images has size [150, 150] and contain numbers from 0 to 255:

Top:
Click

Side:
Click

Front:
Click

Then I've created a model:

Click

My training dataset is 30 models and for each I create 5 different rotations, so there's 150 samples. I used 105 for training and 45 for validation

Then, when I've tried to fit it for 100 epochs, batch size = 40, Adam, learning rate = 0.1, error - mean absolute error. I use my custom metric, it's just sum of abs(angle_true - angle_pred). It showed me this and something extremely similar during all training:

Epoch 95/100 3/3 [==============================] - 4s 1s/step - loss: 6.8082 - metr: 25.7488 - val_loss: 7.8395 - val_metr: 16.2496
Epoch 96/100 3/3 [==============================] - 4s 1s/step - loss: 6.8203 - metr: 28.0160 - val_loss: 7.8005 - val_metr: 16.1032
Epoch 97/100 3/3 [==============================] - 4s 1s/step - loss: 6.7898 - metr: 21.8611 - val_loss: 7.8166 - val_metr: 15.6580
Epoch 98/100 3/3 [==============================] - 4s 1s/step - loss: 6.7806 - metr: 18.9963 - val_loss: 7.8766 - val_metr: 15.1825
Epoch 99/100 3/3 [==============================] - 4s 1s/step - loss: 6.7973 - metr: 21.3751 - val_loss: 7.8581 - val_metr: 14.8261
Epoch 100/100 3/3 [==============================] - 4s 1s/step - loss: 6.7750 - metr: 19.1987 - val_loss: 7.8100 - val_metr: 14.2220

There's what model actually predicts (five it's predictions vs five true angles):

[[-2.9442613  -0.54196733  2.4832273 ]
[-4.1728406  -0.60556126  1.6946273 ]
[-4.727777   -1.2003385   0.9080634 ]
[-3.125803    0.2552796   1.7383668 ]
[-5.6989026   0.5544905   1.539639  ]
[-3.6019537   0.29354924  1.2323818 ]]

[[ -4.  -8.   2.]
[-12.  -7.   4.]
[-13.  -4.  -3.]
[ -7.   2.  -4.]
[-13.   8. -12.]
[-15. -11. -11.]]

I recreated it some times and, as you can see, results were always close to one number and didn't varied. I don't know why they can't reach ewen 10.

I've tried to add SeparableConv2D after every Conv2D layer, to change loss function and to change learning rate to 0.01 and 0.001 but nothing changed. Why the model doesn't fit?

答案1

得分: 0

数据集对于回归任务来说太小了。尝试添加更多样本并使用数据增强(例如水平翻转、平移、缩放、颜色抖动)。

英文:

Dataset is too small for regression task. Try to add more samples and use data augmentation (e.g. horizontal flipping, shifting, zooming, color jittering).

huangapple
  • 本文由 发表于 2023年5月22日 03:11:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定