IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 【AI目标检测】MMROTATE踩坑记录 -> 正文阅读

[人工智能]【AI目标检测】MMROTATE踩坑记录

MMROTATE介绍

MMRotate 是一款基于 PyTorch 的旋转框检测的开源工具箱,是 OpenMMLab 项目的成员之一。
在这里插入图片描述

MMROTATE安装

mmrotate的安装同mmdet等类似
参考mmrotate安装

  1. 创建环境
conda create -n openmmlab python=3.7 -y
conda activate openmmlab
  1. 安装pytorch
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.1 -c pytorch
  1. pip install 必要的包

首先是mmcv-full

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

然后要安装mmdet

pip install mmdet

mmrotate建议从源码安装

git clone https://github.com/open-mmlab/mmrotate.git
cd mmrotate
pip install -r requirements/build.txt
pip install -v -e .  # or "python setup.py develop"

其中pip install -v -e .orpython setup.py develop将会安装为开发模式,所有对源码的修改都将生效。(pip install -v -e .最后的.表示当前路径,不要漏掉!)

训练测试

根据自己的要求写配置文件,修改为自己的数据集路径和类别以及类别数目

# the new config inherits the base configs to highlight the necessary modification
_base_ = '../r3det/r3det_r50_fpn_1x_dota_oc.py'

# 验证设置
evaluation = dict(interval=1, metric='mAP')
runner = dict(type='EpochBasedRunner', max_epochs=200)
checkpoint_config = dict(interval=100)

# 1. dataset settings
dataset_type = 'DOTADataset'
classes = ('comp', 'procl')
data = dict(
    samples_per_gpu=2,
    workers_per_gpu=2,
    train=dict(
        type=dataset_type,
        # explicitly add your class names to the field `classes`
        classes=classes,
        ann_file='/home/wd337/projects/mmrotate/data/dota/annotations/train',
        img_prefix='/home/wd337/projects/mmrotate/data/dota/images/train'),
    val=dict(
        type=dataset_type,
        # explicitly add your class names to the field `classes`
        classes=classes,
        ann_file='/home/wd337/projects/mmrotate/data/dota/annotations/val',
        img_prefix='/home/wd337/projects/mmrotate/data/dota/images/val'),
    test=dict(
        type=dataset_type,
        # explicitly add your class names to the field `classes`
        classes=classes,
        ann_file='/home/wd337/projects/mmrotate/data/dota/annotations/test',
        img_prefix='/home/wd337/projects/mmrotate/data/dota/images/test'))

# 2. model settings
model = dict(
    bbox_head=dict(
        # explicitly over-write all the `num_classes` field from default 15 to 5.
        num_classes=2))

训练(单卡):

python tools/train.py configs/my_config/my_config.py --work-dir=work_dirs/my_model

测试:

python ./tools/test.py \
  configs/my_config/my_config.py \
  work_dirs/my_model/my_model_pth.pth --show-dir work_dirs/vis

出现的错误

error 1

ValueError: could not convert string to float: 'imagesource:null'

原因:由于在查看DOTA数据集的时候发现有标注文件都有imagesource和gsd信息,在转换时加上了这两行信息,去掉即可

error 2

