MMDetection新手安装使用教程(无限踩坑)

2023-11-12

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

MMDetection是商汤和港中文大学针对目标检测任务推出的一个开源项目,它基于Pytorch实现了大量的目标检测算法,例如fast_rcnn,frater_rcnn,detr等算法。


提示:以下是本篇文章正文内容,下面案例可供参考

一、MMDetection安装过程

1.torch+torchvision的安装

首先我们要安装mmdetection利用GPU推理训练的CUDA以及Pytorch框架。以我自身的RTX3060 12G为例,我安装的是CUDA11.3+torch1.11.0+torchvision0.12.0.

CUDA11.3的安装请查看其他教程链接。链接: link

这里推荐创建一个新的虚拟环境进行安装,打开anaconda prompt

// 创建虚拟环境
conda create -n 环境名 python=X.X

以python3.9为例(以自己的python版本为准)

conda create -n pythorch2 python=3.9

激活环境

activate pythorch2 

在这里插入图片描述

之后下载torch1.11.0和torchvision0.12.0文件,文件下载链接如下:
链接: link

注意自己的python版本以及win平台
在这里插入图片描述
往下滑下载找到对应的torchvision版本,torch1.11对应torchvision0.12.0版本

在这里插入图片描述
打开在下载好的两个文件的文件夹中,复制文件的地址
在这里插入图片描述在这里插入图片描述回到我们的虚拟环境中进行安装torch

在这里插入图片描述同样的方法安装torchvision

在这里插入图片描述安装完成后进行pip list查看

在这里插入图片描述
测试torch安装是否成功,显示true表明torch安装成功

在这里插入图片描述

2.mmdetection的安装

官网安装简介链接如下:
https://mmdetection.readthedocs.io/zh_CN/latest/get_started.html

显卡的注意事项:对于30系列的显卡建议安装CUDA11.X的版本
在这里插入图片描述
官网给出了基本的安装步骤,如下图:

在这里插入图片描述

在步骤1中,建议采用方案a进行安装,因为在之后使用的过程中,如果采用方案b作为第三方库进行安装的话,在后续的使用过程中可能会出现部分项目无法编辑的问题。

当然,官网文档中也给出了使用pip 进行安装的教程,这两种安装方法都可以,还是在我们的虚拟环境中进行pip install 安装。

// 安装mmengine
pip install mmengine;
// 安装 MMCV(以cuda113+torch1.11为例)
pip install "mmcv>=2.0.0" -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11.0/index.html;
// 安装mmdet
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -v -e .
# "-v" 指详细说明,或更多的输出
# "-e" 表示在可编辑模式下安装项目,因此对代码所做的任何本地修改都会生效,从而无需重新安装。;

安装完成后在pip list查看会有如下三个库

在这里插入图片描述之后在运行项目的时候如果出现缺少一些基本库的现象,采用pip install进行下载安装即可。例如安装CV2

pip install opencv-python

二、MMDetection的使用步骤

1.下载项目文件

我下载的是mmdetection3.0.0项目文件,如下图:
在Tags中选择v3.0.0版本项目,链接如下:
https://github.com/open-mmlab/mmdetection/tree/v3.0.0
在这里插入图片描述之后Download Zip下载到本地即可

在这里插入图片描述在这里插入图片描述

2.使用教程

2.1验证安装是否成功

用pycharm打开项目文件(注意将解释器配置成自己创建的虚拟环境),在image_demo.py中进行验证

在这里插入图片描述官网给出了验证过程,当然我们也可以在pycharm中进行验证。首先在官网下载需要的模型文件和权重文件

在这里插入图片描述

mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .

在cmd运行上面指令,一般会下载到用户文件夹(C:\Users\Ogl),将下载好的两个文件放到mmdetection3.0.0项目文件夹中
在这里插入图片描述
之后在pycharm的image_demo.py运行前传入这两个文件的地址以及demo图片的地址作为参数传入。
复制三个文件的绝对路径,示例如下:(注意是双斜杠\\)

E:\\mmdetection-3.0.0\\mmdetection-3.0.0\\demo\\demo.jpg(图片地址)
E:\\mmdetection-3.0.0\\mmdetection-3.0.0\\rtmdet_tiny_8xb32-300e_coco.py(模型文件地址)
 --weights 
