当前位置:网站首页>[pytorch tutorial] 04 - explain the update of pre training model loading in torchvision 0.13 and the solution to error reporting (latest in 2022)
[pytorch tutorial] 04 - explain the update of pre training model loading in torchvision 0.13 and the solution to error reporting (latest in 2022)
2022-07-21 21:16:00 【Zimujun】

Load pre training model ( There are major updates )
Believe recently (2022 year 7 month ) Installed or updated PyTorch and torchvision My comrades may have encountered one of the following errors when running the code :
UserWarning: The parameter ‘pretrained’ is deprecated since 0.13 and will be removed in 0.15, please use ‘weights’ instead.
UserWarning: Arguments other than a weight enum or
None
for ‘weights’ are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passingweights=ResNet50_Weights.IMAGENET1K_V1
. You can also useweights=ResNet50_Weights.DEFAULT
to get the most up-to-date weights.Expected type ‘Optional[ResNet50_Weights]’, got ‘str’ instead
This is because torchvision 0.13 A major update has been made to the loading method of the pre training model . Today, you can put it on at one time 3 strip Bug Destroy all .
from torchvision 0.13 Start ,torchvision Offer a brand new Multi weight support API (Multi-weight support API) , It supports loading different versions of weight parameter files into the model .
1. Comparison between new and old versions
from torchvision 0.13 Start , Load the parameters of the pre training model function from
pretrained = True
Change it toweights= Pre training model parameter version
. And the old version will be written in the future torchvision 0.15 Version is Deprecated .
for instance :
from torchvision import models
# The old version is written , In the future torchvision 0.15 Version is Deprecated
model_old = models.resnet50(pretrained=True) # deprecated
model_old = models.resnet50(True) # deprecated
# torchvision 0.13 And later new versions
model_new = models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V1)
# No pre training model loaded
model = models.resnet50(weights=None)
model = models.resnet50()
among , The first 8 Line code IMAGENET1K_V1
It means ResNet-50 stay ImageNet The first version of the weight parameter file for pre training on the dataset . Is a version identifier .
2. The benefits of the new writing
In the old version pretrained = True
in , We don't have much choice for pre training weight parameters , The default pre training weight file version should be used as soon as it is implemented . But the problem is , The development of deep learning is changing with each passing day , Soon, a more powerful model was born .
And use the new version weights= Pre training model parameter version
, It is equivalent to that we have the option of pre training weight parameter file . We can enjoy using more accurate, faster and more updated pre training weight parameter files , Help our research to a higher level .
for instance :
from torchvision import models
# The loading accuracy is 76.130% Old weight parameter file V1
model_v1 = models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V1)
# Equivalent writing
model_v1 = models.resnet50(weights="IMAGENET1K_V1")
# The loading accuracy is 80.858% New weight parameter file V2
model_v2 = models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V2)
# Equivalent writing
model_v1 = models.resnet50(weights="IMAGENET1K_V2")
If you don't know which version of the weight file is the latest , No problem , Choose the default DEFAULT that will do . The official will follow torchvision Upgrade and give way DEFAULT The weight file version is kept up to date . As shown in the following code :
from torchvision import models
# If you don't know which version is the latest , Choose the default DEFAULT that will do
model_new = models.resnet50(weights=models.ResNet50_Weights.DEFAULT)
边栏推荐
- Oracle processes和sessions参数(进程连接数&会话连接数)
- VMware出现“该虚拟机似乎正在使用中”问题
- MySQL高可用实战部署方案——Galera Cluster
- [authority promotion] search ideas and utilization methods of raising rights exp
- Redis(七) - 封裝Redis工具類
- /usr/bin/applydeltarpm not installed问题解决
- 并发编程(二十四) - JMM之happens-before原则
- Concurrent programming (XXIX) - memory layout of objects
- Navicat 16.1 为OceanBase 社区版提供管理开发工具的新选择
- 浅析 SQL Server 的 CROSS APPLY 和 OUTER APPLY 查询 - 第一部分
猜你喜欢
【MySQL】17-超详细的MySQL聚合函数总结
[authority promotion] search ideas and utilization methods of raising rights exp
【MySQL】MySQL中 UNION 并的使用
peoplecode 根据上下文引用来赋值
How to use normal distribution transformation for registration
(note) Wu Enda's in-depth study l4w2
Concurrent programming (XX) -reentrantlock locking and unlocking principle
tic-tac-toe
浅谈 | 嵌套连接
How to match multiple point clouds step by step
随机推荐
Concurrent programming (XXIV) - JMM's happens before principle
浅谈 | 嵌套连接
PostgreSQL HA集群高可用方案介绍 & pgpool-II+PostgreSQL HA方案部署
peoplecode 定义的名字引用
peopleCode 理解组件缓存的结构和内容
【MySQL】18-MySQL中子查询的使用详细总结
实操演练 | 数据库中检索奇数或偶数行的简单方法
盗版引发设备瘫痪 | 官方严正声明:切勿在非官方渠道购买或下载Navicat
SQL select 语句
Amy Tabb robot world hand eye calibration (1. Environment matching)
Use Arduino to build an IOT smart home based on Alibaba cloud platform
Minesweeping (C language)
数据库监控的重要性
Easy language learning notes (2)
并发编程(二十七) - JUC之原子类
yum check 时报错libmysqlclient.so.18()(64bit)
测试 SQL 的危险 | 切勿掉以轻心
Matlab2021a configuration GPU encountered error c1083: unable to open include file: "gpu/mxgpuarray.h": no such file or directory
2021-08-11
[MySQL] classification of multi table query 1: equivalent connection and non equivalent connection