我正在尝试创建一个带有用于表达式分类的keras的卷积自动编码器,但是在训练过程中,经过2-3个时期后,其精度在0.10(最大为10%)时卡住了。是因为代码中的问题,还是因为我的数据集太小(每个类约70张图像)? (编辑:我也尝试过性别分类,为此我有大约450张图片,但情况仍然相同)
这是我的模型代码:
def getModel(size):
input_img = Input(shape=(80, 80, 1))
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
# at this point the representation is (4, 4, 8) i.e. 128-dimensional
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu', padding = 'same')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_img, decoded)
opt = SGD(lr = 0.01, decay=1e-6, momentum=0.9, nesterov=True)
autoencoder.compile(optimizer=opt, loss='binary_crossentropy', metrics=['acc'])
#print(autoencoder.summary())
return autoencoder
` 我在每层中尝试了不同数量的过滤器,并尝试了2-3种不同的优化器
我想做的是针对不同的类别(7个表达式)训练不同的自动编码器,然后在将所有7个经过训练的模型传递给输出之后,通过比较输出来预测测试点的值。
对于训练一个班级,该模型在某种程度上提高了准确性,但随后又停止了(准确性很低)。这是日志:
Epoch 1/50
- 1s - loss: 0.6966 - acc: 0.0197 - val_loss: 0.6941 - val_acc: 0.0263
Epoch 2/50
- 1s - loss: 0.6942 - acc: 0.0368 - val_loss: 0.6915 - val_acc: 0.0513
Epoch 3/50
- 1s - loss: 0.6915 - acc: 0.0774 - val_loss: 0.6894 - val_acc: 0.0568
Epoch 4/50
- 1s - loss: 0.6892 - acc: 0.0897 - val_loss: 0.6873 - val_acc: 0.0586
Epoch 5/50
- 1s - loss: 0.6869 - acc: 0.0944 - val_loss: 0.6850 - val_acc: 0.0588
Epoch 6/50
- 1s - loss: 0.6844 - acc: 0.0947 - val_loss: 0.6824 - val_acc: 0.0588
Epoch 7/50
- 1s - loss: 0.6817 - acc: 0.0947 - val_loss: 0.6795 - val_acc: 0.0588
Epoch 8/50
- 1s - loss: 0.6787 - acc: 0.0947 - val_loss: 0.6765 - val_acc: 0.0588
Epoch 9/50
- 1s - loss: 0.6755 - acc: 0.0947 - val_loss: 0.6733 - val_acc: 0.0588
Epoch 10/50
- 1s - loss: 0.6721 - acc: 0.0947 - val_loss: 0.6700 - val_acc: 0.0588
Epoch 11/50
- 1s - loss: 0.6686 - acc: 0.0947 - val_loss: 0.6667 - val_acc: 0.0588
Epoch 12/50
- 1s - loss: 0.6650 - acc: 0.0947 - val_loss: 0.6633 - val_acc: 0.0588
我的代码是否有问题,或者应该尝试解决问题的任何其他方式? 如果没有,那可能是因为数据集,因为每个表达式我只有大约70张图像。 (编辑:我也尝试过性别分类,为此我有大约450张图片,但情况仍然相同)