【发布时间】:2020-05-19 20:08:43
【问题描述】:
我正在使用迁移学习训练网络。我目前冻结了前 70 层,并且只在最后 10 层进行训练。由于我的数据集的大小,每个 epoch 需要 45 分钟来训练。如果有办法,我想在整个网络上训练 1 个 epoch,得到最后一个冻结层的输出张量,并将其输入到训练层中,以确定需要多少个 epoch。
我希望这将减少训练网络所需的时间,因为本质上是跳过了常量层。
from tensorflow.keras.applications import MobileNet
from tensorflow.keras.models import Model
base_model = MobileNet(weights='imagenet', include_top=False, input_shape=(224,224,3), dropout=.2)
x = base_model.output
x = Dense(10, activation='softmax')(x)
model = Model(inputs=base_model.input,outputs=x)
for layer in model.layers[:70]:
layer.trainable=False
for layer in model.layers[70:]:
layer.trainable=True
...
我使用 ImageDataGenerator 将我的数据导入网络。
这是我正在关注的教程:https://towardsdatascience.com/transfer-learning-using-mobilenet-and-keras-c75daf7ff299
【问题讨论】:
-
对不起,你能告诉我,你为什么需要这个?你认为它会提高火车速度吗?
-
是的。这就是目标
标签: python tensorflow keras transfer-learning