Tensorflow 之finetune微调模型方法&&不同层上设置不同的学习率

时间:2023-03-09 08:28:03
Tensorflow 之finetune微调模型方法&&不同层上设置不同的学习率

ConvNets:

AlexNet finetune:

- 自己搭建的网络,加载初始化模型:

def load_with_skip(data_path, session, skip_layer):
data_dict = np.load(data_path).item()
for key in data_dict:
if key not in skip_layer:
with tf.variable_scope(key, reuse=True):
for subkey, data in zip(('weights', 'biases'), data_dict[key]):
session.run(tf.get_variable(subkey).assign(data)) print('Load pre-trained model: {}'.format(weight_file))
load_with_skip(weight_file, sess, ['fc8']) # Skip weights from fc8

VGG模型finetune:

- 自定义网络;加载参数,很详细教程:

- 另外:这是个基于tensorflow-vgg16Caffe to TensorFlow的VGG16和VGG19的一个TensorFlow的实现。

ResNet的slim模型finetune: