[踩坑记录]mmdetevtion v1.2.0的安装与调试

文章介绍了如何在Ubuntu18.04环境下,为使用MGAN模型回溯到mmdetectionv1.2.0版本,包括安装Pytorch1.4.0,处理cublas_v2.h缺失错误,以及验证安装成功的详细步骤。
部署运行你感兴趣的模型镜像

最近在学习掩码引导的注意力机制(mask-guided-attention),需要用到github上一位佬实现的MGAN。但是这个是用mmdetection的1.2.0版本实现的,现在主流版本都到2.20多了,得重新退旧版的。

配置:Ubuntu 18.04, Python 3.7, CUDA 10.1, cudNN 7, NVCC, Pytorch 1.4.0, VNC

pytorch版本要求:mmdet v1.2需要的pytorch版本是1.1.0~1.4.0,必须在这个区间内,但是强烈推荐安装1.3.0版本或者1.4.0版本的pytorch。我使用的1.4.0版本,torchvision是0.5.0。

过程(默认你已经安装好的torch和torchvision):

第一步:克隆对应版本的mmdetection

git clone -branch v1.2.0 https://github.com/open-mmlab/mmdetection

第二步:下载对应的mmcv。这里一定要注意,别下别的版本的,我相信用过mmdetection v2.x的朋友们都被mmcv困扰过,在v1.x里,mmcv一样很烦

pip install mmcv==0.5.0

第三步:cd mmdetevtion,进入mmdet的目录,把它所需的一切东西都安装好(写在requirements.txt了)

pip install -r requirements.txt

第四步:开始安装(依然在mmdet的目录下)

python setup.py develop

这个时候,你可能会遇到一个错误:fatal error: cublas_v2.h: No such file or directory;这是因为一些未知的GCC编译原因,以及你的torch版本和你的cuda版本有点对应不上这个mmdetection v1.2,它太古老了。

fatal error: cublas_v2.h: No such file or directory

这个时候,在你的命令行运行以下两行代码:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/libcublas-dev_10.1.0.105-1_amd64.deb
dpkg -i libcublas-dev_10.1.0.105-1_amd64.deb

然后清理一下之前安装时候的残余:

python setup.py clean --all

再重新安装:

python setup.py develop

安装的时候会有一堆warning,别理它们,这可能要花费很久。

第五步:验证你的安装,这里感谢:Ubuntu18.04+pytorch1.3+mmdetection v1.2_yzb_123的博客-优快云博客

#在demo文件夹下,新建demo.py,将代码中'testing image you want to detect.jpg',改为自己想要测试的图片
import argparse
import cv2
import torch
from mmdet.apis import inference_detector, init_detector, show_result

def parse_args():
    parser = argparse.ArgumentParser(description='MMDetection webcam demo')
    parser.add_argument('--config', default='../configs/faster_rcnn_r50_fpn_1x.py', help='test config file path')
    parser.add_argument('--checkpoint', default='../checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth',
                        help='checkpoint file')
    parser.add_argument('--device', type=int, default=0, help='CUDA device id')
    parser.add_argument(
        '--camera-id', type=int, default=0, help='camera device id')
    parser.add_argument(
        '--score-thr', type=float, default=0.5, help='bbox score threshold')
    args = parser.parse_args()
    return args

args = parse_args()
model = init_detector(
        args.config, args.checkpoint, device=torch.device('cuda', args.device))
img = 'testing image you want to detect.jpg'
show_img = inference_detector(model, img)
show_result(img, show_img, model.CLASSES, score_thr=args.score_thr)

如果能够运行,那就是安装好了!

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Amigo_5610

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值