美文网首页
Finetune预训练模型

Finetune预训练模型

作者: 阮恒 | 来源:发表于2019-07-03 22:11 被阅读0次

1、PyTorch学习笔记(1)-finetune网络的一些注意事项https://blog.csdn.net/u014448054/article/details/80623514k+

2、全局微调和局部微调

https://blog.csdn.net/u012759136/article/details/65634477

3、局部微调选择层数

https://blog.csdn.net/u012436149/article/details/78038098

4、CS231关于transfer learning的教程

http://cs231n.github.io/transfer-learning/

5、Pytorch Tutorial for Fine Tuning/Transfer Learning a Resnet for Image Classification

https://github.com/Spandan-Madan/Pytorch_fine_tuning_Tutorial

6、pytorch官方教程

https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html

https://pytorch.org/docs/stable/torchvision/models.html

github网络配置文件

https://github.com/pytorch/vision/tree/master/torchvision/models

例程:

import torch

from torchvisionimport models

model = models.resnet18(pretrained=True)

# #######全局finetune,使用不同的learning rate#########

# ignored_params = list(map(id,model.fc.parameters()))

# base_params = filter(lambda p: id(p) not in ignored_params, model.parameters())

#

# optimizer = torch.optim.SGD([{'params': base_params}, {'params': model.fc.parameters(), 'lr': 1e-5}], lr=1e-4, momentum=0.9)

#

#######局部finetune,只学习fc#######################

# in_features = model.fc.in_features

# #######change the output feature of fc######

# model.fc = torch.nn.Linear(in_features, 15)

# for param in model.parameters():

#    param.requires_grad = False

# model.fc = torch.nn.Linear(in_features, 15)

# optimizer = torch.optim.SGD(model.fc.parameters(), lr=1e-2, momentum=0.9)

#

######局部finetune, 学习fc和top parameters#########

fc_params = list(map(id,model.fc.parameters()))

top_params = list(map(id, model.layer4.parameters()))

ignored_params = fc_params.append(top_params)

base_params_model = filter(lambda p: id(p)not in ignored_params, model.parameters())

fc_params_model = filter(lambda p: id(p)in fc_params, model.parameters())

top_params_model = filter(lambda p: id(p)in top_params, model.parameters())

optimizer = torch.optim.SGD([{'params': fc_params_model}, {'params': top_params_model, 'lr':1e-3}], lr=1e-2, momentum=0.9)

报错:fc size mismatch

inception_v3 RuntimeError: size mismatch

原因是input image的size应该是224(vgg、resnet)或者299(inception)不是448

相关文章

  • UIE实体关系抽取解读

    通过UIE默认抽取关系 通过预训练模型直接抽取,数据没有返回。 先看下通过finetune预训练模型后的结果如下:...

  • Finetune预训练模型

    1、PyTorch学习笔记(1)-finetune网络的一些注意事项https://blog.csdn.net/u...

  • Pytorch预训练模型finetune

    这一块实在是因为之前没有过pytorch的经验,从0开始一步一步摸滚打爬。而且发现自己手总是处于闲置状态实在不好,...

  • BERT fintune 的艺术

    BERT 预训练模型就如宰好待烹的猪,则 finetune 便是烹饪之法,猪头能用来做成香糯浓醇的烧猪头肉,猪蹄能...

  • 文字检测trick

    数据扩增方面:FOTS: 在synth800k 训练+MLT 训练+验证集上预训练,然后再继续finetune。旋...

  • pytorch finetune模型

    pytorch finetune模型 文章主要讲述如何在pytorch上读取以往训练的模型参数,在模型的名字已经变...

  • Bert基础介绍

    BERT理解 1、预训练模型 BERT是一个预训练的模型,那么什么是预训练呢? 假设已有A训练集,先用A对网络进行...

  • 2020-05-18 神经网络保存训练模型

    Tensorflow加载预训练模型和保存模型

  • TensorFlow 同时导入多个预训练模型进行 finetun

    这篇文章将说明怎么同时导入多个预训练模型进行训练。 前面的文章 TensorFlow 使用预训练模型 ResNet...

  • pytorch如何给预训练模型添加新的层

    在使用pytorch预训练模型的时候发现预训练模型的输出层没有激活函数,为了提高模型的训练效果需要自己添加。以Re...

网友评论

      本文标题:Finetune预训练模型

      本文链接:https://www.haomeiwen.com/subject/cyzfjftx.html