pycharm相关错误及解决(一)——AlphaPose


(一)AlphaPose

 

1.项目介绍

项目GitHub地址:GitHub - Amanbhandula/AlphaPose: AlphaPose Implementation in Pytorch along with the pre-trained wights

注:这只是AlphaPose项目的简化版本,原版地址为:GitHub - MVIG-SJTU/AlphaPose: Real-Time and Accurate Full-Body Multi-Person Pose Estimation&Tracking System,这里以简化版本为例说明。

背景本机操作系统为win 10,通过win 10上的pycharm远程连接Linux服务器运行该项目。由于本机上没有摄像头,所以只测试了图片和视频,没有测试摄像头(如果想测试摄像头可以参考文末视频)。

 

2.环境介绍

(1)cuda 10.2(参考视频推荐10.1)

查看cuda版本:

import torch
print(torch.version.cuda)

 

(2)cudnn 7.6.5(参考视频推荐7.6)

查看cudnn版本:

import torch
print(torch.backends.cudnn.version())    # 输出7605对应版本为7.6.5

 

(3)pytorch (参考视频推荐cuda 10.1对应的版本,选定了pytorch版本(4)和(5)也就安装好了)

(4)torch 1.10.0 (参考视频推荐1.7.1)

查看torch版本:

import torch
torch.__version__     # 注意这里是双下划线

 

(5)torchvision 0.11.1 (参考视频推荐0.8.2)

查看torchvision版本:

import torchvision
torchvision.__version__   # 注意这里是双下划线

 

 

 

结果如图1所示:

 

图1

 

(6)python 3.8

 

3.pycharm配置AlphaPose环境

参考:https://blog.csdn.net/weixin_42419611/article/details/115797628

 

 

 

4.下载模型

参考文末视频链接P13

 

5.依赖项

可以直接用pip命令运行requirements.txt文件来安装依赖项,但是不知道为什么我的pip命令运行不起来,只能手动下载requirements.txt中的包(手动下载方法如下),然后再通过Xftp拉到Linux服务器上,放到/data/z*y/anacoda3/envs/NewPytorch/lib/python3.8/site-packages目录下即可(这个目录在之后用到很多次,主要是包的问题)。但是要注意!把下载好的包解压缩后拉到Linux服务器时,要将名字改为和requirements.txt文件中的名字一样,否则运行的时候还会找不到包。

手动下载依赖项的两种方法:

(1)在这个地址下载所需要的包:https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/

 

下载时,在上面这个链接后面直接添加所需要的包名,如要下载visdom这个包:https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/visdom

(2)在GitHub中查找要下载的包名进行下载

附:使用pip时所报的错误,即使按照网上所说换成如下豆瓣源也不行

pip install visdom -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

Looking in indexes: http://pypi.douban.com/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f46159fcac0>: Failed to establish a new connection: [Errno -2] 未知的名称或服务')': /simple/visdom/

total一直从4到0,运行不成功。

 

6.问题及解决

(1)问题:

from scipy.__config__ import show as show_config
ModuleNotFoundError: No module named 'scipy.__config__'

原因:scipy和numpy版本不兼容,scipy版本太高,没有scipy.__config_(可以去Linux服务器中/data/z*y/anacoda3/envs/NewPytorch/lib/python3.8/site-packages目录下看看scipy文件夹中是否有这个文件)

解决:降低scipy版本(我这里下载的是1.3.2),重新手动下载。

另外,可以通过pip show numpy查看numpy版本,我这里是1.21.2。

(2)问题:AttributeError: module 'cv2' has no attribute 'VideoWriter_fourcc'

原因:opencv3.0中才有这个函数

解决:删除之前的opencv包,重新手动下载opencv_contrib_python-3.4.11.39-cp38-cp38-manylinux2014_x86_64.whl和opencv_python-3.4.11.39-cp38-cp38-manylinux2014_x86_64.whl

(3)问题:AssertionError: Cannot capture source

原因:没有找到源

解决:在README.txt中找到这一行参数(图2)复制到指定位置(图4中所示位置)即可。

 

 

 

图2

注:A、如果是测试视频,复制图2中这行参数;如果测试图片,复制图2中上面那一行参数。

    B、如果是测试视频,${path to video}改为测试视频所在的目录(要绝对路径,否则会出问题),具体到视频的名字;如果测试图片,${img_directory}改为测试图片所在的目录(这里不用绝对路径,/examples/demo即可),而不用具体到图片名字(因为将其当作list处理了)。

    C、不管是测试视频还是图片,后面的--outdir之后的路径都要改为绝对路径,否则最后处理之后的图片不能被保存。

