mmdetection代码教学

该博客详细介绍了如何更改CUDA和PyTorch版本,并通过MMDetection库进行目标检测。首先,使用pip安装了特定版本的PyTorch、TorchVision和Torchaudio。接着,安装了mmcv-full和mmdetection。然后,从OpenMMLAB下载预训练的fast-rcnn模型,并进行了推理计算。最后,展示了如何在一张图片上进行目标检测并绘制结果。
摘要由CSDN通过智能技术生成

改变cuda和pytorch版本

!pip --default-timeout=1000 install torch1.10.0+cu113 torchvision0.11.1+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

查看torch版本

import torch
print(torch.version)
在这里插入图片描述

安装mmcv-full

!pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html
在这里插入图片描述

安装mmdetection

克隆并安装mmdetection

!git clone https://github.com/open-mmlab/mmdetection.git

切换到目录

%cd mmdetection/
在这里插入图片描述

源码安装

!pip install -e .

检查mmdet版本

import mmdet
print(mmdet.__version__)

在这里插入图片描述

下载训练好的fast-rcnn模型到checkpoints文件夹

下面展示一些 内联代码片

!mkdir checkpoints 
!wget https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth -O checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth

推理计算

from mmdet.apis import inference_detector,init_detector,show_result_pyplot
#根据colab状态设置device
device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
#device='cuda:0'
#选择模型对应的配置文件
config='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
#选择下载好的checkpoints
checkpoint='checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
#初始化模型
model=init_detector(config,checkpoint,device=device)
#使用模型进行单张图推理
img='demo/demo.jpg'
result=inference_detector(model,img)
#在原图上绘制结果
show_result_pyplot(model,img,result,score_thr=0.9)

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

加油吧小森

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

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

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

打赏作者

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

抵扣说明:

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

余额充值