E:\\mmdetection-3.0.0\\mmdetection-3.0.0\\rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth(权重文件地址)
--show

将文件地址复制到参数项(parameters)中

在这里插入图片描述

之后运行image_demo.py即可

在这里插入图片描述

能显示demo.jpg图片的物体被成功识别及预测后,自此我们的mmdetection安装运行成功

2.2选择模型对COCO数据集进行推理训练

本文以faster_rcnn_r50_fpn_1x_coco.py为例,我们在configs中找到模型文件
在这里插入图片描述之后在./tools/train.py中传入该文件地址,在work_dirs中会生成一个faster_rcnn_r50_fpn_1x_coco.py文件,该文件包含之前py文件的各种配置文件,方便我们后续对模型进行修改

在这里插入图片描述之后下载coco数据集,我这里用的是coco2017数据集

在这里插入图片描述

如果要使用自己的数据集需按照官网的数据集格式准备数据集,mmdetection官网数据集准备链接如下:
链接: link
在这里插入图片描述在detection3.0.0项目新建data文件夹,将COCO数据集放到data文件夹中,就可以运行tools/train.py 进行训练了
在这里插入图片描述
打开terminal窗口,在窗口中输入以下指令

(pytorch2) PS E:\mmdetection-3.0.0\mmdetection-3.0.0> python .\tools\train.py E:\\mmdetection-3.0.0\\mmdetection-3.0.0\\work_dirs\\faster-rcnn_r50_fpn_1x_coco\\faster-rcnn_r50_fpn_1x_coco.py

成功运行后会在终端提示如下信息,并开始训练。

 (pytorch2) PS E:\mmdetection-3.0.0\mmdetection-3.0.0> python .\tools\train.py E:\\mmdetection-3.0.0\\mmdetection-3.0.0\\work_dirs\\faster-rcnn_r50_fpn_1x_coco\\faster-rcnn_r50_fpn_1x_coco.py
 
06/15 14:05:09 - mmengine - INFO - 
------------------------------------------------------------
System environment:
    sys.platform: win32
    Python: 3.9.16 (main, Mar  8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)]
    CUDA available: True
    numpy_random_seed: 201700358
    GPU 0: NVIDIA GeForce RTX 3060
    CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3
    NVCC: Cuda compilation tools, release 11.3, V11.3.58
    MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.34.31942GCC: n/a
    PyTorch: 1.11.0+cu113
    PyTorch compiling details: PyTorch built with:
  - C++ Version: 199711
  - MSVC 192829337
  - Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.5.2 (Git Hash a9302535553c73243c632ad3c4c80beec3d19a1e)
  - OpenMP 2019
  - LAPACK is enabled (usually provided by MKL)
  - CPU capability usage: AVX2
  - CUDA Runtime 11.3
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_37,code=compute_37

  - CuDNN 8.2
  - Magma 2.5.4
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /b
igobj -DUSE_PTHREADPOOL -openmp:experimental -IC:/actions-runner/_work/pytorch/pytorch/builder/windows/mkl/include -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILE
R_USE_KINETO, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.11.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF,

    TorchVision: 0.12.0+cu113
    OpenCV: 4.7.0
    MMEngine: 0.7.4

Runtime environment:
    cudnn_benchmark: False
    mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0}
    dist_cfg: {'backend': 'nccl'}
    seed: 201700358
    Distributed launcher: none
    Distributed training: False
    GPU number: 1
------------------------------------------------------------