File "/home/wd337/projects/mmrotate/mmrotate/datasets/dota.py", line 199, in evaluate
    mean_ap, _ = eval_map(
TypeError: eval_map() got an unexpected keyword argument 'version'

原因:
在mean_ap传参时的version=self.version在构建eval_map时并未使用,将其注释掉

mean_ap, _ = eval_map(
                results,
                annotations,
                scale_ranges=scale_ranges,
                iou_thr=iou_thr,
                dataset=self.CLASSES,
                # version=self.version,
                logger=logger,
                nproc=nproc)
                
def eval_map(det_results,
             annotations,
             scale_ranges=None,
             iou_thr=0.5,
             dataset=None,
             logger=None,
             nproc=4):

后续0.1.1版本官方版本已经解决

error 3

  File "/home/wd337/projects/mmrotate/mmrotate/datasets/dota.py", line 199, in evaluate
    mean_ap, _ = eval_map(
  File "/home/wd337/projects/mmrotate/mmrotate/datasets/dota.py", line 454, in eval_map
    print_map_summary(
  File "/home/wd337/projects/mmrotate/mmrotate/datasets/dota.py", line 516, in print_map_summary
    label_names[j], num_gts[i, j], results[j]['num_dets'],
IndexError: tuple index out of range

配置文件中的class没有改完全,使用的r3det配置文件中在model中的refine_heads中也有num_class参数,修改为自己的class数即可

error 4

Traceback (most recent call last):
  File "tools/train.py", line 182, in <module>
    main()
  File "tools/train.py", line 171, in main
    train_detector(
  File "/home/wd337/projects/mmrotate/mmrotate/apis/train.py", line 156, in train_detector
    runner.run(data_loaders, cfg.workflow)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 127, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 47, in train
    for i, data_batch in enumerate(self.data_loader):
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 359, in __iter__
    return self._get_iterator()
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 305, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 944, in __init__
    self._reset(loader, first_iter=True)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 975, in _reset
    self._try_put_index()
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1209, in _try_put_index
    index = self._next_index()
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 512, in _next_index
    return next(self._sampler_iter)  # may raise StopIteration
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 226, in __iter__
    for idx in self.sampler:
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmdet/datasets/samplers/group_sampler.py", line 36, in __iter__
    indices = np.concatenate(indices)
  File "<__array_function__ internals>", line 180, in concatenate
ValueError: need at least one array to concatenate

原因:
配置文件中的数据集路径写错了,一定要仔细检查

error 5

Traceback (most recent call last):
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/wd337/projects/mmrotate/mmrotate/models/detectors/r3det.py", line 48, in __init__
    self.refine_head.append(build_head(refine_head))
  File "/home/wd337/projects/mmrotate/mmrotate/models/builder.py", line 37, in build_head
    return ROTATED_HEADS.build(cfg)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/registry.py", line 24, in build_from_cfg
    raise KeyError(
KeyError: '`cfg` or `default_args` must contain the key "type", but got {\'num_classes\': 2, \'train_cfg\': {\'assigner\': {\'type\': \'MaxIoUAssigner\', \'pos_iou_thr\': 0.6, \'neg_iou_thr\': 0.5, \'min_pos_iou\': 0, \'ignore_iof_thr\': -1, \'iou_calculator\': {\'type\': \'RBboxOverlaps2D\'}}, \'allowed_border\': -1, \'pos_weight\': -1, \'debug\': False}, \'test_cfg\': {\'nms_pre\': 2000, \'min_bbox_size\': 0, \'score_thr\': 0.05, \'nms\': {\'iou_thr\': 0.1}, \'max_per_img\': 2000}}\nNone'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/train.py", line 182, in <module>
    main()
  File "tools/train.py", line 152, in main
    model = build_detector(
  File "/home/wd337/projects/mmrotate/mmrotate/models/builder.py", line 55, in build_detector
    return ROTATED_DETECTORS.build(
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/wd337/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: 'R3Det: \'`cfg` or `default_args` must contain the key "type", but got {\\\'num_classes\\\': 2, \\\'train_cfg\\\': {\\\'assigner\\\': {\\\'type\\\': \\\'MaxIoUAssigner\\\', \\\'pos_iou_thr\\\': 0.6, \\\'neg_iou_thr\\\': 0.5, \\\'min_pos_iou\\\': 0, \\\'ignore_iof_thr\\\': -1, \\\'iou_calculator\\\': {\\\'type\\\': \\\'RBboxOverlaps2D\\\'}}, \\\'allowed_border\\\': -1, \\\'pos_weight\\\': -1, \\\'debug\\\': False}, \\\'test_cfg\\\': {\\\'nms_pre\\\': 2000, \\\'min_bbox_size\\\': 0, \\\'score_thr\\\': 0.05, \\\'nms\\\': {\\\'iou_thr\\\': 0.1}, \\\'max_per_img\\\': 2000}}\\nNone\''

原因,配置文件的写法不规范

error 6

最后的结果都是歪的,但是mAP却很高
原因:
在确认框的方向的时候将坐标系搞错,从而在转换数据集的时候缺少了一个负号,因此框全都少了同样的角度

error 7

修改backbone中的ReResNet不起作用
原因:
默认的配置是使用的ResNet和FPN,并不是仓库中用e2cnn重写的ReResNet和ReFPN

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-04-07 22:41:41  更:2022-04-07 22:46:01 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 11:44:31-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码