深度学习之旋转目标检测复现:ARC-main 关于mvcc,mvcc-full ,mmdet,mmegine的爬坑记录

发布于:2024-06-21 ⋅ 阅读:(90) ⋅ 点赞:(0)

Get Started
1) prepare environment

# create environment
conda create -n arc python=3.7 -y
conda activate arc

# install pytorch and torchvision
pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 -f https://download.pytorch.org/whl/torch_stable.html

# clone this codebase, including submodule
git clone https://github.com/LeapLabTHU/ARC.git --recursive

# install submodule
cd BboxToolkit
pip install -v -e .
cd ..

# install mmcv
pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html

# install other requirements
pip install -r requirements/build.txt
pip install mmpycocotools
pip install einops

# install this codebase
pip install -v -e .

我是先导入ARC-main整个项目,后下载的BboxToolkit项目,解压后放进ARC-main,在splitn data的过程中,出现BboxToolkit包无法下载的问题,当时我忘记运行pip install -v -e .命令,cd到BboxToolkit后,即可成功下载BboxToolkit包,直接运行pip install BboxToolkit命令无法 成功下载,匹配不到合适的版本包。
2)Prepare data
Download the DOTA dataset from official website, change the diretory in ./BboxToolkit/tools/split_configs/dota1_0/ss_trainval.json and ./BboxToolkit/tools/split_configs/dota1_0/ss_test.json, and then run the following script
坑:DOTA数据集,官网上下载的train和test都分为part1,part2,貌似只是压缩包太大了。。解压之后放在一起就可以了,train的原始文件夹是1411张。(心累)

cd ./BboxToolkit/tools/
python img_split.py --base_json split_configs/dota1_0/ss_trainval.json
python img_split.py --base_json split_configs/dota1_0/ss_test.json

ss_trainval.json文件中,定义数据集的路径是最好使用绝对路径,不然会报错,不在BboxToolkit下属文件夹中(应该是没有指定绝对路径就会在tools下面寻找了)
这步应该是要把trainval数据,按照分块的方法,拆分成好多张:
路径定义好就可以,还有生成的新数据的路径,注意开始的时候要是空的,不然也会报错(若只)

ss_trainval.json
在这里插入图片描述
ss_test.json
在这里插入图片描述
把数据分好了之后就可以开始训练了
3)Download the pretrained backbone
Download the pretrained ARC-ResNet from TsinghuaCloud or [GoogleDrive(https://cloud.tsinghua.edu.cn/d/46177201209d4d2a827b/), then put it in ./pretrained/.
4)Change data path
In the file ./configs/obb/base/datasets/dota.py, change the data path following data_root to YOUR_DATA_PATH.
这里面用的trainval数据集就是split data之后的

dataset_type = 'DOTADataset'
data_root = '/home/amax/wzq/ARC-main/data/split_ss_dota1_0/'
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadOBBAnnotations', with_bbox=True,
         with_label=True, obb_as_mask=True),
    dict(type='LoadDOTASpecialInfo'),
    dict(type='Resize', img_scale=(1024, 1024), keep_ratio=True),
    dict(type='OBBRandomFlip', h_flip_ratio=0.5, v_flip_ratio=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='RandomOBBRotate', rotate_after_flip=True,
         angles=(0, 0), vert_rate=0.5, vert_cls=['roundabout', 'storage-tank']),
    dict(type='Pad', size_divisor=32),
    dict(type='DOTASpecialIgnore', ignore_size=2),
    dict(type='FliterEmpty'),
    dict(type='Mask2OBB', obb_type='obb'),
    dict(type='OBBDefaultFormatBundle'),
    dict(type='OBBCollect', keys=['img', 'gt_bboxes', 'gt_obboxes', 'gt_labels'])
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipRotateAug',
        img_scale=[(1024, 1024)],
        h_flip=False,
        v_flip=False,
        rotate=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='OBBRandomFlip'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='RandomOBBRotate', rotate_after_flip=True),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='OBBCollect', keys=['img']),
        ])
]

# does evaluation while training
# uncomments it  when you need evaluate every epoch
# data = dict(
    # samples_per_gpu=2,
    # workers_per_gpu=4,
    # train=dict(
        # type=dataset_type,
        # task='Task1',
        # ann_file=data_root + 'train/annfiles/',
        # img_prefix=data_root + 'train/images/',
        # pipeline=train_pipeline),
    # val=dict(
        # type=dataset_type,
        # task='Task1',
        # ann_file=data_root + 'val/annfiles/',
        # img_prefix=data_root + 'val/images/',
        # pipeline=test_pipeline),
    # test=dict(
        # type=dataset_type,
        # task='Task1',
        # ann_file=data_root + 'val/annfiles/',
        # img_prefix=data_root + 'val/images/',
        # pipeline=test_pipeline))
# evaluation = dict(metric='mAP')

# disable evluation, only need train and test
# uncomments it when use trainval as train
data = dict(
    samples_per_gpu=1,
    workers_per_gpu=3,
    train=dict(
        type=dataset_type,
        task='Task1',
        ann_file=data_root + 'trainval/annfiles/',
        img_prefix=data_root + 'trainval/images/',
        pipeline=train_pipeline),
    test=dict(
        type=dataset_type,
        task='Task1',
        ann_file=data_root + 'test/annfiles/',
        img_prefix=data_root + 'test/images/',
        pipeline=test_pipeline))
evaluation = None

Usage

Training

# train a Oriented R-CNN model with ARC-ResNet50 backbone
python tools/train.py configs/obb/arc/arc_orcnn_r50fpn1x_ss_dota10_RxFFF_n4.py;

# train a Oriented R-CNN model with ARC-ResNet101 backbone
python tools/train.py configs/obb/arc/arc_orcnn_r101fpn1x_ss_dota10_RxFFF_n4.py;

啊嗯,关于train有很多问题要说
一个就是之前一定要记得运行pip install -v -e .
版本的解决问题记录一下:
1.https://blog.csdn.net/qq_69469062/article/details/128708152
关于mmdet版本升级问题,我是原来的mmdet版本是3.3.0,少了什么函数不记得了,总之就是卸载,然后重装链接推荐版本
2.关于mmdetv3.x版本更新后的设置
3.mmcv官网,选择对应的torch、os、cuda、python版本生成下载命令
4.言简意赅 记得setup
5.mmcv变化

Error Debug
【mmcv报错】ModuleNotFoundError: No module named ‘mmcv.runner
就是版本问题,我应该是运行了基础的安装命令版本(就是安装mmcv-full,然后在最后的setup中更新了mmcv的版本,应该是2.0.0

train.py中导入包函数错误:

import argparse
import copy
import os
import os.path as osp
import time

import mmcv
import torch
from mmengine import Config, DictAction  #
from mmengine.dist.utils import init_dist  #这两行开始都是从mmcv中直接导入,检索了一下,第一行的mmcv改成mmegine,这行的改成mmegine.dist.utils 

from mmdet import __version__
from mmdet.apis import set_random_seed, train_detector
from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.utils import collect_env, get_root_logger

最有用的!
https://blog.51cto.com/u_15906550/5921374
重新安装,reset!

加个这个
华为开发者联盟的一个复现

github关于MaskRCNN的一个坑

记录一下目前的包版本,目前正常train,有问题来记录
在这里插入图片描述
在这里插入图片描述

YOLOX OBB --YOLOX 旋转框检测 知乎一篇帖子
知乎

BboxToolkit工具包使用