06/15 14:05:09 - mmengine - INFO - Config:
model = dict(
    type='FasterRCNN',
    data_preprocessor=dict(
        type='DetDataPreprocessor',
        mean=[123.675, 116.28, 103.53],
        std=[58.395, 57.12, 57.375],
        bgr_to_rgb=True,
        pad_size_divisor=32),
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=True),
        norm_eval=True,
        style='pytorch',
        init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
    neck=dict(
        type='FPN',
        in_channels=[256, 512, 1024, 2048],
        out_channels=256,
        num_outs=5),
    rpn_head=dict(
        type='RPNHead',
        in_channels=256,
        feat_channels=256,
        anchor_generator=dict(
            type='AnchorGenerator',
            scales=[8],
            ratios=[0.5, 1.0, 2.0],
            strides=[4, 8, 16, 32, 64]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[0.0, 0.0, 0.0, 0.0],
            target_stds=[1.0, 1.0, 1.0, 1.0]),
        loss_cls=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
        loss_bbox=dict(type='L1Loss', loss_weight=1.0)),
    roi_head=dict(
        type='StandardRoIHead',
        bbox_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        bbox_head=dict(
            type='Shared2FCBBoxHead',
            in_channels=256,
            fc_out_channels=1024,
            roi_feat_size=7,
            num_classes=2,
            bbox_coder=dict(
                type='DeltaXYWHBBoxCoder',
                target_means=[0.0, 0.0, 0.0, 0.0],
                target_stds=[0.1, 0.1, 0.2, 0.2]),
            reg_class_agnostic=False,
            loss_cls=dict(
                type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
            loss_bbox=dict(type='L1Loss', loss_weight=1.0))),
    train_cfg=dict(
        rpn=dict(
            assigner=dict(
                type='MaxIoUAssigner',
                pos_iou_thr=0.7,
                neg_iou_thr=0.3,
                min_pos_iou=0.3,
                match_low_quality=True,
                ignore_iof_thr=-1),
            sampler=dict(
                type='RandomSampler',
                num=256,
                pos_fraction=0.5,
                neg_pos_ub=-1,
                add_gt_as_proposals=False),
            allowed_border=-1,
            pos_weight=-1,
            debug=False),
        rpn_proposal=dict(
            nms_pre=2000,
            max_per_img=1000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=dict(
            assigner=dict(
                type='MaxIoUAssigner',
                pos_iou_thr=0.5,
                neg_iou_thr=0.5,
                min_pos_iou=0.5,
                match_low_quality=False,
                ignore_iof_thr=-1),
            sampler=dict(
                type='RandomSampler',
                num=512,
                pos_fraction=0.25,
                neg_pos_ub=-1,
                add_gt_as_proposals=True),
            pos_weight=-1,
            debug=False)),
    test_cfg=dict(
        rpn=dict(
            nms_pre=1000,
            max_per_img=1000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=dict(
            score_thr=0.05,
            nms=dict(type='nms', iou_threshold=0.5),
            max_per_img=100)))
dataset_type = 'CocoDataset'
data_root = 'data/coco/'
backend_args = None
train_pipeline = [
    dict(type='LoadImageFromFile', backend_args=None),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(type='Resize', scale=(1333, 800), keep_ratio=True),
    dict(type='RandomFlip', prob=0.5),
    dict(type='PackDetInputs')
]
test_pipeline = [
    dict(type='LoadImageFromFile', backend_args=None),
    dict(type='Resize', scale=(1333, 800), keep_ratio=True),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(
        type='PackDetInputs',
        meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
                   'scale_factor'))
]
train_dataloader = dict(
    batch_size=2,
    num_workers=2,
    persistent_workers=True,
    sampler=dict(type='DefaultSampler', shuffle=True),
    batch_sampler=dict(type='AspectRatioBatchSampler'),
    dataset=dict(
        type='CocoDataset',
        data_root='data/labelme-data/coco-formatcoco/',
        ann_file='annotations/instances_train2017.json',
        data_prefix=dict(img='images/train2017/'),
        filter_cfg=dict(filter_empty_gt=True, min_size=32),
        pipeline=[
            dict(type='LoadImageFromFile', backend_args=None),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(type='Resize', scale=(1333, 800), keep_ratio=True),
            dict(type='RandomFlip', prob=0.5),
            dict(type='PackDetInputs')
        ],
        backend_args=None))
val_dataloader = dict(
    batch_size=1,
    num_workers=2,
    persistent_workers=True,
    drop_last=False,
    sampler=dict(type='DefaultSampler', shuffle=False),
    dataset=dict(
        type='CocoDataset',
        data_root='data/labelme-data/coco-formatcoco/',
        ann_file='annotations/instances_val2017.json',
        data_prefix=dict(img='images/val2017/'),
        test_mode=True,
        pipeline=[
            dict(type='LoadImageFromFile', backend_args=None),
            dict(type='Resize', scale=(1333, 800), keep_ratio=True),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(
                type='PackDetInputs',
                meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
                           'scale_factor'))
        ],
        backend_args=None))
