最近在学习掩码引导的注意力机制(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)
如果能够运行,那就是安装好了!
文章介绍了如何在Ubuntu18.04环境下,为使用MGAN模型回溯到mmdetectionv1.2.0版本,包括安装Pytorch1.4.0,处理cublas_v2.h缺失错误,以及验证安装成功的详细步骤。
4219

被折叠的 条评论
为什么被折叠?



