当前位置:网站首页>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 
边栏推荐
- ACM模式输入输出练习
- Shell programming specifications and variables
- JS逻辑运算符
- 【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图
- Es specify user name and password when instantiating resthighlevelclient
- mysql一个select语句的执行过程
- shell课程总结
- Text to image论文精读RAT-GAN:文本到图像合成中的递归仿射变换 Recurrent Affine Transformation for Text-to-image Synthesis
- 三范式,约束,部分关键字区别,
- [translation] explicit and implicit batch in tensorrt
猜你喜欢

2022最新直播监控24小时监控(三)直播间弹幕解析

shell课程总结

2022年T2I文本生成图像 中文期刊论文速览-1(ECAGAN:基于通道注意力机制的文本生成图像方法+CAE-GAN:基于Transformer交叉注意力的文本生成图像技术)

超出隐藏显示省略号
![[translation] explicit and implicit batch in tensorrt](/img/17/3f00697d53ff43cd881960849da5f7.png)
[translation] explicit and implicit batch in tensorrt
![Unity Huatuo revolutionary hot update series [1]](/img/bc/ed480fc979c08c362784a3956d7fe2.jpg)
Unity Huatuo revolutionary hot update series [1]

left join 、inner join 、right join区别

IO function of standard C library

Share 29 chrome plug-ins, and there is always one for you

FID指标复现踩坑避坑 文本生成图像FID定量实验全流程复现(Fréchet Inception Distance )定量评价实验踩坑避坑流程
随机推荐
Harmonyos image processing application development live broadcast notes
2022最新直播监控24小时监控(三)直播间弹幕解析
[详解C语言]一文带你认识C语言,让你醍醐灌顶
Flink1.13.6详细部署方式
Specify that SQL only supports select syntax
23nfs shared storage service
MySQL index
Tinyint type map is received and returned as Boolean
Machine learning exercise 7 - K-means and PCA (principal component analysis)
Hash索引和B+树相关知识
mysql的安装
[FPGA tutorial case 29] the second DDS direct digital frequency synthesizer based on FPGA - Verilog development
MySQL multi table query
Pseudo class of a element
2022年最新文本生成图像研究 开源工作速览(Papers with code)
利用九天深度学习平台复现SSA-GAN
D - Difference HDU - 5936
IO function of standard C library
6.30联发科笔试
Introduction to network - Introduction to Enterprise Networking & basic knowledge of network