test_dataloader = dict(
    batch_size=1,
    num_workers=2,
    persistent_workers=True,
    drop_last=False,
    sampler=dict(type='DefaultSampler', shuffle=False),
    dataset=dict(
        type='CocoDataset',
        data_root='data/labelme-data/coco-formatcoco/',
        ann_file='annotations/instances_val2017.json',
        data_prefix=dict(img='images/val2017/'),
        test_mode=True,
        pipeline=[
            dict(type='LoadImageFromFile', backend_args=None),
            dict(type='Resize', scale=(1333, 800), keep_ratio=True),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(
                type='PackDetInputs',
                meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
                           'scale_factor'))
        ],
        backend_args=None))
val_evaluator = dict(
    type='CocoMetric',
    ann_file=
    'data/labelme-data/coco-formatcoco/annotations/instances_val2017.json',
    metric='bbox',
    format_only=False,
    backend_args=None)
test_evaluator = dict(
    type='CocoMetric',
    ann_file=
    'data/labelme-data/coco-formatcoco/annotations/instances_val2017.json',
    metric='bbox',
    format_only=False,
    backend_args=None)
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=50, val_interval=1)
val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')
param_scheduler = [
    dict(
        type='LinearLR', start_factor=0.001, by_epoch=False, begin=0, end=500),
    dict(
        type='MultiStepLR',
        begin=0,
        end=50,
        by_epoch=True,
        milestones=[8, 11],
        gamma=0.1)
]
optim_wrapper = dict(
    type='OptimWrapper',
    optimizer=dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001))
auto_scale_lr = dict(enable=False, base_batch_size=16)
default_scope = 'mmdet'
default_hooks = dict(
    timer=dict(type='IterTimerHook'),
    logger=dict(type='LoggerHook', interval=50),
    param_scheduler=dict(type='ParamSchedulerHook'),
    checkpoint=dict(type='CheckpointHook', interval=1),
    sampler_seed=dict(type='DistSamplerSeedHook'),
    visualization=dict(
        type='DetVisualizationHook', draw=True, test_out_dir='out'))
env_cfg = dict(
    cudnn_benchmark=False,
    mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
    dist_cfg=dict(backend='nccl'))
vis_backends = [dict(type='LocalVisBackend')]
visualizer = dict(
    type='DetLocalVisualizer',
    vis_backends=[dict(type='LocalVisBackend')],
    name='visualizer')
log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True)
log_level = 'INFO'
load_from = '.\\work_dirs\\faster-rcnn_r50_fpn_1x_coco\\epoch_50.pth'
resume = False
launcher = 'none'
work_dir = './work_dirs\\faster-rcnn_r50_fpn_1x_coco'

06/15 14:05:10 - mmengine - INFO - Distributed training is not used, all SyncBatchNorm (SyncBN) layers in the model will be automatically reverted to BatchNormXd layers if they are used.
06/15 14:05:10 - mmengine - INFO - Hooks will be executed in the following order:
before_run:
(VERY_HIGH   ) RuntimeInfoHook
(BELOW_NORMAL) LoggerHook
 --------------------
before_train:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
(VERY_LOW    ) CheckpointHook
 --------------------
before_train_epoch:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
(NORMAL      ) DistSamplerSeedHook
 --------------------
before_train_iter:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
 --------------------
after_train_iter:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
(BELOW_NORMAL) LoggerHook
(LOW         ) ParamSchedulerHook
(VERY_LOW    ) CheckpointHook
 --------------------
after_train_epoch:
(NORMAL      ) IterTimerHook
(LOW         ) ParamSchedulerHook
(VERY_LOW    ) CheckpointHook
 --------------------
before_val_epoch:
(NORMAL      ) IterTimerHook
 --------------------
before_val_iter:
(NORMAL      ) IterTimerHook
 --------------------
after_val_iter:
(NORMAL      ) IterTimerHook
(NORMAL      ) DetVisualizationHook
(BELOW_NORMAL) LoggerHook
 --------------------
