问题教程 cifar10 与 resnet50 训练问题
question to tutorial cifar10 with resnet50 train problem
# load ResNet50
from tensorflow.keras.applications import ResNet50
resnet = ResNet50(
include_top=True, # classification : True, embedding : False
weights=None,
input_shape=(32,32,3),
pooling = 'avg', #gloval avarage pooling
classes=10,
classifier_activation ='softmax'
)
### resnet training strategy
from tensorflow.keras.callbacks import ReduceLROnPlateau
batch_size = 128
epochs = 30 # i used this Passively
lr = 0.1
optimizer = SGD(lr, momentum=0.9)
loss_fn = "sparse_categorical_crossentropy"
metrics = ["accuracy"]
lr_callback = ReduceLROnPlateau(
monitor="val_loss",
factor=0.1,
patience=10,
min_lr=1e-6
)
resnet.compile(optimizer=optimizer,
loss=loss_fn,
metrics=metrics)
# training ResNet50
resnet_history = resnet.fit(X_train, y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(X_test, y_test),
callbacks=[lr_callback],
verbose=1)
我有问题要用 none-runtime-initialization 和 normal train 训练
例如我认为 15 纪元是很好的运动。所以,我直接训练了 30 个纪元,没有使用运行时初始化。但它被毁了
所以接下来使用 runtime_initialization。我训练了 45 个 epoch,但效果很好。有什么区别?
结果图
不使用random_seed
15 epoch
15+30 epoch
45 epoch
----------------答案添加------------------------ ----------
使用 random_seed + 不使用 ReduceLROnPlateau
15 epoch train
15 + Subsequently 30 epoch(not use runtime initialize) train
45 epoch train
我不知道有什么区别。 45 epoch train 运动良好但 15+30 epoch 运动不良
首先,可能是由于随机性在性能不太好时影响更大(因此,较大的学习率可能会阻碍模型收敛。尝试使用 0.01 或 0.001)。
为了解决这个问题,我建议使用以下代码修复种子。
tf.set_random_seed(42)
random.seed(42) # optional
numpy.random.seed(42) # optional
此外,学习率或像ReduceLROnPlateau
这样的提前停止回调会持续监控模型性能并在其中保存一些值,以便re-initializing可能会影响结果。
# load ResNet50
from tensorflow.keras.applications import ResNet50
resnet = ResNet50(
include_top=True, # classification : True, embedding : False
weights=None,
input_shape=(32,32,3),
pooling = 'avg', #gloval avarage pooling
classes=10,
classifier_activation ='softmax'
)
### resnet training strategy
from tensorflow.keras.callbacks import ReduceLROnPlateau
batch_size = 128
epochs = 30 # i used this Passively
lr = 0.1
optimizer = SGD(lr, momentum=0.9)
loss_fn = "sparse_categorical_crossentropy"
metrics = ["accuracy"]
lr_callback = ReduceLROnPlateau(
monitor="val_loss",
factor=0.1,
patience=10,
min_lr=1e-6
)
resnet.compile(optimizer=optimizer,
loss=loss_fn,
metrics=metrics)
# training ResNet50
resnet_history = resnet.fit(X_train, y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(X_test, y_test),
callbacks=[lr_callback],
verbose=1)
我有问题要用 none-runtime-initialization 和 normal train 训练 例如我认为 15 纪元是很好的运动。所以,我直接训练了 30 个纪元,没有使用运行时初始化。但它被毁了 所以接下来使用 runtime_initialization。我训练了 45 个 epoch,但效果很好。有什么区别?
结果图
不使用random_seed
15 epoch
15+30 epoch
45 epoch
----------------答案添加------------------------ ----------
使用 random_seed + 不使用 ReduceLROnPlateau
15 epoch train
15 + Subsequently 30 epoch(not use runtime initialize) train
45 epoch train
我不知道有什么区别。 45 epoch train 运动良好但 15+30 epoch 运动不良
首先,可能是由于随机性在性能不太好时影响更大(因此,较大的学习率可能会阻碍模型收敛。尝试使用 0.01 或 0.001)。
为了解决这个问题,我建议使用以下代码修复种子。
tf.set_random_seed(42)
random.seed(42) # optional
numpy.random.seed(42) # optional
此外,学习率或像ReduceLROnPlateau
这样的提前停止回调会持续监控模型性能并在其中保存一些值,以便re-initializing可能会影响结果。