![](https://img-blog.csdnimg.cn/20190918140012416.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Pytorch编写中遇到的问题
代码遇到的BUG汇总
布尔大学士
工学博士在读,主要从事智能制造、工业精密检测、智能化设备研发等方向研究,已发表二区Top文章一篇、国家级竞赛二等奖一项、已授权软件著作权两项、已发表中文期刊两篇,先后参与国家自然科学基金面上项目、省重点研发计划等课题。
展开
-
Pytorch安装问题:Solving environment 一直循环/Solving environment: failed with initial frozen solve
在conda某个包的时候,出现了Solving environment: \一直不动的情况。实在是等不下去了,那该怎么解决?Pytorch安装问题:Solving environment 一直循环/Solving environment: failed with initial frozen solve。原创 2024-08-08 10:02:27 · 180 阅读 · 0 评论 -
Detectron2中运行demo.py时,报错:AssertionError: get_event_storage() has to be called inside a ‘with EventSt
AssertionError: get_event_storage() has to be called inside a 'with EventStorage(...)' context!原创 2023-05-15 15:22:28 · 269 阅读 · 0 评论 -
代码import torch 报错 ImportError: numpy.core.multiarray failed to import
使用Anaconda安装pytorch后,import torch报错 ImportError: numpy.core.multiarray failed to import 【解决方案】原创 2023-03-02 10:39:06 · 874 阅读 · 0 评论 -
【报错解决】ERROR: pip‘s dependency resolver does not currently take into account all the packages
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.原创 2023-03-02 10:34:11 · 21298 阅读 · 4 评论 -
numpy 报错:”AttributeError: module ‘numpy‘ has no attribute ‘bool‘“
解决方案 numpy 报错:”AttributeError: module 'numpy' has no attribute 'bool'“原创 2023-03-02 10:28:23 · 1293 阅读 · 0 评论 -
fatal: unable to access ‘https://github xxxxxxxxx的解决方法
将命令中的 https改为 git。原创 2023-03-02 10:24:33 · 496 阅读 · 0 评论 -
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
【代码】“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题。原创 2023-02-27 15:14:01 · 1282 阅读 · 0 评论 -
Linux使用解压命令unzip报错:unzip: cannot find zipfile directory in one of xxx.zip
在linux服务器下使用rz上传压缩文件,用unzip命令解压zip包。报这种错误说明在文件上传或下载的过程中出现了文件丢失的情况,需要使用。,然后使用unzip命令或jar命令解压压缩文件。原创 2023-02-12 21:23:15 · 10374 阅读 · 0 评论 -
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.
报错:ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.使用下面的版本安装新版本的tensorboard。tensorboard的版本太低了。安装新版本的tensorboard。原创 2022-10-27 10:19:36 · 4993 阅读 · 24 评论 -
【WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, st】
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, st】原创 2022-10-07 11:00:00 · 21365 阅读 · 1 评论 -
报错FloatingPointError: Loss became infinite or NaN at iteration=88!
FloatingPointError: Loss became infinite or NaN at iteration=88!FloatingPointError: Loss became infinite or NaN at iteration=88!FloatingPointError: Loss became infinite or NaN at iteration=88!原创 2022-10-05 23:17:37 · 11697 阅读 · 1 评论 -
pip安装termcolor失败解决方法+使用方法
pip安装termcolor失败解决方法在本文末尾!!!!pip安装termcolor失败解决方法在本文末尾!!!!ANSII Color formatting for output in terminal. 利用termcolor查看log,进行代码调试,清晰标出自己想要查看的部分。原创 2022-10-05 23:14:49 · 12540 阅读 · 0 评论 -
PyTorch 报错:TypeError: exceptions must derive from BaseException
PyTorch 报错:TypeError: exceptions must derive from BaseException。PyTorch 报错:TypeError: exceptions must derive from BaseException。PyTorch 报错:TypeError: exceptions must derive from BaseException。PyTorch 报错:TypeError: exceptions must derive from BaseException原创 2022-10-06 10:45:00 · 12812 阅读 · 0 评论 -
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.原创 2022-10-05 07:30:00 · 11376 阅读 · 0 评论 -
AttributeError: module ‘torch.jit‘ has no attribute ‘_script_if_tracing‘
torvh使用提示。AttributeError: module 'torch.jit' has no attribute '_script_if_tracing'原创 2022-10-04 06:30:00 · 23741 阅读 · 0 评论 -
TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
运行程序,出现报错信息TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。原创 2022-10-03 10:43:57 · 10031 阅读 · 0 评论 -
解决 RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
解决 RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR原创 2022-10-03 10:39:45 · 9304 阅读 · 2 评论 -
RuntimeError: NCCL error in:XXX,unhandled system error, NCCL version 2.7.8
分布式训练中遇到这个问题,RuntimeError: NCCL error in:XXX,unhandled system error, NCCL version 2.7.8原创 2022-10-03 10:38:21 · 9888 阅读 · 0 评论 -
RuntimeError: Address already in use
问题描述:Pytorch用多张GPU训练时,会报地址已被占用的错误。其实是端口号冲突了。每次只要重新修改master_port。原创 2022-10-03 10:33:53 · 8775 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘pydensecrf‘解决办法
在运行train.py时出现了ModuleNotFoundError: No module named ‘pydensecrf’ 问题。原创 2022-07-11 20:09:59 · 4767 阅读 · 0 评论 -
RuntimeError: CUDA error (10): invalid device ordinal
在 Pytorch 读取参数时,报错 RuntimeError: cuda runtime error (10) : invalid device ordinal。造成这个错误的原因主要是本地只有一个 GPU (GPU:0),而程序中使用 GPUs:1。因此,在程序中找到定义 device 的地方,我的如下:将其中 "cuda:1" 修改为 "cuda:0",程序将不在报错。或者你的配置信息在yaml中:修改对应部分即可......原创 2022-07-11 20:07:34 · 5616 阅读 · 0 评论 -
解决window移植到linux shell执行Python脚本提示找不到模块问题:
调试python工程时代码正常执行,但远程执行时,导入模块时提示找不到模块,即使模块就在当前工程目录下也不行2、直接修改系统的环境变量4、sys.append()详细说明当我们导入一个模块时:import XXX,默认情况下python解释器会搜索当前目录、已安装的内置模块和第三方模块,如果都搜索不到,则会报错。我们的搜索路径存放在sys模块中的path中,sys.path是当前路径的一个列表。[即默认路径可以通过sys.path来打印查看]sys.path是一个列表list,它里面包原创 2022-07-11 20:01:06 · 4520 阅读 · 0 评论 -
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
代码莫名报错:AttributeError: 'version_info' object has no attribute '__version__'解决:pip install pyparsing==2.4.7原创 2022-07-11 19:58:50 · 11207 阅读 · 1 评论 -
解决ImportError: cannot import name ‘NoReturn‘报错
复现论文时,报错:ImportError: cannot import name ‘NoReturn‘ 尝试 pip install 安装 发现并没有这么简单Python版本(3.6.1)与pip版本(21.2.3)不匹配。原创 2022-07-11 19:57:24 · 9726 阅读 · 0 评论 -
【完美解决】RuntimeError: one of the variables needed for gradient computation has been modified by an inp
【就看这一篇就行】RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [256]] is at version 4; expected version 3 instead. Hint: enable anomaly detection to find the operation that fai原创 2022-07-11 19:49:27 · 71368 阅读 · 61 评论 -
TabError: inconsistent use of tabs and spaces in indentation
本文使用PyCharm的格式化代码功能解决TabError: inconsistent use of tabs and spaces in indentation。当把代码从别处复制进来PyCharm,然后运行报错:TabError: inconsistent use of tabs and spaces in indentation这个报错的意思是说IDE分不清tab和空格,说明你的代码中混用了tab和空格。传统的方式是找出代码中报错的地方,然后修改。具体操作是:Code -->Reformat Code原创 2022-06-05 10:50:08 · 2228 阅读 · 0 评论 -
【解决】YOLOv6.1安装requirements.txt报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x84
案例描述:使用YOLOV5时,报错解决UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x84 in position 285: illegal multibyte sequence解决方案:在C:\ProgramData\Anaconda3\lib\distutils\dist.py"文件搜索read将parser.read(filename)修改为parser.read(filename, 'utf-8')然后原创 2022-04-30 11:00:40 · 2939 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘sentencepiece‘
conda install sentencepiece原创 2022-04-23 16:52:12 · 21354 阅读 · 0 评论 -
一条龙操作有效解决PermissionError: [WinError 5] 拒绝访问的问题
1 问题描述当在使用pip install 安装包时,如:pip install scrapy scrapyd scrapyd-client spiderkeeper出现报错:PermissionError: [WinError 5] 拒绝访问。: ‘c:\programdata\anaconda3\lib\site-packages\dateutil\easter.py’2 解决办法:通过更改ananconda的权限解决2.1 找到programdata下anaconda3的pyth原创 2022-04-23 16:51:13 · 15795 阅读 · 3 评论 -
AttributeError: ‘version_info‘ object has no attribute ‘version‘
AttributeError: ‘version_info‘ object has no attribute ‘version‘解决方法为:pip install pyparsing==2.4.7原创 2022-04-23 16:46:17 · 5658 阅读 · 3 评论 -
Pycharm报错:Process finished with exit code -1066598274 (0xC06D007E)
【问题描述】pycharm运行到np.linalg.slogdet()时报错Process finished with exit code -1066598274 (0xC06D007E),检查发现该函数输入shape就会报错【解决方法】将python3.8换成python3.6,问题解决!(还是老老实实用3.6吧 -·- )...原创 2022-04-23 16:40:54 · 4345 阅读 · 0 评论 -
numpy数组中冒号[:,:,0]与[...,0]的区别
先随机产生一个[3,4,5]的numpy数组。则该x维度是3,shape是(3,4,5),总共包含60个元素。x[:,:,0] 意思是对数组x切片,可以想象成一个正方体数据,每次切下一个面的数据。第二维取0则得出来[3,4]大小的数组,即可以验证:那么[...,0]代表了什么?首先...只能出现一次,就是说你可以,[ : , : , : ],但是[ ... , ...]就会报错。使用了 ... 之后,数字0不再是元素的index 了 , 而是 轴(axis)。下面..原创 2022-04-16 10:35:33 · 5799 阅读 · 0 评论 -
应用matplotlib的imshow函数显示彩色图像(RGB data)报错的解决方法
何时出现错误提示 :”Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers)”?在Python中,使用 matplotlib 的函数:plt.imshow(ndarray) 将输入数组显示为彩色 ( RGB ) 图像时。而且,只在处理彩色图像时出现错误提示,显示为空白图像;处理灰度图像时函数运行正常、显示图像。原因plt.imsho原创 2022-04-15 18:55:19 · 6667 阅读 · 0 评论 -
Expected more than 1 value per channel when training, got input size torch.Size
Expected more than 1 value per channel when training, got input size torch.Size训练的时候,batch size必须大于1,但是预测的时候,batch size可以等于1原因:因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。解决方法:1. 加大batch_size2.原创 2022-04-15 18:52:15 · 6026 阅读 · 1 评论 -
cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle‘
在使用opencv画矩形框的时候下面的这行出现了错误:cv2.rectangle(img, (22.0, 3.0),(33.0, 45.0), translate_color(classes[k]), 3, 1)cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle’Overload resolution failed:Can’t parse ‘pt1’. Expected seque.原创 2022-04-15 18:50:04 · 5290 阅读 · 1 评论 -
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
报错:RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton解决:img = Image.open(image_path)改为img = Image.open(image_path).convert('RGB')。完成~原创 2022-04-15 18:47:40 · 3127 阅读 · 2 评论 -
AttributeError: ‘set‘ object has no attribute ‘items‘
AttributeError: ‘set’ object has no attribute ‘items’出现这个问题,原因可能是定义的header有问题正确如下:header={“key”:“value”}如果是直接在请求数据中复制,很有可能会忽略键和值的冒号。...原创 2022-04-15 18:45:25 · 3433 阅读 · 0 评论 -
AttributeError: module ‘torch.utils‘ has no attribute ‘data‘
一、解决问题AttributeError: module 'torch.utils' has no attribute 'data'二、解决思路属性错误:模块的'torch.utils'没有属性'data'三、解决方法只需在顶行添加此代码即可!import torch.utils.data # 新添加代码...原创 2022-04-23 15:18:33 · 3282 阅读 · 0 评论 -
RuntimeError: Can‘t call numpy() on Variable that requires grad. Use var.detach().numpy()
1. 问题描述如题,将PyTorch Tensor类型的变量转换成numpy时报错:RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.2. 解决办法出现这个现象的原因是:待转换类型的PyTorch Tensor变量带有梯度,直接将其转换为numpy数据将破坏计算图,因此numpy拒绝进行数据转换,实际上这是对开发者的一种提醒。如果自己在转换数原创 2022-04-15 18:43:05 · 3897 阅读 · 0 评论 -
Python带*参数和带**参数
一、带*形参1、格式:*形参名,如*args2、数据类型:元组3、传参方式:接收任意个位置参数(可以不传参)。4、位置:在一个函数里只能有一个,且放在末尾(没有带**形参的情况下)。二、带**形参1、格式:**形参名,如**kwargs2、数据类型:字典3、传参方式:接收任意个关键字参数(可以不传参)。4、位置:在一个函数里只能有一个,且放在末尾。def foo(n,*args,**kwargs): print("n=",n,"*args=",args,..原创 2022-04-09 19:54:59 · 2830 阅读 · 0 评论