after_val_epoch:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
(BELOW_NORMAL) LoggerHook
(LOW         ) ParamSchedulerHook
(VERY_LOW    ) CheckpointHook
 --------------------
after_train:
(VERY_LOW    ) CheckpointHook
 --------------------
before_test_epoch:
(NORMAL      ) IterTimerHook
 --------------------
before_test_iter:
(NORMAL      ) IterTimerHook
 --------------------
after_test_iter:
(NORMAL      ) IterTimerHook
(NORMAL      ) DetVisualizationHook
(BELOW_NORMAL) LoggerHook
 --------------------
after_test_epoch:
(VERY_HIGH   ) RuntimeInfoHook
(NORMAL      ) IterTimerHook
(BELOW_NORMAL) LoggerHook
 --------------------
after_run:
(BELOW_NORMAL) LoggerHook
 --------------------
loading annotations into memory...
Done (t=0.01s)
creating index...
index created!
loading annotations into memory...
Done (t=0.02s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
06/15 14:05:12 - mmengine - INFO - load model from: torchvision://resnet50
06/15 14:05:12 - mmengine - INFO - Loads checkpoint by torchvision backend from path: torchvision://resnet50
06/15 14:05:12 - mmengine - WARNING - The model and loaded state dict do not match exactly

unexpected key in source state_dict: fc.weight, fc.bias

Loads checkpoint by local backend from path: .\work_dirs\faster-rcnn_r50_fpn_1x_coco\epoch_50.pth
06/15 14:05:12 - mmengine - INFO - Load checkpoint from .\work_dirs\faster-rcnn_r50_fpn_1x_coco\epoch_50.pth
06/15 14:05:12 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io
06/15 14:05:12 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future.
06/15 14:05:12 - mmengine - INFO - Checkpoints will be saved to E:\mmdetection-3.0.0\mmdetection-3.0.0\work_dirs\faster-rcnn_r50_fpn_1x_coco.
06/15 14:05:20 - mmengine - INFO - Exp name: faster-rcnn_r50_fpn_1x_coco_20230615_140507
06/15 14:05:20 - mmengine - INFO - Epoch(train)  [1][9/9]  lr: 3.4032e-04  eta: 0:06:53  time: 0.9368  data_time: 0.2160  memory: 4485  loss: 0.8013  loss_rpn_cls: 0.0591  loss_rpn_bbox: 0.0445  loss_cls: 0.2363  acc: 92.2852  loss_bbox: 0.4615
06/15 14:05:20 - mmengine - INFO - Saving checkpoint at 1 epochs
06/15 14:05:23 - mmengine - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.02s).
Accumulating evaluation results...
DONE (t=0.02s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.153
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.435
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.073
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.318
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
06/15 14:05:23 - mmengine - INFO - bbox_mAP_copypaste: 0.153 0.435 0.073 0.318 -1.000 -1.000
06/15 14:05:23 - mmengine - INFO - Epoch(val) [1][2/2]    coco/bbox_mAP: 0.1530  coco/bbox_mAP_50: 0.4350  coco/bbox_mAP_75: 0.0730  coco/bbox_mAP_s: 0.3180  coco/bbox_mAP_m: -1.0000  coco/bbox_mAP_l: -1.0000  data_time: 0.6178  time: 0.8028
06/15 14:05:27 - mmengine - INFO - Exp name: faster-rcnn_r50_fpn_1x_coco_20230615_140507
06/15 14:05:27 - mmengine - INFO - Epoch(train)  [2][9/9]  lr: 7.0068e-04  eta: 0:05:02  time: 0.6997  data_time: 0.1117  memory: 5159  loss: 0.8078  loss_rpn_cls: 0.0608  loss_rpn_bbox: 0.0441  loss_cls: 0.2357  acc: 92.7734  loss_bbox: 0.4672
06/15 14:05:27 - mmengine - INFO - Saving checkpoint at 2 epochs
06/15 14:05:29 - mmengine - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.02s).
Accumulating evaluation results...
DONE (t=0.01s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.140
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.401
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.037
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.314
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.312
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.312
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.312
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.312
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
06/15 14:05:29 - mmengine - INFO - bbox_mAP_copypaste: 0.140 0.401 0.037 0.314 -1.000 -1.000
06/15 14:05:29 - mmengine - INFO - Epoch(val) [2][2/2]    coco/bbox_mAP: 0.1400  coco/bbox_mAP_50: 0.4010  coco/bbox_mAP_75: 0.0370  coco/bbox_mAP_s: 0.3140  coco/bbox_mAP_m: -1.0000  coco/bbox_mAP_l: -1.0000  data_time: 0.0082  time: 0.0971
06/15 14:05:33 - mmengine - INFO - Exp name: faster-rcnn_r50_fpn_1x_coco_20230615_140507
06/15 14:05:33 - mmengine - INFO - Epoch(train)  [3][9/9]  lr: 1.0610e-03  eta: 0:04:20  time: 0.6156  data_time: 0.0756  memory: 5388  loss: 0.8012  loss_rpn_cls: 0.0611  loss_rpn_bbox: 0.0444  loss_cls: 0.2323  acc: 94.4336  loss_bbox: 0.4634
06/15 14:05:33 - mmengine - INFO - Saving checkpoint at 3 epochs
06/15 14:05:34 - mmengine - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.00s).
Accumulating evaluation results...
DONE (t=0.02s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.148
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.445
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.052
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.319
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.317
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
06/15 14:05:34 - mmengine - INFO - bbox_mAP_copypaste: 0.148 0.445 0.052 0.319 -1.000 -1.000
06/15 14:05:34 - mmengine - INFO - Epoch(val) [3][2/2]    coco/bbox_mAP: 0.1480  coco/bbox_mAP_50: 0.4450  coco/bbox_mAP_75: 0.0520  coco/bbox_mAP_s: 0.3190  coco/bbox_mAP_m: -1.0000  coco/bbox_mAP_l: -1.0000  data_time: 0.0111  time: 0.0956
06/15 14:05:38 - mmengine - INFO - Exp name: faster-rcnn_r50_fpn_1x_coco_20230615_140507
06/15 14:05:38 - mmengine - INFO - Epoch(train)  [4][9/9]  lr: 1.4214e-03  eta: 0:03:58  time: 0.5761  data_time: 0.0581  memory: 5388  loss: 0.8093  loss_rpn_cls: 0.0605  loss_rpn_bbox: 0.0454  loss_cls: 0.2331  acc: 95.0195  loss_bbox: 0.4703
06/15 14:05:38 - mmengine - INFO - Saving checkpoint at 4 epochs
06/15 14:05:40 - mmengine - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.02s).
Accumulating evaluation results...
DONE (t=0.00s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.153
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.421
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.153
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.268
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.267
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.267
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.267
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.267
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
06/15 14:05:40 - mmengine - INFO - bbox_mAP_copypaste: 0.153 0.421 0.153 0.268 -1.000 -1.000
06/15 14:05:40 - mmengine - INFO - Epoch(val) [4][2/2]    coco/bbox_mAP: 0.1530  coco/bbox_mAP_50: 0.4210  coco/bbox_mAP_75: 0.1530  coco/bbox_mAP_s: 0.2680  coco/bbox_mAP_m: -1.0000  coco/bbox_mAP_l: -1.0000  data_time: 0.0104  time: 0.0912
06/15 14:05:44 - mmengine - INFO - Exp name: faster-rcnn_r50_fpn_1x_coco_20230615_140507
06/15 14:05:44 - mmengine - INFO - Epoch(train)  [5][9/9]  lr: 1.7818e-03  eta: 0:03:42  time: 0.5506  data_time: 0.0474  memory: 5159  loss: 0.8008  loss_rpn_cls: 0.0594  loss_rpn_bbox: 0.0455  loss_cls: 0.2366  acc: 92.1875  loss_bbox: 0.4593
06/15 14:05:44 - mmengine - INFO - Saving checkpoint at 5 epochs
06/15 14:05:47 - mmengine - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.04s).
Accumulating evaluation results...
DONE (t=0.01s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.170
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=1000 ] = 0.525
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=1000 ] = 0.087
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.290
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.288
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 ] = 0.288
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=1000 ] = 0.288
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.288
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = -1.000
06/15 14:05:47 - mmengine - INFO - bbox_mAP_copypaste: 0.170 0.525 0.087 0.290 -1.000 -1.000
06/15 14:05:47 - mmengine - INFO - Epoch(val) [5][2/2]    coco/bbox_mAP: 0.1700  coco/bbox_mAP_50: 0.5250  coco/bbox_mAP_75: 0.0870  coco/bbox_mAP_s: 0.2900  coco/bbox_mAP_m: -1.0000  coco/bbox_mAP_l: -1.0000  data_time: 0.0156  time: 0.1525
;

