MMDetection框架入门教程(一):Anaconda3下的安装教程(mmdet+mmdet3d)
本博客基于下列文档整理得到,有兴趣的同学可以直接阅读原文。
- GitHub - MMDetection
- GitHub - MMCV
- GitHub - MmDetection3D
- 官方说明文档 - MMDetection
- 官方说明文档 - MMDetection3D
- 官方说明文档 - MMCV
- MMDetection教程(西安交通大学)
MMDetection概述
MMDetection是MMLab家族的一员,是由香港中文大学和商汤科技共同推出的,以一个统一的架构支撑了15个大方向的研究领域。MMDetection依赖Pytorch和MMCV,因此安装之前需要先安装这两个库。
Step1: Anaconda虚拟环境搭建
打开Anaconda Prompt,创建一个新的虚拟环境mmlab
。注意我这里选择了python3.6,因为在python3.7下出现了mmdet3d.apis中的类无法无法import的情况(但mmdet3d可以import),暂时不清楚原因。
conda create -n mmlab python=3.6
然后切换到该环境下:
activate mmlab
Step2: Pytorch安装
根据Pytorch官网的教程安装Pytorch,注意根据自己电脑的CUDA版本选择。在命令行运行nvcc -V查看当前cuda版本:
另外,当前(2021.10.23)MMCV最新仅支持到pytorch-1.9,安装最新的pytorch1.10会导致MMDetection无法使用,因此安装的时候需要指定pytorch版本为1.9。
conda install pytorch==1.9.1 torchvision torchaudio cudatoolkit=10.2 -c pytorch
验证pytorch安装成功:
Step3: MMCV安装
MMCV有两mmcv-full
和mmcv
两个版本,两者差别在于是否包含CUDA操作,如果不需要使用CUDA可以安装mmcv
,不过官方还是推荐安装完整版的mmcv-full
,如果处于服务器这类无法联网的环境,可以参照官方说明使用源码安装:Build MMCV from source。
pip install mmcv-full
Step4: MMDetection安装
首先从github上下载mmdetection的源码,然后根据requirements.txt安装所需的依赖库,最后执行setup.py安装mmdetection。
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements.txt
python setup.py develop
官方提供了Demo验证安装是否成功,位于./demo
文件夹下。先新建一个demo_test
工程,下载预训练模型(下载链接)放至test_demo\checkpoints
文件下,新建main.py并运行:
import osfrom mmdet.apis import init_detector, inference_detectordef demo_mmdet():base_dir = r'D:\Program Files\Third_Part_Lib\mmdetection' # mmdetection的安装目录config_file = os.path.join(base_dir, r'configs\faster_rcnn\faster_rcnn_r50_fpn_1x_coco.py')# download the checkpoint from model zoo and put it in `checkpoints/`# url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pthcheckpoint_file = r'checkpoints\faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'# 根据配置文件和 checkpoint 文件构建模型model = init_detector(config_file, checkpoint_file, device='cuda:0')# 测试单张图片并展示结果img = os.path.join(base_dir, r'demo\demo.jpg') # 或者 img = mmcv.imread(img),这样图片仅会被读一次result = inference_detector(model, img)# 在一个新的窗口中将结果可视化model.show_result(img, result, out_file=None, show=True)if __name__ == '__main__':demo_mmdet()
运行成功效果如下:
Step5: MMDetection3D安装
MMDetection3D依赖MMSegmentation,先安装MMSegmentation:
git clone https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -r requirements.txt
python setup.py develop
然后再安装MMDetection3D,这一步编译时间可能会久一点。
git clone https://github.com/open-mmlab/mmdetection3d.git
cd mmdetection3d
pip install -r requirements.txt
python setup.py develop
最后再利用官方提供的Demo,先下载预训练模型(下载链接)放至test_demo\checkpoints
文件下,然后运行下面代码:
import os
from mmdet3d.apis import inference_detector, init_model, show_result_meshlabdef demo_mmdet3d():base_dir = r'D:\Program Files\Third_Part_Lib\mmdetection3d' # mmdetection3d的安装目录config_file = os.path.join(base_dir, r'configs\second/hv_second_secfpn_6x8_80e_kitti-3d-car.py')# download the checkpoint from model zoo and put it in `checkpoints/`# url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pthcheckpoint_file = r'checkpoints\hv_second_secfpn_6x8_80e_kitti-3d-car_20200620_230238-393f000c.pth'# build the model from a config file and a checkpoint filemodel = init_model(config_file, checkpoint_file, device='cuda:0')# test a single binpcd = os.path.join(base_dir, r'demo/data/kitti/kitti_000008.bin')result, data = inference_detector(model, pcd)# show the resultsshow_result_meshlab(data,result,'',0,show=True,snapshot=False,task='det')if __name__ == '__main__':demo_mmdet3d()
运行成功效果如下:
MMDetection框架入门教程(一):Anaconda3下的安装教程(mmdet+mmdet3d)相关推荐
- centos7 mysql安装教程_centos7环境下MySQL安装教程
Linux centos7环境下安装MySQL步骤的详细介绍 安装MySQL mysql 有两个跟windows不同的地方 1).my.ini 保存到/etc/my.ini 2).用户权限,单独用户执 ...
- ROCm与tensorflow在ubuntu 18.04下的安装教程
ROCm与tensorflow在ubuntu 18.04下的安装教程 本来准备买Nvidai的显卡,可是囊中羞涩再加上听说AMD的卡也能使用tensorflow进行深度学习加速了,所以1149 ...
- Linux 下 GitLab 安装教程
Linux 下 GitLab 安装教程 安装 Linux 下载 GitLab 安装 GitLab 登录 GitLab GitLab 汉化 GitLab 设置密钥 卸载 GitLab 为了便于以后使用, ...
- Linux 下 Redis 安装教程
Linux 下 Redis 安装教程 事先准备 下载 Redis 安装 Redis 设置 Redis 开机自启动 远程访问 Redis RDM 远程访问 Redis 笔者的运行环境: CentOS S ...
- mysql linux 安装_mysql-5.7.28 在Linux下的安装教程图解
2.上传tar包到服务器到 /usr/local/src 3.卸载系统自动的Mariadb rpm -qa | grep mariadb rpm -e --nodeps mariadb-libs-5. ...
- centos7环境下MySQL安装教程
Linux centos7环境下MySQL安装教程 作者:随缘相识-(志同道合) 字体:[增加 减小] 类型:转载 时间:2017-03-17 我要评论 这篇文章主要为大家详细介绍了Linux cen ...
- Geant4在Ubuntu下的安装教程
Geant4在Ubuntu下的安装教程 Geant4是欧洲核子中心(CERN)开发的一款粒子输运模拟软件,使用蒙特卡洛(Monte carlo)算法,特长领域是高能物理.核物理等,如光子中子的辐射屏蔽 ...
- linux系统nginx安装教程,Linux下Nginx安装教程
Linux下Nginx安装教程分享,具体内容如下 1.安装编译文件及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl op ...
- Windows10 系统下cuda安装教程,小白教程 !很详细!!
Windows10 系统下cuda安装教程 1.查看适合自己电脑的cuda版本 1.点击Windows+R 输入nvidia-smi 看一下自己电脑支持的conda 版本是: 根据下图白框标出的地方可 ...
最新文章
- Keras之DNN:利用DNN算法【Input(8)→12+8(relu)→O(sigmoid)】利用糖尿病数据集训练、评估模型(利用糖尿病数据集中的八个参数特征预测一个0或1结果)
- 专辑一:爱之初体验(初级)
- Spring中的ModelAndView
- 统一项目管理平台(UMPlatForm.NET)-4.7 组织机构管理模块
- [网站seo优化] 史上最全增加外链的方法!
- Spring中AOP源码剖析
- java图书管理系统毕业设计_java图书管理系统毕业论文
- nodejs读取服务器json文件,如何使用Node.js读取JSON文件
- 路由器命令级别和用户级别
- imei服务器清除id_苹果绕过ID解锁
- 安信可LoRa快速入门指南
- 【蓝桥杯】第十三届蓝桥杯省赛 AK 攻略 —— C++ B组全真题超详细剖析
- Capture Modules 车载网络报文捕获(监听)模块(低时延、802.1AS时钟同步)
- PTA 7-10 古风排版
- Excel—PAPAYA电脑教室
- 如何对 iOS App 内购买项目进行测试?
- 动态网站要怎么通过CDN实现加速?
- iwrite复制粘贴方法
- 淘宝卖家如何设置公益宝贝
- mysql DAYOFWEEK 和 WEEKDAY函数