mmdetection部署+训练,一步到位

1、安装

准备环境

  1. 创建一个 conda 虚拟环境并激活它。

    conda create -n openmmlab python=3.7 -y
    conda activate openmmlab
    
  2. 按照官方说明安装 PyTorch 和 torchvision,例如,

    conda install pytorch torchvision -c pytorch
    
    注意:请确保编译 CUDA 版本和运行时 CUDA 版本匹配。 您可以在 PyTorch 网站上查看预编译包支持的 CUDA 版本。 

2、安装 MMDetection

建议使用 MIM 安装 MMDetection, 自动处理 OpenMMLab 项目的依赖项,包括 mmcv 和其他 python 包。

pip install openmim
mim install mmdet

3、下载mmdetection代码

在github官网下载mmdetection代码。

下载压缩包后,解压好之后用pycharm打开mmdetection项目。

1.在demo目录下创建Images和outputs文件夹,并在outputs文件夹下创建result文件夹。再将demo文件夹下的demo.jpg图片放入Images文件夹中.

2.在根目录下创建checkpoints文件,在本文资源中下载预训练模型。

3.在demo文件夹下创建demo.py文件,将下述代码复制到demo.py文件中。

import os
from mmdet.apis import init_detector, inference_detector
from mmdet.registry import VISUALIZERS
import mmcv

# 使用前修改下面的路径
image_path = r'demo/Images'  #此处就写刚刚创建的Images路径
savePath = r'E:\WorkSpace\mmdetection-main\demo\outputs\result' #此处换成result文件夹在自己电脑下文件的绝对路径

config_file = 'E:/WorkSpace/mmdetection-main/work_dirs/faster-rcnn_r50_fpn_1x_coco.py' #此处换成自己盘下的绝对路径,如果需要其他的配置文件可以换
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# gpu 不行 会 Out of memory
device = 'cuda:0'

model = init_detector(config_file, checkpoint_file, device=device)

visualizer = VISUALIZERS.build(model.cfg.visualizer)
# the dataset_meta is loaded from the checkpoint and
# then pass to the model in init_detector
visualizer.dataset_meta = model.dataset_meta

for filename in os.listdir(image_path):
    imgPath = os.path.join(image_path, filename)

    print('process ', imgPath)
    img = mmcv.imread(imgPath)
    result = inference_detector(model, img)
    out_file = os.path.join(savePath, filename)

    ### old implementation invalid
    # show_result_pyplot(model, img, result, out_file, score_thr=0.3)
    ###

    # show the results
    visualizer.add_datasample('result',
                              img, data_sample=result,
                              draw_gt=False,
                              wait_time=0,
                              out_file=out_file,
                              pred_score_thr=0.3
                              )
    # vis
    # visualizer.show()
    # break

到此就部署完成,并训练好了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值