网上没有HRSC2016 数据集 L2 L3 task 任务的开源项目,我的毕设跟老师吹的牛是把数据集用到L2、L3任务上,现在发现没有开源代码,心态没了。
接下来这段时间尝试手写代码,完成这个任务。
还是接着之前使用的autodl 的GPU,当时保存镜像了,现在拖过来可以直接使用。
1.修改网络模型中 num_class=33configsobboriented_rcnnfaster_rcnn_orpn_r50_fpn_3x_hrsc.py
num_classes=1,改成33
configsobb_base_datasetshrsc.py
classwise=False,改成True
训练读取的标签从哪读取?
为什么都没改读取标签的位置就能行?
因为数据集里的annotation还是labelTxt,用的是哪个我不确定。先把testdataset里边的labelTxt文件夹删掉进行测试。能运行,表示Oriented R-CNN没用labelTxt里边的文件,那我直接修改上边两处试试。
(obbdetection) root@container-bd721182ac-1b86a0fe:~/OBBDetection# python tools/test.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py /root/OBBDetection/work_dirs/epoch_35.pth --eval mAP
Starting loading HRSC dataset information.
100%|███████████████████████████████████████████████████████████████████████████████████████| 444/444 [00:00<00:00, 4659.11it/s]
Finishing loading HRSC, get 444 images, using 0.214s.
load checkpoint from local path: /root/OBBDetection/work_dirs/epoch_35.pth
[ ] 0/444, elapsed: 0s, ETA:/root/OBBDetection/mmdet/core/post_processing/obb/obb_nms.py:29: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1595629403081/work/torch/csrc/utils/python_arg_parser.cpp:766.)
labels = valid_mask.nonzero()[:, 1]
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 444/444, 9.9 task/s, elapsed: 45s, ETA: 0s
+-------+------+------+--------+--------+
| class | gts | dets | recall | ap |
+-------+------+------+--------+--------+
| ship | 1188 | 3160 | 0.9840 | 0.9049 |
+-------+------+------+--------+--------+
| mAP | | | | 0.9049 |
+-------+------+------+--------+--------+
不确定: 现在看他的Annotation里的东西我们没用到。当时转化成txt格式了,后边都是ship,0/1,看来还得再转换一边。
4. 修改前 完整性测试先运行一下 Train.py,确保修改之前正确。
nohup python tools/train.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py --work-dir work_dirs >xcbTrain202205171509.log 2>&1 &
可以正常训练。
5.然后修改参数configsobboriented_rcnnfaster_rcnn_orpn_r50_fpn_3x_hrsc.py
num_classes=1,改成33
configsobb_base_datasetshrsc.py
classwise=False,改成True
nohup python tools/train.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py --work-dir work_dirs >xcbTrain202205171520.log 2>&1 &
2022年5月17日15点22分
训练一下,2080Ti的GPU 预计使用一个半小时。打游戏了。
可以看GPU的使用情况,2s刷新一次。
watch -n 2 -d nvidia-smi
中途因为空间不够(他每次都生成xepoch.pth),中断了,所以重新恢复训练。
这里注意,从Jupyter notebook 选中后右键删除的文件并没从磁盘上消失,也就是你的磁盘空间还是不足,因为他放入了回收站、c。
用这个代码清空回收站
rm -rf ~/.local/share/Trash/*
可以用这个语句查询磁盘空间
df -h 或者 df /root/OBBDetection 其他等等。
然后我们恢复训练。注意,我们上次失败是存储到epoch24.pth了。但是数据不全,所以从epoch23.pth开始恢复
nohup python tools/train.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py --work-dir work_dirs --resume-from work_dirs/epoch_23.pth >xcbTrain202205171647.log 2>&1 &
训练完成了,让我们找个图片测试。
6.测试图片python demo/image_demo.py demo/100001132.bmp configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py work_dirs/epoch_36.pth
贴上几张图片。
注意:每个预测框上的第一个数字表示33个类型,比如09表示佩里级护卫舰 perry class frigate。这个文件在imageset里叫 sysdata.xml
下面是sysdata.xml 部分标签的参考:
先用VOC07评价:
(obbdetection) root@container-bd721182ac-1b86a0fe:~/OBBDetection# python tools/test.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py /root/OBBDetection/work_dirs/epoch_36.pth --eval mAP --options use_07_metric=True
Starting loading HRSC dataset information.
100%|█████████████████████████████████████████████████████████████████████████| 444/444 [00:00<00:00, 5789.69it/s]
Finishing loading HRSC, get 444 images, using 0.148s.
load checkpoint from local path: /root/OBBDetection/work_dirs/epoch_36.pth
[ ] 0/444, elapsed: 0s, ETA:/root/OBBDetection/mmdet/core/post_processing/obb/obb_nms.py:29: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1595629403081/work/torch/csrc/utils/python_arg_parser.cpp:766.)
labels = valid_mask.nonzero()[:, 1]
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 444/444, 10.0 task/s, elapsed: 44s, ETA: 0s
+-------+-----+------+--------+--------+
| class | gts | dets | recall | ap |
+-------+-----+------+--------+--------+
| 01 | 230 | 547 | 0.8391 | 0.6287 |
| 02 | 0 | 0 | 0.0000 | 0.0000 |
| 03 | 22 | 284 | 0.9091 | 0.1458 |
| 04 | 2 | 0 | 0.0000 | 0.0000 |
| 05 | 35 | 70 | 1.0000 | 0.8107 |
| 06 | 12 | 76 | 0.9167 | 0.4671 |
| 07 | 158 | 293 | 0.9684 | 0.8945 |
| 08 | 40 | 111 | 0.9250 | 0.8055 |
| 09 | 128 | 268 | 0.9766 | 0.8960 |
| 10 | 22 | 103 | 1.0000 | 0.9716 |
| 11 | 103 | 212 | 0.9806 | 0.9072 |
| 12 | 1 | 0 | 0.0000 | 0.0000 |
| 13 | 2 | 68 | 1.0000 | 0.4000 |
| 14 | 0 | 0 | 0.0000 | 0.0000 |
| 15 | 35 | 93 | 1.0000 | 0.9225 |
| 16 | 50 | 84 | 1.0000 | 0.9917 |
| 17 | 1 | 0 | 0.0000 | 0.0000 |
| 18 | 18 | 49 | 0.8889 | 0.6243 |
| 19 | 39 | 112 | 0.9487 | 0.8279 |
| 20 | 16 | 32 | 1.0000 | 0.9192 |
| 21 | 0 | 0 | 0.0000 | 0.0000 |
| 22 | 50 | 73 | 0.9200 | 0.7254 |
| 23 | 0 | 0 | 0.0000 | 0.0000 |
| 24 | 1 | 34 | 1.0000 | 0.0303 |
| 25 | 119 | 214 | 0.9076 | 0.8259 |
| 26 | 4 | 69 | 1.0000 | 0.4387 |
| 27 | 60 | 82 | 0.9500 | 0.8959 |
| 28 | 4 | 7 | 0.7500 | 0.4870 |
| 29 | 10 | 79 | 1.0000 | 0.9587 |
| 30 | 16 | 57 | 0.9375 | 0.8745 |
| 31 | 0 | 0 | 0.0000 | 0.0000 |
| 32 | 10 | 67 | 1.0000 | 0.9504 |
| 33 | 0 | 0 | 0.0000 | 0.0000 |
+-------+-----+------+--------+--------+
| mAP | | | | 0.6444 |
+-------+-----+------+--------+--------+
用VOC12评价
python tools/test.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py /root/OBBDetection/work_dirs/epoch_36.pth --eval mAP --options use_07_metric=False
Starting loading HRSC dataset information.
100%|█████████████████████████████████████████████████████████████████████████| 444/444 [00:00<00:00, 6964.86it/s]
Finishing loading HRSC, get 444 images, using 0.139s.
load checkpoint from local path: /root/OBBDetection/work_dirs/epoch_36.pth
[ ] 0/444, elapsed: 0s, ETA:/root/OBBDetection/mmdet/core/post_processing/obb/obb_nms.py:29: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1595629403081/work/torch/csrc/utils/python_arg_parser.cpp:766.)
labels = valid_mask.nonzero()[:, 1]
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 444/444, 10.0 task/s, elapsed: 44s, ETA: 0s
+-------+-----+------+--------+--------+
| class | gts | dets | recall | ap |
+-------+-----+------+--------+--------+
| 01 | 230 | 547 | 0.8391 | 0.6419 |
| 02 | 0 | 0 | 0.0000 | 0.0000 |
| 03 | 22 | 284 | 0.9091 | 0.1445 |
| 04 | 2 | 0 | 0.0000 | 0.0000 |
| 05 | 35 | 70 | 1.0000 | 0.8120 |
| 06 | 12 | 76 | 0.9167 | 0.4504 |
| 07 | 158 | 293 | 0.9684 | 0.9453 |
| 08 | 40 | 111 | 0.9250 | 0.8261 |
| 09 | 128 | 268 | 0.9766 | 0.9495 |
| 10 | 22 | 103 | 1.0000 | 0.9755 |
| 11 | 103 | 212 | 0.9806 | 0.9726 |
| 12 | 1 | 0 | 0.0000 | 0.0000 |
| 13 | 2 | 68 | 1.0000 | 0.4000 |
| 14 | 0 | 0 | 0.0000 | 0.0000 |
| 15 | 35 | 93 | 1.0000 | 0.9441 |
| 16 | 50 | 84 | 1.0000 | 0.9970 |
| 17 | 1 | 0 | 0.0000 | 0.0000 |
| 18 | 18 | 49 | 0.8889 | 0.6429 |
| 19 | 39 | 112 | 0.9487 | 0.8628 |
| 20 | 16 | 32 | 1.0000 | 0.9236 |
| 21 | 0 | 0 | 0.0000 | 0.0000 |
| 22 | 50 | 73 | 0.9200 | 0.7296 |
| 23 | 0 | 0 | 0.0000 | 0.0000 |
| 24 | 1 | 34 | 1.0000 | 0.0303 |
| 25 | 119 | 214 | 0.9076 | 0.8414 |
| 26 | 4 | 69 | 1.0000 | 0.4248 |
| 27 | 60 | 82 | 0.9500 | 0.9305 |
| 28 | 4 | 7 | 0.7500 | 0.4821 |
| 29 | 10 | 79 | 1.0000 | 0.9636 |
| 30 | 16 | 57 | 0.9375 | 0.9014 |
| 31 | 0 | 0 | 0.0000 | 0.0000 |
| 32 | 10 | 67 | 1.0000 | 0.9455 |
| 33 | 0 | 0 | 0.0000 | 0.0000 |
+-------+-----+------+--------+--------+
| mAP | | | | 0.6569 |
+-------+-----+------+--------+--------+
我找到了有两篇做了L3L2 task的文章他们没开源
分别是:
Ship detection and classification from optical
remote sensing images: A survey
好像是民航和北航联合做的,删掉了不存在的类
还有一篇西电的硕士毕业论文:
基于深度学习的卫星图像目标检测算法研究_李巍
精度我也没看他们用的VOC几,因为目前类的数量不同。
本文参考的代码上直接使用了33类的,就是HRSC2016自带的所有标签,可以看出有些标签根本不存在,可能他们的文章为了美观没放上去,这个后续再说吧。
我下一步尝试进行L2 级别的task。
说来很惭愧,我自己什么都没做,只是改了几处代码 :<
现在已知的信息是:
1.能做L1 task 分类,只有ship 1 class
2.能做L3 task 分类,有 33 classs
修改的地方只有 classwise 和 num_class
接下来把num_class 改成四试试。
然后在BboxToolkitdatasetsmisc.py文件中加入
'HRSC_4cls': ('01', '02', '03', '04'),
还得在dataset_aliases
加入
'HRSC_cls': product(['hrsc', 'HRSC'], ['_4cls', '2016_4cls']),
在mmdetdatasetsobbhrsc.py中
修改:
if classwise:
HRSCDataset.CLASSES = bt.get_classes('hrsc_4cls')
然后进行测试。
忙着头做的,也不知道行不行,好紧张。一个小时后见分晓。
2022年5月17日19点25分
打游戏去。
nohup python tools/train.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py --work-dir work_dirs >xcbTrain202205171920.log 2>&1 &8.完了
‘HRSC_4cls’: product([‘hrsc’, ‘HRSC’], [‘_4cls’, ‘2016_4cls’]),
这个地方训练之前HRSC_CLS
忘记加4了,先试试epoch5.pth 怎么样。
epoch5,7,10 都检测不出来,
log显示 坏了
刚才粗心了,现在重新训练。
(obbdetection) root@container-bd721182ac-1b86a0fe:~/OBBDetection# python tools/test.py configs/obb/oriented_rcnn/faster_rcnn_orpn_r101_fpn_3x_hrsc.py /root/OBBDetection/work_dirs/epoch_36.pth --eval mAP
Starting loading HRSC dataset information.
100%|████████████████████████████████████████████████████████████████████████| 444/444 [00:00<00:00, 10876.42it/s]
Finishing loading HRSC, get 444 images, using 0.131s.
load checkpoint from local path: /root/OBBDetection/work_dirs/epoch_36.pth
[ ] 0/444, elapsed: 0s, ETA:/root/OBBDetection/mmdet/core/post_processing/obb/obb_nms.py:29: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1595629403081/work/torch/csrc/utils/python_arg_parser.cpp:766.)
labels = valid_mask.nonzero()[:, 1]
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 444/444, 10.2 task/s, elapsed: 44s, ETA: 0s
+-------+-----+------+--------+--------+
| class | gts | dets | recall | ap |
+-------+-----+------+--------+--------+
| 01 | 230 | 1668 | 0.7913 | 0.5600 |
| 02 | 0 | 1158 | 0.0000 | 0.0000 |
| 03 | 22 | 1516 | 0.5000 | 0.1264 |
| 04 | 2 | 1147 | 0.0000 | 0.0000 |
+-------+-----+------+--------+--------+
| mAP | | | | 0.2288 |
+-------+-----+------+--------+--------+
肯定是读取的标签不对,相当于我把33个类减到四个类了c。
肯定得从读取标签的地方入手。
BboxToolkitdatasetsHRSCio.py文件中,
修改Class_ID为HRS_Class_ID
cls = obj.find('Class_ID').text
改为
cls = obj.find('HRS_Class_ID').text
报错了,这个是sysdata.xml的名称,应该改每张图片对应的annotation的
应该把他加载annotation的代码,Class_ID为HRS_Class_ID。明天再说,今天腰疼了。



