pytorch各种报错个人笔记

1、one of the variables needed for gradient computation has been modified by an inplace operation

可能有多种原因
1、以 ‘_’ 结尾的函数
2、+=、/=这样的操作
3、激活函数如 torch.nn.ReLU(inplace=True)

如果是第二种,把 a += b 换成 a = a + b 即可,第三种则置inplace为False;若是第一种则麻烦一点,需要找替代函数或者自己实现该函数的功能

2、An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

在使用torch.multiprocessing.spawn时报此错。pytorch的torch.multiprocessing是基于python的原生multiprocessing进行二次开发的模块,在multiprocessing中,当在另一个CPU核心上产生一个子进程时,会将原来的主py文件再次导入,因此,在如下示例代码中

# start process for each gpu
mp.spawn(main, nprocs=args.g, args=(args,))

当其被加载至另一个CPU核心运行时,此语句会被再执行一遍,因此会递归产生大量子进程,最后导致该报错。因此此语句应该加入如下代码后进行运行:

if __name__ == '__main__':
    # start process for each gpu
    mp.spawn(main, nprocs=args.g, args=(args,))

这样子进程就不会再运行mp.spawn了

3、注:to_tensor会自动把输入图像从0-255转化成0-1的范围

官方文档见:https://pytorch.org/vision/stable/generated/torchvision.transforms.ToTensor.html#torchvision.transforms.ToTensor

4、如果模型中有dropout或者batchnorm,在test的时候(包括从文件恢复模型),一定要加eval(),因为这两个模块在train和test的行为是不一样的,不加的话torch会自动当作train进行处理,会使得test的效果变差

5、NotImplementedError: Could not run 'aten::slow_conv3d_forward' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::slow_conv3d_forward' is only available for these backends: [CPU, BackendSelect, Python, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, AutocastCPU, Autocast, Batched, VmapMode, Functionalize].

在我的情况里面实际是因为数据没有用.to(device)弄到cuda上

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 当在使用PyTorch下载数据集时,可能会遇到的情况。其中一个常见的是由于网络问题导致无法下载数据集。这可能是因为程序无法连接到目标网站或者下载速度过慢。为了解决这个问题,可以尝试手动下载数据集并将其放入目标文件夹。具体步骤如下:首先,在想要存储数据的地方,新建一个路径,例如"{数据集名称}/raw/"。然后,使用pip list命令检查pip的版本是否需要更新。如果需要更新,可以使用命令"python.exe -m pip install --upgrade pip"来进行更新。接下来,将root参数设置为存储数据的地址,即数据集名称的父目录,并使用相应的代码加载数据集。例如,对于MNIST数据集,可以使用以下代码进行加载: ``` import torch from torchvision import datasets # Download training data from datasets. training_data = datasets.MNIST( root="D:/classic_dataset", train=True, download=True, transform=ToTensor(), ) # Download test data from datasets. test_data = datasets.MNIST( root="D:/classic_dataset", train=False, download=True, transform=ToTensor(), ) ``` 通过按照上述步骤进行操作,您应该能够成功下载并加载数据集,从而解决PyTorch下载的问题。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [Pytorch无法下载/读取数据集Error downloading(不必改源代码)](https://blog.csdn.net/weixin_44126491/article/details/123810162)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [安装Pytorch时出现ERROR: Could not find a version that satisfies the requirement...的解决方法](https://blog.csdn.net/m0_63604019/article/details/129961036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值