论文复现使用PaddleDetection复现OrientedRepPoints的复现笔记
Posted songyuc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了论文复现使用PaddleDetection复现OrientedRepPoints的复现笔记相关的知识,希望对你有一定的参考价值。
1 复现流程
复现流程表:
- 翻译原始论文;
- 学习PaddleDetection配置参数
- 对齐Dataloader;
2 MMRotate原始模型代码
2.1 数据集配置:DOTA1.0
2.1.1 在Win11上使用mklink创建软链接
示例代码:
mklink /j "D:\\Professional\\Paddle\\mmrotate_oriented_reppoints\\data\\DOTA" "D:\\Professional\\Paddle\\DOTA"
2.1.2 划分数据集:mmrotate: split dota dataset
1024×1024 patches with an overlap of 200
Ss_trainval:
python tools/data/dota/split/img_split.py --base-json tools/data/dota/split/split_configs/ss_trainval.json
Ss_test:
python tools/data/dota/split/img_split.py --base-json tools/data/dota/split/split_configs/ss_test.json
Multiple scale dataset
Ms_trainval:
python tools/data/dota/split/img_split.py --base-json tools/data/dota/split/split_configs/ms_trainval.json
ms_test:
python tools/data/dota/split/img_split.py --base-json tools/data/dota/split/split_configs/ms_test.json
Clone原始模型代码:
git clone https://github.com/open-mmlab/mmrotate.git mmrotate_oriented_reppoints
2.2 配置mmrotate环境
验证mmrotate安装时出现错误:“RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)”
在使用mmrotate官方示例验证其安装时,出现错误:
[mmrotate_oriented_reppoints]:
…
File “d:\\professional\\xxx\\mmrotate\\models\\roi_heads\\bbox_heads\\rotated_bbox_head.py”, line 418, in get_bboxes
det_bboxes, det_labels = multiclass_nms_rotated(
File “d:\\professional\\xxx\\mmrotate\\core\\post_processing\\bbox_nms_rotated.py”, line 58, in multiclass_nms_rotated
bboxes, scores, labels = bboxes[inds], scores[inds], labels[inds]
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
(1)将测试命令修改为使用cpu
进行推理:
python demo/image_demo.py demo/demo.jpg oriented_rcnn_r50_fpn_1x_dota_le90.py oriented_rcnn_r50_fpn_1x_dota_le90-6d2b2ce0.pth --out-file result.jpg --device cpu
(2)将出错位置的张量索引操作改成一致的设备
大概率出错的是这两句代码:
def assign(self,
points,
gt_rbboxes,
gt_rbboxes_ignore=None,
gt_labels=None,
overlaps=None):
......
gt_bboxes_wh = (gt_bboxes[:, 2:] - gt_bboxes[:, :2]).clamp(min=1e-6)
scale = self.scale
gt_bboxes_lvl = ((torch.log2(gt_bboxes_wh[:, 0] / scale) +
torch.log2(gt_bboxes_wh[:, 1] / scale)) / 2).int()
gt_bboxes_lvl = torch.clamp(gt_bboxes_lvl, min=lvl_min, max=lvl_max)
# stores the assigned gt index of each point
assigned_gt_inds = points.new_zeros((num_points, ), dtype=torch.long)
# stores the assigned gt dist (to this point) of each point
assigned_gt_dist = points.new_full((num_points, ), float('inf'))
points_range = torch.arange(points.shape[0]) # NOT specify a device
for idx in range(num_gts):
gt_lvl = gt_bboxes_lvl[idx]
# get the index of points in this level
lvl_idx = gt_lvl == points_lvl
points_index = points_range[lvl_idx] # <-- error1
...
# the index of nearest k points to gt center in this level
min_dist_points_index = points_index[min_dist_index] # <-- error2
我看了一下,points_index
也是来自于points_range
,很大的可能性是points_range
的设备不一致,然后track上去,发现points_range = torch.arange(points.shape[0])
这一句代码没有显示指定设备,可能会分配到CPU上从而引发错误,于是把代码修改为:
points_range = torch.arange(points.shape[0]).to(gt_bboxes_lvl.device) # 跟gt_bboxes_lvl的设备保持一致
4 PaddleDetection学习笔记
4.1 配置环境&Clone代码
创建conda环境:
conda create --name conda-paddle python=3.10
Clone代码:
git clone https://github.com/PaddlePaddle/PaddleDetection.git Paddle_oriented_reppoints
4.2 PaddleDetection配置文件说明
_BASE_
:基础配置
‘…/…/datasets/dota.yml’:DOTA数据集配置文件
‘…/…/runtime.yml’:运行时配置
5 重写配置文件
5.1 超参数换算表
mmrorate | paddleDetection |
---|---|
lr_config.step | schedulers.milestones = step - 1 |
Backbone: | |
frozen_stages (1) | freeze_at = frozen_stages - 1 (0) |
out_indices | return_idx = out_indices + 1 |
FPN: | |
start_level | extra_stage = start_level + 1 |
Head: | |
anchor_generator.scales | anchor_scales = scales |
关于schedulers.milestones
的设置
这个我已经跟鑫鑫确认了,schedulers.milestones = step - 1,聊天记录如下:
以上是关于论文复现使用PaddleDetection复现OrientedRepPoints的复现笔记的主要内容,如果未能解决你的问题,请参考以下文章
全网良心论文复现!Centos 7.9 复现MAPPO出现的问题汇总收藏干货