安装mmvc、mmdet并测试

发布于:2022-08-08 ⋅ 阅读:(642) ⋅ 点赞:(0)

目录

基本信息

服务器信息

版本选择

CUDA、Pytorch对应关系

mmvc、cuda、pytorch对应关系

MMDetection 和 MMCV 版本兼容性

安装

安装mmcv

安装 MMDetection


基本信息

服务器信息

(不知道为什么本地就是按不上)

镜像

PyTorch  1.8.1

Python  3.8

Cuda  11.1

GPU

RTX 3060 * 1

显存:12GB

CPU

7核 Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz

内存:20GB

版本选择

CUDA、Pytorch对应关系

(个人拙见,这里的CUDA其实是CUDA Toolkit)
(CUDA和CUDA Toolkit也是有个对应关系的、)

Previous PyTorch Versions | PyTorch

mmvc、cuda、pytorch对应关系

https://github.com/open-mmlab/mmcv#install-with-pip

 Previous PyTorch Versions | PyTorch

 本人选择cuda11.1+pytorch1.8(采用服务器可以选择不用安装)

conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

MMDetection 和 MMCV 版本兼容性

mmdetection/get_started.md at master · open-mmlab/mmdetection · GitHub

**注意:**如果已经安装了 mmcv,首先需要使用 pip uninstall mmcv 卸载已安装的 mmcv,如果同时安装了 mmcv 和 mmcv-full,将会报 ModuleNotFoundError 错误。

安装

此时电脑应该已经具备

PyTorch  1.8.1

Python  3.8

Cuda  11.1

安装mmcv

 本人选择mmcv-full==1.4.0

pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html

安装 MMDetection

pip install mmcv-full

出现警告:
UserWarning: “ImageToTensor” pipeline is replaced by “DefaultFormatBundle” for batch inference. It is recommended to manually replace it in the test data pipeline in your config file. ‘data pipeline in your config file.’, UserWarning)
 

修改mmdetection/configs/_base_/datasets/coco_detection.py中的代码

官方文档:

1: Inference and train with existing models and standard datasets — MMDetection 2.25.1 documentation

# use ImageToTensor (deprecated)
pipelines = [
   dict(type='LoadImageFromFile'),
   dict(
       type='MultiScaleFlipAug',
       img_scale=(1333, 800),
       flip=False,
       transforms=[
           dict(type='Resize', keep_ratio=True),
           dict(type='RandomFlip'),
           dict(type='Normalize', mean=[0, 0, 0], std=[1, 1, 1]),
           dict(type='Pad', size_divisor=32),
           dict(type='ImageToTensor', keys=['img']),
           dict(type='Collect', keys=['img']),
       ])
   ]

# manually replace ImageToTensor to DefaultFormatBundle (recommended)
pipelines = [
   dict(type='LoadImageFromFile'),
   dict(
       type='MultiScaleFlipAug',
       img_scale=(1333, 800),
       flip=False,
       transforms=[
           dict(type='Resize', keep_ratio=True),
           dict(type='RandomFlip'),
           dict(type='Normalize', mean=[0, 0, 0], std=[1, 1, 1]),
           dict(type='Pad', size_divisor=32),
           dict(type='DefaultFormatBundle'),
           dict(type='Collect', keys=['img']),
       ])
   ]

验证展示:

需创建指定文档下载权重

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: http://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 = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a single image
img = 'demo/demo.jpg'
result = inference_detector(model, img)
# show the results
show_result_pyplot(model, img, result)

结果为: 

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到