mmdetction使用指南

一、简介
参考:https://blog.csdn.net/Adam897/article/details/127534510
MMDetection是MMLab家族的一员,是由香港中文大学和商汤科技共同推出的,以一个统一的架构支撑了15个大方向的研究领域。MMDetection依赖Pytorch和MMCV,因此安装之前需要先安装这两个库。MMCV有两mmcv-full和mmcv两个版本,两者差别在于是否包含CUDA操作,如果不需要使用CUDA可以安装mmcv,不过官方还是推荐安装完整版的mmcv-full。还有MMDetection3D,后续使用到再做研究。
二、安装
参考:https://blog.csdn.net/ArthurHai521/article/details/138356084
1、在线安装

pip install mmcv
pip install mmdet

2、离线安装

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -v -e .

去官网指定下载地址https://download.openmmlab.com/mmcv/dist/cu118/torch2.1/index.html下载对应版本mmcv:
mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl
安装:pip install mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl
验证是否安装成功

// An highlighted block
import os

from mmdet.apis import init_detector, inference_detector


def 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.pth
    checkpoint_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) ##有的版本可能报错没有show_result,就使用https://blog.csdn.net/csy1021/article/details/132080887方法


if __name__ == '__main__':
    demo_mmdet()

三、使用
1、添加自定义模型
https://blog.csdn.net/qq_41627642/article/details/124754147

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值