当然我们也可以用到text.py 来对模型进行测试, 需要出入模型文件地址和训练的权重文件地址,训练的权重文件一般保存在work_dirs 文件夹下,我这里是E:\mmdetection-3.0.0\mmdetection-3.0.0\work_dirs\faster-rcnn_r50_fpn_1x_coco文件夹下
找到最后的epoch训练得到的权重参数,如下:
在这里插入图片描述
我这里总共训练了50次,就选择epoch_50.pth作为权重文件进行测试,测试指令如下:

(pytorch2) PS E:\mmdetection-3.0.0\mmdetection-3.0.0> python .\tools\test.py .\work_dirs/faster-rcnn_r50_fpn_1x_coco/faster-rcnn_r50_fpn_1x_coco.py .\work_dirs\faster-rcnn_r50_fpn_1x_coco\epoch_50.pth --show-dir out

在该文件夹下会生成一个out文件夹,就是对测试图片的识别和预测。
在这里插入图片描述在这里插入图片描述


总结

以上就是今天要讲的内容,本文主要介绍了mmdetection的安装以及采用标准COCO数据集的使用过程,后续如果读者需要,也会介绍自己数据集的制作以及利用mmdetection中的模型进行训练和测试。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MMDetection新手安装使用教程(无限踩坑) 的相关文章

