当前位置:网站首页>Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
2022-07-27 02:08:00 【Medium coke with ice】
Catalog
- problem 1:pytorch Next , To multidimensional tensor Zoom
- problem 2:'PIL.Image' has no attribute '****'
- problem 3:ImportError: cannot import name 'imread'
- problem 4:models/bird/netG.pth is a zip archive (did you mean to use torch.jit.load()?)
- problem 5: Model saving and loading
- problem 6:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 226: illegal multibyte sequence
problem 1:pytorch Next , To multidimensional tensor Zoom
Question why : Sometimes you want to make the size of the image too large or too small , Want to generate tensor The tensor is scaled , At the same time, keep the same proportion of the original image . If there is one now tensor, His size is :[64,3,256,256],64 representative batch size,3 Indicates the number of channels ,256 It stands for length and width , Want to narrow it down to 32*32 The size of the .
Solution : We can use transform.resize(), But after trying , Discover the use of torch.nn.functional.interpolate It will work better
First, explain its parameters :torch.nn.functional.interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=None)
- input Is our input tensor (Tensor)
- size It's the output size
- scale_factor (float or Tuple[float]) Specify how many times the output is the input
- mode It is the choice of up sampling algorithm : Yes ’nearest’, ‘linear’, ‘bilinear’, ‘bicubic’ , ‘trilinear’ and ’area’, The default is ’nearest’
- align_corners (bool, optional) If set to True, Then the input and output tensors are aligned by the center point of their corner pixels , This preserves the value at the corner pixels . If set to False, Then the input and output tensors are aligned by the corners of their corner pixels , Interpolation uses the boundary value of the value outside the boundary to fill
Use samples :
print(train_mask.size())
# train_mask The size was originally [64,3,256,256]
train_mask = torch.nn.functional.interpolate(train_mask, scale_factor=1 / 4, mode='bilinear',align_corners=False)
# After the change ,train_mask The size changes to [64,3,64,64]
print(train_mask.size())
problem 2:‘PIL.Image’ has no attribute ‘****’
Question why : This is because the system has been installed PIL It's too new , Some properties have been deprecated in the new version
Solution : Just change back to the original version :pip install pillow==4.1.1, Install the old version pillow, Finally, I will tell you that this version is out of date , Never mind .
problem 3:ImportError: cannot import name ‘imread’
Question why :“scipy” The version of the library is too high
Solution : Change back to the original version :pip install scipy==1.2.1
problem 4:models/bird/netG.pth is a zip archive (did you mean to use torch.jit.load()?)
Question why : Where the parameters were saved after training pytorch Environment and now loading parameters pytorch The environment may be different , Version inconsistency , As a result, the parameters saved at that time cannot be read now .
Solution : First in 1.x Loading models under version , Then save as non zip Format , Setting the use_new_zipfile_serialization=False That's it .
#torch_version==1.x
import torch
from models import net
checkpoint = 'xxx.pth'
model = net()
model.load_state_dict(torch.load(checkpoint))
model.eval()
torch.save(model.state_dict(), model_path, use_new_zipfile_serialization=False)
problem 5: Model saving and loading
Problem description : In actual operation , Pay attention to every 100 round epoch Or every time 50 round epoch Save the trained parameters , provide against any misfortune ( power failure 、 Disconnection 、 Hardware failure 、 Earthquake, fire, etc ), In this way, this round can be loaded directly next time epoch The parameters of are then trained , You don't have to start over .
Solution :
Save parameters :
torch.save(model.state_dict(), path)
Loading of parameters
model.load_state_dict(torch.load(path))
problem 6:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 226: illegal multibyte sequence
Question why : A file is gbk code , It cannot be decoded .
Solution : See if you are yml Chinese is written in the document or other documents ( As in the figure below I accidentally wrote Chinese in the notes , Cause decoding failure ), Just delete it 
边栏推荐
- dlib安装失败解决办法
- MySQL single table query exercise
- 三范式,约束,部分关键字区别,
- Machine learning exercise 6 - Support Vector Machines
- Difference between fat AP and thin AP & advantages and disadvantages of networking
- 解决方案:Win10如何使用bash批处理命令
- 24ssh service
- Pseudo class of a element
- mysql视图
- Text to image论文精读DF-GAN:A Simple and Effective Baseline for Text-to-Image Synthesis一种简单有效的文本生成图像基准模型
猜你喜欢

Use ECs and OSS to set up personal network disk

Introduction to network - Introduction to home networking & basic network knowledge

CEPH (distributed storage)

Flink1.13.6 detailed deployment method

7.16 多益网络笔试

24ssh service

Unity Huatuo hot update environment installation and sample project

高度塌陷解决方法
![[polymorphism] the detailed introduction of polymorphism is simple and easy to understand](/img/85/7d00a0d9bd35d50635a0e41f49c691.png)
[polymorphism] the detailed introduction of polymorphism is simple and easy to understand

详解文本生成图像的仿射变换模块(Affine Transformation)和条件批量标准化(CBN)
随机推荐
MySQL master-slave replication and read-write separation
7.8 锐捷网络笔试
MySQL备份恢复
事务数据库及其四特性,原理,隔离级别,脏读,幻读,不可重复读?
2022zui新抖音24小时循环值守直播监控(一)直播间开播监控
--Project summary
使用ECS和OSS搭建个人网盘
Machine learning exercise 6 - Support Vector Machines
When El table is selected, the jump page remains selected
2022年最新文本生成图像研究 开源工作速览(Papers with code)
Shell course summary
[translation] reduced precision in tensorrt
7.7 SHEIN希音笔试
分库与分表
Connect mysql detailed graphic operations in ECs docker (all)
Virtualization technology KVM
Installation and basic operation of docker
2022最新抖音直播监控(二)直播间流媒体下载
高度塌陷解决方法
left join 、inner join 、right join区别