def setTrainable(model,trainlayers):
# 先全部设置成不可训练
for layer in model.layers:
layer.trainable = False
# 设置可训练的层
for i in trainlayers:
model.layers[i].trainable = True
# 可训练层
print('trainable:')
for x in model.trainable_weights:
print(x.name)
print('\n')
# 不可训练层
print('untrainable: ')
for x in model.non_trainable_weights:
print(x.name)
print('\n')
keras 设置模型每层的trainable
最新推荐文章于 2023-03-19 11:39:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)