随机推荐

  • 刷题之轮转数组

    给你一个数组 将数组中的元素向右轮转 k 个位置 其中 k 是非负数 示例 1 输入 nums 1 2 3 4 5 6 7 k 3 输出 5 6 7 1 2 3 4 解释 向右轮转 1 步 7 1 2 3 4 5 6 向右轮转 2 步 6
  • 如何实现零宕机的配置热加载

    对于高可用的服务 为了保证服务可用性 更新配置时必然不能直接停止服务 可以使用配置热加载来避免服务暂停 不需要重启服务 配置的热加载可以分为两个场景 手动更新与自动更新 手动更新 对于一些临时调试 服务数量不多的情况下 可以进行手动更新配置
  • 外包干了2个月,技术退步明显.......

    先说一下自己的情况 大专生 18年通过校招进入武汉某软件公司 干了接近4年的功能测试 今年年初 感觉自己不能够在这样下去了 长时间呆在一个舒适的环境会让一个人堕落 而我已经在一个企业干了四年的功能测试 已经让我变得不思进取 谈了2年的女朋友
  • 【Tensorflow2.0】11、经典图像CNN模型实现代码

    文章目录 1 Lenet5 2 AlexNet 3 VGG 4 Inception系列 v1到v4 4 1 Inceptionv1 GoogLeNet 4 2 inceptionv2 4 3 inceptionv3 4 4 Inceptio
  • Android快速开发框架-ZBLibrary 源码分享

    坐标标准库ZBLibrary 是一个MVP架构的Android快速开发框架 提供一套开发标准 UI Data Listener 以及模板和工具类并规范代码 封装层级少 简单高效兼容性好 一句代码就可实现全局滑动返回 可重写 集成方便快捷的照
  • matlab练习程序(c/c++调用matlab

    这里的环境是windows7 vs2010 matlabR2010b 上一篇是通过engine来调用matlab中的语句 本篇是通过调用m文件编译成的h lib dll文件而实现的 首先写一个函数mysvd m function s v d
  • docker国内镜像加速

    1 阿里云容器 生成自己的加速地址 登陆地址 https cr console aliyun com 选择自己的系统 2 修改配置文件 针对Docker客户端版本大于 1 10 0 的用户 您可以通过修改daemon配置文件 etc doc
  • Linux防火墙

    安全防御 常见的攻击手段 拒绝服务 已知漏洞 口令破解 欺骗用户 常见的安全防御设备 基础类防火墙 IDS类 入侵检测系统 提供报告 事后分析 IPS类 入侵防御系统 针对数据包分析 根据模式匹配 阻断非法访问 主动安全类 什么是防火墙 工
  • 这篇文章带你读懂IP地址

    这篇文章带你读懂IP地址 一 IP地址介绍 二 IP地址分类及表示 三 IP地址的主要特点 四 特殊IP地址及私有IP地址 一 IP地址介绍 IP地址 全世界唯一的32位 4字节标识符 标识路由器主机的接口 IP地址 lt 网络号 gt l
  • 【Git CMD】Git上传本地代码到远程仓库(6步到位)

    步骤 1 创建指定名称的分支并切换至该分支 2 添加文件到暂存区 3 查看本地仓库和暂存区的状态 4 提交文件到本地仓库 5 查看本地仓库提交的历史 6 将本地当前分支推送到与本地当前分支同名的远程分支 1 创建指定名称的分支并切换至该分支
  • 学习PGL课程:图卷积网络GCN、图注意力网络GAT

    一 GCN 什么是图卷积 不同的地方在于 图像像素点周围的像素个数通常是固定的 而图结构上某个节点周围的节点数是不固定的 图卷积网络计算公式 1 邻接矩阵解释 2 度矩阵 表示节点与之相连节点的个数 包括自环 3 H l 表示第l次迭代的节
  • 具体项目下解决Echarts多端同步开发和维护的问题

    具体问题场景 PC端和移动端需要同时上线图表功能 没有多余工时 之后的版本迭代 功能 样式 配置等 默认双端同步 开发人员只希望维护一套代码 Echarts在移动端有部分功能不兼容不支持 Echarts在移动端的坑 移动端页面使用echar
  • Raspberry Pi使用TinyML运动识别

    我们将使用机器学习来构建在微型微控制器RP2040上运行的手势识别系统 探索Raspberry Pi Pico及其SDK Raspberry Pi Pico是具有灵活数字接口的低成本 高性能微控制器板 主要功能包括 Raspberry Pi
  • C11 : 函数模板 std::function

    目录 std function 定义 实现原理 应用 注意事项 std function 定义 类模板 std function 是一种通用的 多态的函数封装 std function 的实例可以对任何可以调用的目标实体进行存储 复制和调用
  • react hooks无法获取到最新值问题

    无法获取最新值的写法 在state中定义初始值 import React useState useEffect from react const type setType useState 0 通过setType方法修改type div s
  • 字符替换 英文字符串单词个数统计 python123题解

    字符替换 描述 假设有段英文 其中有单独字母 P 被误写为 p 请编写程序进行纠正 输入格式 用户输入一个字符串 不要使用提示词语 输出格式 程序输出字符串 其中原本包含的英文字母 p 全部被替换为 P 输入输出示例 输入 输出 示例 py
  • MYSQL常用字段属性

    MYSQL常用字段属性 1 DECIMAL M D 2 INT 3 VARCHAR 4 CHAR 5 TEXT 6 DATA 1 DECIMAL M D M是总位数 1 65 包含精度 D是小数位 0 30 当表示定点小数时使用类型 比fl
  • PostgreSQL配置优化

    转载请注明原文出处 http blog csdn net roddick621 PostgreSQL配置优化 PostgreSQL配置优化 硬件和系统配置 测试工具 配置文件 主要选项 测试数据 总结 硬件和系统配置 操作系统 Ubuntu
  • GVIM编辑器实现自定义配对关键字之间的跳转

    由于刚开始接触GVIM编辑器 在使用GVIM写Verilog代码的时候发现使用 命令可以实现配对括号之间的跳转 但其它的一些关键字之间却不能实现配对跳转 从而导致在代码量较大的时候常常会出现配对关键字多写或漏写的情况 很不方便 网上查阅了相
  • MMDetection新手安装使用教程(无限踩坑)

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 文章目录 前言 一 MMDetection安装过程 1 torch torchvision的安装 2 mmdetection的安装 二 MMDetection的使用步骤 1