异常处理
进行文件和代码调试时的异常情况和bug处理
Wanderer001
AR/VR软件与硬件技术:图像增强、图像分类、语义分割、目标检测、目标跟踪、风格迁移、强化学习、三维重建、SLAM
展开
-
命令行执行 ModuleNotFoundError: No module named ‘...‘
在一个项目中如果我们使用类似pycharm这样的软件来写项目,项目中有些文件需要单独执行的时候,我们通常会使用软件自带的执行按钮来运行python脚本,但是有时候我们需要使用在命令行内敲击python run.py这样的方式来运行脚本,这时就会出现ModuleNotFoundError: No module named ‘…’ 这样的报错。这样报错的原因是我们import模块的时候使用的是相对路径,所以命令行运行的时候就找不到模块的路径。这里解决办法是在文件最上面,也就是import模块之前,加上类似如原创 2022-05-07 12:30:15 · 4624 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘skbuild‘
下面介绍针对类的测试,很多程序中都会用到类,因此能够证明你的类能够正确地工作会大有裨益。如果针对类的测试通过了,你就能确信对类所做的改进没有意外地破坏其原有的行为。1.各种断言的方法python在unittest.TestCase类中提供了很多断言方法。断言方法检查你认为应该满足的条件是否确实满足。如果该条件满足,你对程序行为的假设就得到了确认。你就可以确信其中没有错误。如果你认为应该满足...原创 2022-02-20 12:03:50 · 664 阅读 · 0 评论 -
ValueError: not enough values to unpack (expected 4, got 3)
用Tensorflow跑自己的数据集时,用saver将参数保存在checkpoint中。后来在在测试的时候,用saver.restore导入模型到Session中,报如下错误:tensorflow.python.framework.errors_impl.InvalidArgumentError exception str() failed出现这个错误的原因是:我修改了网络的优化方法...原创 2022-02-18 12:04:42 · 5427 阅读 · 0 评论 -
non-default parameter follows default parameter
想系统的学学webgl,发现在windows系统下浏览器竟然不支持WebGL,下面是在网上搜索的解决方案:打开firefox软件,在地址栏中输入:about:config,会出现FireFox的配置信息,在Search中输入webgl,即会出现webGL相关的配置信息:将webgl.force-enabled设置为true 将webgl.disabled设置为false 在过滤器...原创 2022-02-18 12:04:48 · 775 阅读 · 0 评论 -
安装labelImg时报错ModuleNotFoundError: No module named ‘libs.resources‘
安装LabelImg到最后一步,打开LabelImg时报错:解决方案:将LabelImg-master中的resources.py复制到lib文件中,如下图:再输入命令即可打开LabelImg:承接Matlab、Python和C++的编程,机器学习、计算机视觉的理论实现及辅导,本科和硕士的均可,咸鱼交易,专业回答请走知乎,详谈请联系QQ号757160542,非诚勿扰。...原创 2022-03-24 13:09:07 · 1303 阅读 · 0 评论 -
ImportError: cannot import name ‘imread‘ from ‘scipy.misc‘
pip install scipy==1.2.0#将scipy库的版本还原至1.2.0版本from imageio import imread#使用imageio库同样能够完成此功能原创 2022-02-26 10:38:05 · 484 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘imageio‘
pip install imageio原创 2022-02-26 10:38:13 · 1898 阅读 · 1 评论 -
RuntimeError: given chunk sizes don‘t sum up to the tensor‘s size (sum(chunk_sizes) == 48, but expec
博主这个问题是在训练CenterNet时遇到的,解决方法为使得chunk_size和自己可用的GPU数匹配。剩下的就是调整batch_size了。原创 2022-02-26 10:38:17 · 290 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘pycocotools‘
概要:由于缺少pycocotools包引发的错误,而pycocotools包需要cython和C编译器,所以在安装cython之前需要先安装Cython。解决办法:安装cython pip install -U cython Linux安装pycocotools pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI" Wind原创 2022-02-26 10:38:33 · 771 阅读 · 0 评论 -
RuntimeError: Trying to backward through the graph a second time...
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.torch.autograd.backwardtorch.autograd.backward(tensors, grad_tensors=None, retain原创 2022-02-27 13:28:51 · 3950 阅读 · 0 评论 -
ValueError: num_samples should be a positive integer value, but got num_samp=0
跑baseline调试代码时遇到了一些问题,当时报了错,反复找不到原因,后来受到了下面这篇博客的启发终于解决了问题,我就将这个问题再总结一下:https://blog.csdn.net/xnmc2014/article/details/85557384出现的问题的地方可能是如下的地方:调用DataLoder时注意参数self.train_dataloader = DataLoader(train_dataset, batch_size=TrainOption.train_batch_size,原创 2022-03-01 13:30:49 · 5293 阅读 · 1 评论 -
Building wheel for opencv-python (PEP 517) ... /
安装opencv时候总是报错,呜,错误如上,修改方法就是加上版本信息,采用低版本的opencv。pip install opencv-python==3.4.9.31原创 2022-03-01 13:31:07 · 2944 阅读 · 1 评论 -
ModuleNotFoundError: No module named ‘mmcv._ext
问题:在安装mmdetection时,安装mmcv经常出现、ModuleNotFoundError: No module named ‘mmcv._ext’ 问题。环境:ubuntu16.04+Anaconda3+python3.7.7+cuda10.0+cuDNN7.6.4.3解决方法:安装时不要使用:pip install mmcv使用:pip install mmcv-full如果还有奇奇怪怪的问题请使用与自己环境相匹配的mmcv版本,如:pip install mmc原创 2022-02-28 10:43:55 · 10303 阅读 · 0 评论 -
AssertionError: MMCV==1.1.0 is used but incompatible. Please install mmcv>=1.0.5, <=1.0.5.
Traceback (most recent call last): File "tools/test.py", line 12, in <module> from mmdet.apis import multi_gpu_test, single_gpu_test File "d:\a文件盘\a项目\cv\mmdetection-master\mmdet\__init__.py", line 25, in <module> f'MMCV=={mmcv.__v.原创 2022-02-28 10:43:58 · 7940 阅读 · 4 评论 -
TypeError: string indices must be integers
Python3报错:TypeError: string indices must be integers问题如下图所示:原因在于for循环中的i代表String类型变量,而List中的i代表Int类型变量,二者冲突,导致出错。原创 2022-03-03 12:06:07 · 1433 阅读 · 0 评论 -
RuntimeError: cannot perform reduction function max on tensor with no elements because the operation
计算损失的时候产生了空标签,解决方法之一:检查difficult是不是导致了这个问题。原创 2022-03-15 08:22:23 · 2121 阅读 · 0 评论 -
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying
下面的程序会报错:RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~` or `logical_not()` operator instead.mask = torch.Tensor([True,True,False]).type(torch.bool)a = torch.Tensor([3,2,原创 2022-03-04 12:27:26 · 2407 阅读 · 0 评论 -
TypeError: conv2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
这里出现类似错误往往是因为,conv2d()函数的第一个参数,需要时一个tensor行的数据,然而却赋值成了not后给的类型。我出现问题的原因是,中间有一个函数缺少返回值,因此会造成NoneType的错误。其余错误类似,只需把送给conv2d()的数据转换成tensor即可;这里:numpy 和 tensor数据相互转换的方法:1.numpy->tensordata = torch.tensor(data)2.tensor->numpy非训练数据(训练结束后的tensor原创 2022-03-04 12:25:57 · 6468 阅读 · 0 评论 -
RuntimeError: result type Float can‘t be cast to the desired output type Long
使用BCEWithLogitsLoss()时RuntimeError: result type Float can't be cast to the desired output type Long使用BCEWithLogitsLoss(output,target),output 为float类型,target为int64,报错RuntimeError: result type Float can't be cast to the desired output type Long参考提问,提到原创 2022-03-04 12:26:06 · 13230 阅读 · 27 评论 -
double free or corruption
今天遇到这样一个问题 *** glibc detected *** ./cupd: double free or corruption (!prev): 0x093b1208 ***错误出现这个问题的可能原因是1、多次释放同一内存区,需要检查代码,是否出现了对同以内存区释放两次以上的地方。 2、内存区溢出,malloc申请的内存区大小有限,如果操作不当,要存储的数据大于内存...原创 2022-03-07 14:23:43 · 3016 阅读 · 0 评论 -
pytorch报错RuntimeError: DataLoader worker (pid(s) xxx) exited unexpectedly
报错pytorch报错RuntimeError:DataLoader worker (pid(s) ... exited unexpectedly解决因为torch.utils.data.DataLoader中设置了num_works=4,也就是多线程读取。根据其他方法,我设置num_works=1或者num_works=0都不行。最后重装了pytorch,就可以了。pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -原创 2022-03-07 14:23:49 · 16558 阅读 · 3 评论 -
cudaCheckError() failed : invalid device function解决方法
先将出现的问题截图,上图所示为我遇见的错误。我在服务器上(ubuntu14.04),运行smallcorgi/Faster-RCNN的tensorflow代码时候出现的问题,我的显卡是TeslaK40。在百度后发现根本没有切实可行的方法,最后还是使用Google解决了问题,发现在运行代码时候在lib文件夹下面执行make操作的时候需要将make.sh文件进行修改,将arch参数从sm_37改为sm_35。为大家附上参数列表。承接Matlab、Python和C++的编程,机器学习、计算机...原创 2022-03-14 10:48:14 · 1304 阅读 · 0 评论 -
【python】from scipy.misc import imread报错:ImportError: cannot import name imread
from scipy.misc import imread报错:ImportError: cannot import name imread在网上找了解决方法,大致如下:1.安装Pillow(imread依赖于pillow)2.检查Pillow和scipy是不是安装在同一路径3.其他但是,这些并不能解决我的问题,最后在某处评论看到如下方法:将scipy降级到1.2.1版本(pip install scipy==1.2.1)亲测可用但是,会有这样的红字(不影响使用和输出结果)意思是,i原创 2022-03-19 10:23:04 · 2750 阅读 · 1 评论 -
Pytorch 读取参数错误 RuntimeError: cuda runtime error (10) : invalid device ordinal
博主实在使用Pytorch分布式训练时遇到这个问题的,原因是程序中GPU数量和指定的GPU数量不一样导致的。底层查看之后,发现了问题。原来是Pytorch在参数保存的时候,会注册一个跟原来参数位置有关的location。比如原来你在服务器上的GPU1训练,这个location很可能就是GPU1了。而如果你台式机上只有一个GPU,也就是GPU0的时候,那么这个参数带进来的Location信息于你的台式机不兼容,就会发生找不到cuda device的问题了。...原创 2022-03-23 14:45:17 · 1207 阅读 · 1 评论 -
dlerror: libcudart.so.10.0: cannot open shared object file ...
2019-11-11 23:37:00.153893: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/c.原创 2022-03-23 14:46:02 · 1547 阅读 · 0 评论 -
mask-rcnn benchmark 错误:‘List’ object has no attribute ‘resize‘ 的解决方法
首先这个问题出现是由于我下载的GitHub源码是别人的,不是Facebook官方的才导致。如果你也是从别人那下载的,很有可能别人改动了代码导致此bug。解决方法:定位:maskrcnn_benchmark/data/datasets/coco.pyline:66, 95, 96self.transform 改为 self._transform如果你的代码是 self._transform,那这里的情况可能不适用你,需要查找其他其原因。另外一种问题:‘Image’ objec.原创 2022-03-25 11:09:16 · 809 阅读 · 0 评论 -
cython编译错误
running build_extskipping ‘bbox.c’ Cython extension (up-to-date)skipping ‘nms.c’ Cython extension (up-to-date)building ‘cython_bbox’ extension{‘gcc’: [’-Wno-cpp’, ‘-Wno-unused-function’]}gcc -pthread -B /home/gsadhasivam/anaconda3/envs/r3det/compiler.原创 2022-03-25 11:09:27 · 1769 阅读 · 0 评论 -
no module named‘pycocotools_mask‘
在使用tensorflow object-detection api 中出现了这个问题我以为是cocoAPI没装好,在tensorflow/models/research下有一个pycocotools,程序会优先导入这个包,但是这个包里的_mask并不是python程序,把这个包删了。在 models/research下重新安装,命令为git clone https://github.com/cocodataset/cocoapi.gitcd cocoapi/PythonAPImakemake in原创 2022-03-25 11:09:58 · 1291 阅读 · 0 评论 -
ImportError: libcublas.so.9.0: cannot open shared object file: No such file
可能原因,CUDA版本不对1、查看下版本信息cat /usr/local/cuda/version.txt 2、根据CUDA和tensorflow版本对应的关系表,检查自己的版本是否匹配3、如果不匹配请安装相应的TensorFlow或者CUDA版本安装对应版本TensorFlow的GPU版本pip install tensorflow-gpu==版本号安装对应版本的CUDA参考:https://blog.csdn.net/wf19930209/ar.原创 2022-03-25 11:10:07 · 2231 阅读 · 0 评论 -
ValueError: could not broadcast input array from shape (4) into shape (0)
Can you share your training prototxt file? This error is due to dimension mismatch.The size of "bbox_pred" layer should be 4*"num_classes". Also, make sure that the "cls_score" layer is the same size as "num_classes" layer.承接Matlab、Python和C++的编程,..原创 2022-03-25 11:10:34 · 2969 阅读 · 1 评论 -
conda环境opencv报错cv2.error:
conda环境中使用opencv时,可能会报以下错误:cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/highgui/src/window.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you原创 2022-03-25 11:10:50 · 9831 阅读 · 1 评论 -
python无法导入自定义类
问题描述是python3环境;在C:\Python36\Lib\site-packages\mekk\xmind目录下有__init__.py、document.py、id_gen.py和xmlutil.py四个文件;但是在引入mekk.xmind的时候,提示from document import XMindDocument, ALL_MARKS as XMIND_MARKS找了很久,终于知道解决办法:将C:\Python36\Lib\site-packages\mekk\xmind目录下原创 2022-04-06 10:10:05 · 1151 阅读 · 1 评论 -
ValueError: numpy.ufunc size changed, may indicate binary incompatibility.
最近学习frcnn编译过程中,有个错误记录一下:ValueError: numpy.ufunc size changed,may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject上网搜了一下,发现两种相关错误,有一种是因为numpy版本过高的问题,错误大致是这样的:ValueError: numpy.ufunc size changed, may indicate bin原创 2022-04-29 07:48:26 · 2710 阅读 · 1 评论 -
SSD-pytorch踩坑及修正(StopIteration)
SSD-pytorch踩坑(StopIteration)ssd-pytorch代码链接 bug 解决方案ssd-pytorch代码链接github上的:https://github.com/amdegroot/ssd.pytorchbug这篇博客写的基本上没什么问题,但是其实也有坑。https://blog.csdn.net/sinat_39307513/article/details/84646177在这篇博客的评论区里面出现了“博主您好,我训练时候损失降得又快又低,但是运行e原创 2022-04-23 08:14:56 · 866 阅读 · 0 评论 -
Ubuntu16 安装cocoapi中的x86_64-linux-gnu-gcc: error: pycocotools/_mask.c: No such file or directory 问题
在官方的github的issue中大家讨论了这个问题:https://github.com/cocodataset/cocoapi/issues/172最全面的方案如下 whether you have installed cython in the correct version. Namely you should install cython for python2/3 if you use python2/3 whether you have downloaded the w原创 2022-04-06 10:10:56 · 755 阅读 · 0 评论 -
error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow‘
import cv2 as cvimport numpy as np#读取图片img=cv.imread(r'E:\Downloaded\pexels\The sea21471.jpeg',1)#获取图片的长宽信息sp=img.shapelength=sp[1]heighth=sp[0]print('加载的图片的宽度:{},高度:{}'.format(length,heighth))#显示窗口和图片cv.namedWindow('原图片')cv.imshow('.原创 2022-04-07 10:57:53 · 1268 阅读 · 0 评论 -
anaconda下载包时网络连接错误的解决方法(CondaHTTPError:HTTP 000 connection failed for url)
不论用conda安装一些python的包,还是创新独立的编程环境时,出现以下报错:在anaconda安装完毕之后,通常要做的就是配置更新,这一步主要将conda下载源从国外的网站转移到国内网站,这样就可以大大缩减下载时间,防止出现以上网络问题。该问题的解决方法只有一种,那就是更换conda下载源。下载源通常位于~/.condarc文件中,或者/home/用户名/.condarc文件中。查看源的方式:方法1:除了vim,也可用cat/more/less显示vi ~/.condarc原创 2022-04-06 10:12:22 · 4045 阅读 · 0 评论 -
Conda安装过程中InvalidArchiveError
如果在conda安装的过程中遇到类似:InvalidArchiveError("Error with archive /home/blah/.conda/pkgs/pytorch-1.3.0-py3.7_cuda10.0.130_cudnn7.6.3_0.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nFailed to crea原创 2022-04-06 10:12:09 · 2094 阅读 · 0 评论 -
error: command ‘/usr/bin/nvcc‘ failed with exit status 1
/home/user4/anaconda3/lib/python3.7/site-packages/torch/include/ATen/cuda/CUDAContext.h:7:10: fatal error: cublas_v2.h: No such file or directory #include <cublas_v2.h> ^~~~~~~~~~~~~compilation terminated.error: command '/usr/bin/nvcc' .原创 2022-03-29 18:50:29 · 2525 阅读 · 0 评论 -
Python把二维numpy数组转变为灰度图
from PIL import Image# image_array是归一化的二维浮点数矩阵image_array *= 255 # 变换为0-255的灰度值im = Image.fromarray(image_array)im = im.convert('L') # 这样才能转为灰度图,如果是彩色图则改L为‘RGB’im.save('outfile.png')承接Matlab、Python和C++的编程,机器学习、计算机视觉的理论实现及辅导,本科和硕士的均可,咸鱼交易,专业回答请走知乎.原创 2022-03-26 09:21:42 · 11392 阅读 · 0 评论