当前位置:网站首页>[pytorch] fine tuning technology
[pytorch] fine tuning technology
2022-07-26 06:16:00 【Li Junfeng】
Preface
Training neural networks is a very time-consuming thing , It requires a lot of computing power and a lot of data . Obviously, starting from scratch is not a wise choice , Making good use of existing resources is the wise choice .
Fine tuning technology
Generally speaking, image recognition can be divided into two steps :
- Extract the features of the picture , This part often passes CNN Convolution neural network .
- According to the extracted features , To classify , This part is often realized by fully connected neural network .
- Is there any similarity between identifying a cat and identifying a dog ?
The answer is yes , They are Extract picture features Are very similar .
consider CNN The role of convolution in , It is identifying different edges , So whether it's a cat , Or dogs , Picture features are similar , But how to learn according to these characteristics is the key .
Pre training model
In image recognition , There are many classic Neural Networks , for example vgg,resnet etc. , For these classic Networks ,pytorch They all provide good training models . Some of these are in ImageNet On the training , With high accuracy . Use some trained to extract image features , It can greatly reduce the time of training .
Code implementation
import torch
from torch import nn
from torch.nn import functional as F
from torchsummary import summary
net = torchvision.models.resnet18(pretrained=True)
net.fc = nn.Linear(net.fc.in_features, 5)
nn.init.xavier_uniform_(net.fc.weight)
summary(net , input_size=(3,224,224) , device="cpu")
lr = 0.0005
loss = nn.CrossEntropyLoss(reduction="mean")
params_1x = [param for name, param in net.named_parameters()
if name not in ["fc.weight", "fc.bias"]]
trainer = torch.optim.SGD([{
'params': params_1x},{
'params': net.fc.parameters(),'lr': lr * 80}],lr=lr, weight_decay=0.001)
epochs = 15
It's very simple , It's even simpler than defining neural networks completely by hand , Because it does not need to define its own network structure .
But these and training models can't be used directly , Some modifications are needed :
- Modify the last category number
stay ImageNet in , The final full connection layer is an output of 1000 1000 1000 Vector , That means 1000 1000 1000 Categories , In practice, , It needs to be modified according to the number of categories recognized at present . - Learning rate
Generally speaking , Pre trained parameters need not be modified , It can be set as a parameter without learning , You can also set its learning rate to be very small . And for the final full connection layer , That is, the network that classifies the extracted image information , Its learning rate will be relatively large .
Function and significance
Fine tuning technology is a blessing for people who don't have enough computing power , It greatly reduces the cost of training .
- Extracting image features CNN Networks tend to be closer to input , Training through gradient back propagation , It often takes more time than a fully connected network close to the output .
- Using micro carving technology , You can get a very good result in a very short time , stay 5 After a round of iterations, we can already achieve 91% The accuracy of ;15 One round of iteration can achieve 97% The accuracy of .

Shortcomings and limitations
Not all cases can use fine-tuning Technology , When there are significant differences in picture features , Using fine-tuning technology often does not get satisfactory results .
such as , stay ImageNet The models trained on are all based on normal pictures , But if it is used to recognize medical images (X Light film, etc ) It will lead to failure . Similarly, using this model to recognize cartoon pictures will often recognize .
边栏推荐
- Latex merges multiple rows and columns of a table at the same time
- 【无标题】
- Do it yourself smart home: intelligent air conditioning control
- Huawei cloud koomessage is a new marketing weapon in the hot public beta
- Mobile web
- [day04_0421] C language multiple choice questions
- Is the transaction in mysql45 isolated or not?
- [SQL optimization] (big table tips) sometimes a 2-hour SQL operation may take only 1 minute
- PHP 多任务秒级定时器的实现方法
- [day_050422] statistical palindrome
猜你喜欢

逆序打印链表
C language explanation series - comprehensive exercises, guessing numbers games
![[day_060423] no two](/img/2b/5bcb3e089a3157fe72a50ddb767e63.png)
[day_060423] no two

Kingbasees SQL language reference manual of Jincang database (7. Conditional expression)

Embedded sharing collection 14

Convolutional neural network (II) - deep convolutional network: case study

【pytorch】微调技术

Workflow activiti5.13 learning notes (I)

VRRP protocol and experimental configuration

redis 哨兵集群搭建
随机推荐
WebAPI整理
Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
【pytorch】CNN实战-花朵种类识别
【Day_07 0425】Fibonacci数列
Is the transaction in mysql45 isolated or not?
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
机械制造企业如何借助ERP系统,做好生产管理?
Convolutional neural network (IV) - special applications: face recognition and neural style transformation
【Day_05 0422】统计回文
Mysql45 talks about transaction isolation: why can't I see it after you change it?
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
Embedded sharing collection 14
How can machinery manufacturing enterprises do well in production management with the help of ERP system?
Calling mode and execution sequence of JS
MySQL multi table query introduction classic case
【Day_06 0423】把字符串转换成整数
Servlet filter details
【Day_03 0420】数组中出现次数超过一半的数字
Operating steps for uninstalling the mobile app
[(SV & UVM) knowledge points encountered in written interview] ~ phase mechanism