打开Edit Configuarions,如图3所示。

 

 

 

图3

将图2中复制的参数粘贴到图4位置即可。

 

 

图4

注:A、如果测试图片,左侧选中demo;如果测试视频,左侧选中video_demo。

    B、测试视频--video /data/z**y/PoseEstimation/AlphaPose/examples/testvideo/1.mp4 --outdir examples/resvideo/ --save_video --sp

       测试图片--indir examples/demo --outdir /data/z**y/PoseEstimation/AlphaPose/examples/resimg --save_img --vis --sp

(4)问题:测试图片时,

data_loader = ImageLoader(im_names, batchSize=args.detbatch, format='yolo').start()
NameError: name 'im_names' is not defined

具体如图5所示:

 

 

 

图5

 

 

 

原因:无法获取输入图像的名字,可能参数没有配置好

解决:如图4所示。

(5)问题:TypeError: 'module' object is not callable

定位到demo.py第72行:im_names_desc =tqdm(range(data_len))

原因:https://blog.csdn.net/coding_zhang/article/details/89403135

解决:将该行改为:im_names_desc = tqdm.tqdm(range(data_len))

(6)问题:[W CudaIPCTypes.cpp:15] Producer process has been terminated before all shared CUDA tensors released. See Note [Sharing CUDA tensors]

具体如图6所示:

 

 

图6 

解决:图4中的parameter最后要加上--sp,单线程。

(7)问题:最后没有报错,但是也没有生成处理之后的图片或者视频,或者是运行后的图像或视频未被保存。

原因:A、保存路径不是绝对路径

    B、没有指定要保存图片或视频

    C、测试图像时,参数没有加--vis,所以图像无法实时显示;测试视频时,视频本身就无法实时显示,只能通过保存的文件查看。

解决:A、参考问题(3)的注

    B、图4中的parameter最后要加上--save_img(保存图像)或者--save_video(保存视频)

    C、测试图像时,图4中的parameter最后要加上--vis(图像可见)

如果还未解决,见问题(8)。

另外,可以参考opt.py文件,里面对参数都有详细说明,如图7所示。

 

 

图7

(8)问题:qt.qpa.xcb: could not connect to display 

具体如图8所示:

 

 

图8

原因:处理之后的图片无法显示。配置XManager 11+XShell 7即可。

解决配置DISPLAY变量(先查看本机的DISPLAY变量,只能通过XShell输入echo $DISPLAY,不知道为什么在cmd中查不出来),运行之后,提示要下载Xmanager。

然后在pycharm中添加DISPLAY变量,方法参考该链接:https://blog.csdn.net/qq_34907927/article/details/116597908
Xmanager和pycharm配置参考:https://www.bbsmax.com/A/QV5Zyx3eJy/

(9)问题:测试视频时,AssertionError: Cannot capture source

原因:没找到源

解决:见问题(3)、注B

(10)问题:

qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/data/z**y/anacoda3/envs/NewPytorch/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

为了找到更详细的报错信息,

edit configuration输入环境变量QT_DEBUG_PLUGINS为1。

图9

详细错误:

QElfParser: '/data/z**y/anacoda3/envs/NewPytorch/bin/2to3-3.8' is not an ELF object"'/data/z**/anacoda3/envs/NewPytorch/bin/2to3-3.8' is not an ELF object"not a plugin

具体错误如图10所示:

 

 

图10 

原因:A、edit configurations参数错误。最后是--save_video而不是--vis(和测试图片时不一样)。

    B、edit configurations中DISPLAY参数错误,通过Xshell查找(查找方法参考问题(8))。

解决:A、见问题(3)、注B

    B、修改edit configurations中DISPLAY参数的

(11)问题:Producer process has been terminated before all shared CUDA tensors released

原因:edit configurations参数没有指明单线程。

解决:最后加上--sp就可以了,完整见问题(3)、注B

(12)问题:图片清晰度以及图片一闪而过的问题。

解决:参考https://blog.csdn.net/Zhangrx_/article/article/details/107810537

 

 

环境搭建主要参考:https://www.bilibili.com/video/BV1hb4y117mu?from=search&seid=6563444869225322&spm_id_from=333.337.0.0

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM