这是我在Keras上使用ResNet34对Mnist进行的两个训练设置
两个网络之间的唯一区别在于“重新缩放”
这是我的两个问题:
2。为什么我应该在开始训练时使用“ x_train * 255”。(下面的代码)
非常感谢您!
数据集:Mnist数据集 环境:Colab 框架:Keras 型号:ResNet34
我只告诉大家两个网络之间的不同部分 下面代码的训练结果:
x_train = x_train.reshape(-1, 28, 28, 1)
x_test = x_test.reshape(-1, 28, 28, 1)
x_train = x_train / 255
x_test = x_test /255
from keras.preprocessing.image import ImageDataGenerator
img_gen = ImageDataGenerator(
rescale=1./255,
horizontal_flip=False
)
Epoch 1/5
3750/3750 [==============================] - 243s 65ms/step - loss: 0.2988 - acc: 0.9291 - val_loss: 0.0800 - val_acc: 0.9799
Epoch 2/5
3750/3750 [==============================] - 232s 62ms/step - loss: 0.1247 - acc: 0.9686 - val_loss: 0.0988 - val_acc: 0.9725
Epoch 3/5
3750/3750 [==============================] - 231s 62ms/step - loss: 0.0867 - acc: 0.9776 - val_loss: 0.0677 - val_acc: 0.9794
Epoch 4/5
3750/3750 [==============================] - 232s 62ms/step - loss: 0.0695 - acc: 0.9821 - val_loss: 0.0302 - val_acc: 0.9914
Epoch 5/5
3750/3750 [==============================] - 256s 68ms/step - loss: 0.0493 - acc: 0.9868 - val_loss: 0.0369 - val_acc: 0.9882
这是第二个网络 结果是
x_train = x_train.reshape(-1, 28, 28, 1)
x_test = x_test.reshape(-1, 28, 28, 1)
from keras.preprocessing.image import ImageDataGenerator
img_gen = ImageDataGenerator(
rescale=1./255,
horizontal_flip=False
)
Epoch 1/5
3750/3750 [==============================] - 264s 70ms/step - loss: 0.4926 - acc: 0.8603 - val_loss: 11.0879 - val_acc: 0.3114
Epoch 2/5
3750/3750 [==============================] - 230s 61ms/step - loss: 0.1993 - acc: 0.9448 - val_loss: 12.4943 - val_acc: 0.2240
Epoch 3/5
3750/3750 [==============================] - 230s 61ms/step - loss: 0.1596 - acc: 0.9570 - val_loss: 14.5385 - val_acc: 0.0980
Epoch 4/5
3750/3750 [==============================] - 231s 62ms/step - loss: 0.1090 - acc: 0.9694 - val_loss: 14.4918 - val_acc: 0.1009
Epoch 5/5
3750/3750 [==============================] - 229s 61ms/step - loss: 0.0848 - acc: 0.9769 - val_loss: 14.5740 - val_acc: 0.0958
我的第二个问题是为什么我应该添加“ x_train * 255”,因此“ * 255”在最后一部分中如何工作?
History = Resnet34_model.fit_generator(img_gen.flow(x_train*255, y_train, batch_size = 16),
steps_per_epoch = len(x_train)/16, validation_data = (x_test,y_test), epochs = 5 )