pytorch
DeepGoAI
欢迎学习交流!
展开
-
raise AssertionError(“Torch not compiled with CUDA enabled“)
遇到的问题,就是 GPU driver 以及cuda都装完了,pytorch装完之后想试试代码。结果报错,raise AssertionError(“Torch not compiled with CUDA enabled”)。原创 2022-11-15 19:34:15 · 5816 阅读 · 1 评论 -
Pytorch只更新预训练模型的部分参数
假设有一个训练好的模型,并且我们只想微调部分参数。比如,这里我们只想更新最后一部分的参数:可以看到,这里的模块叫b4。我们可以直接通过获取模块的名字来进行更新:也就是说 只要模块名字包含b4 就会让他跟新网络。对应的optimizer 的设置如下:然后直接训练就行。也可以直接 把这些符合条件的 parameters 加入 list中,并传给 optimizer直接训练就行。##...原创 2022-06-25 01:34:29 · 2634 阅读 · 0 评论 -
PIL,CV2,pytorch的图片维度顺序
PIL,CV2,pytorch的图片维度顺序PIL:img = Image.open(file).convert('RGB')w,h = img.sizeCV2:image = cv2.imread(filepath)image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)h, w, c = image.shapepytorch:batch,channel,h,w注意区分...原创 2021-05-15 08:56:19 · 1812 阅读 · 4 评论 -
Pytorch 多GPU TypeError: zip argument #1 must support iteration
碰到Pytorch 多GPU TypeError: zip argument #1 must support iteration这个问题时,考虑如下解决方式:1.尝试在模型forward的时候,不要输入list类型的数据,而是将其改成tensor的形式。实在不行就分开写。这样可能可以解决问题2.model 的forward 方法里,输出不能有常量,必须也是要求tensor的格式,先想办法改一下代码,输出常量在多GPU下是行不通的...原创 2021-05-01 10:45:38 · 2232 阅读 · 0 评论 -
PyTorch 多GPU下模型的保存与加载(踩坑笔记)
转自https://www.cnblogs.com/blog4ljy/p/11711173.html写的很好,留作参考PyTorch 多GPU下模型的保存与加载(踩坑笔记)这几天在一机多卡的环境下,用pytorch训练模型,遇到很多问题。现总结一个实用的做实验方式:多GPU下训练,创建模型代码通常如下:os.environ['CUDA_VISIBLE_DEVICES'] = args.cudamodel = MyModel(args)if torch.cuda.is_avail..转载 2020-05-21 08:55:07 · 1249 阅读 · 0 评论 -
windows 下 non-stationary_texture_syn_master 问题与解决
ubuntu 下non-stationary_texture_syn_master 跑这个项目是完全没问题的,主要在于window下一对问题1.一开始就跑不通 解决: 在 train 中添加以上代码块2.在训练的过程中内存outofmemory找到原因了,保存新生成的图像的时候,会占用GPU缓存,结果就不够用了,用torch.cuda.empty_cache(...原创 2019-01-05 16:58:13 · 242 阅读 · 6 评论 -
ValueError: Expected more than 1 value per channel when training, got input size [1, 512, 1, 1]
ValueError: Expected more than 1 value per channel when training, got input size [1, 512, 1, 1]个人碰到这个问题的时候是在缩放的时候,由于最后缩放大小只有1X1 了,我还有一个下采样代码,导致报了这个错这里提供借鉴,或许可能,你也是这个错误 ...原创 2018-12-23 17:34:04 · 5861 阅读 · 3 评论 -
torch.backend.cudnn.benchmark
torch.backend.cudnn.benchmark大部分情况下,设置这个 flag 可以让内置的 cuDNN 的 auto-tuner 自动寻找最适合当前配置的高效算法,来达到优化运行效率的问题。一般来讲,应该遵循以下准则:如果网络的输入数据维度或类型上变化不大,设置torch.backends.cudnn.benchmark=true 可以增加运行效率; 如果网络的输...转载 2019-08-13 16:49:05 · 262 阅读 · 0 评论 -
BrokenPipeError
转载 2019-07-25 21:00:20 · 530 阅读 · 0 评论 -
Pytorch torchvision.transforms 数据标准化(tensor 和 numpy 的相互转换和可视化)
关于pytorch torchvision.transforms 数据标准化的一些使用转自:https://blog.csdn.net/u014484247/article/details/79997357这里在做一点补充,对于把数据转换回去,只要把公式带回去就能得到结果对应的,关键公式如下:image_numpy = (np.transpose(image_numpy, (1,...原创 2019-03-26 08:53:47 · 1565 阅读 · 0 评论 -
pytorch RuntimeError: cuda runtime error (59)
pytorch RuntimeError: cuda runtime error (59)最后发现是自己类别设错了,对应的可以作为参考,是不是自己设置的label数量和数据量不对称所造成的Traceback (most recent call last): File "./main.py", line 180, in <module> main(args) F...原创 2019-06-20 12:30:42 · 1003 阅读 · 0 评论 -
Pytorch 中retain_graph的坑
Pytorch 中retain_graph的坑在查看SRGAN源码时有如下损失函数,其中设置了retain_graph=True,其作用就是在更新D网络时的loss反向传播过程中使用了retain_graph=True,目的为是为保留该过程中计算的梯度,后续G网络更新时使用; ############################ # (1) Update D ...原创 2019-04-19 10:34:23 · 3066 阅读 · 0 评论 -
ctc loss解决问题:src/binding.cpp:6:29: fatal error: torch/extension.h: No such file or directory
ctc loss解决问题:src/binding.cpp:6:29: fatal error: torch/extension.h: No such file or directory借鉴:https://blog.csdn.net/gubenpeiyuan/article/details/85390830https://blog.csdn.net/yuanlulu/article/d...转载 2019-03-28 22:26:02 · 1600 阅读 · 3 评论 -
pytorch contiguous的使用
pytorch contiguous的使用contiguous一般与transpose,permute,view搭配使用即使用transpose或permute进行维度变换后,调用contiguous,然后方可使用view对维度进行变形。具体原因我还没搞清,看到网上有两种说法,一种是维度变换后tensor在内存中不再是连续存储的,而view操作要求连续存储,所以需要contiguous...转载 2019-03-17 15:44:10 · 194 阅读 · 0 评论 -
pytorch下采样上采样维度无法对齐的问题
pytorch下采样上采样维度无法对齐的问题问题如上,比方说有如下一段pytorch网络代码model += [nn.Conv2d(ngf * mult, ngf * mult * 2, kernel_size=3, stride=2, padding=1), norm_layer(ngf * mult * 2), activation].....原创 2019-03-17 14:16:26 · 5644 阅读 · 0 评论 -
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation原有:pytorch 换了一个网络跑模型整个项目是模块化编程对应的网络都是有自己的模块的,因为替换了一下网络,结果报了这个错,很尴尬,明明什么都没动,就是换了一下网络,...原创 2019-01-27 16:23:41 · 5084 阅读 · 0 评论 -
OSError: [Errno 4] Interrupted system call
转自:https://github.com/pytorch/pytorch/issues/4220I have refer to https://stackoverflow.com/questions/14136195/what-is-the-proper-way-to-handle-in-python-ioerror-errno-4-interrupted-syst and change...转载 2018-11-23 14:07:16 · 1394 阅读 · 0 评论