配置环境:
RTX3090
PyTorch 1.9.0
CUDA 11.3
cudnn 8.2.0
mmcv 0.5.9(旧版本)
opencv 3.4.4.19(旧版本)
DOTA数据集下载:https://captain-whu.github.io/DOTA/dataset.html
R3Det训练好的checkpoints(用于test测试,u8bj):https://pan.baidu.com/share/init?surl=Ijmh1Lco4T7HPwAtT2h0Zg
项目地址:https://github.com/SJTU-Thinklab-Det/r3det-on-mmdetection
论文:https://arxiv.org/abs/1908.05612
实验步骤:
一、安装
下载项目:
git clone https://github.com/SJTU-Thinklab-Det/r3det-on-mmdetection
运行安装脚本:
python setup.py install
卸载mmcv和opencv,重新安装配置要求的旧版本,否则后面会报错。
pip3 uninstall mmcv
pip3 uninstall opencv-python
输入指令查看是否安装成功项目的修改版mmdet
pip3 list
#包含以下库,即安装成功
mmdet (2.1.0+unknown, /usr/local/lib/python3.6/dist-packages/mmdet-2.1.0+unknown-py3.6-linux-x86_64.egg)
二、训练train
图片裁剪:修改dota_image_split.py中关于存储DOTA1.0数据集的位置
if __name__ == '__main__':
trainsplit = DOTAImageSplitTool('../data/dota/train',
'../data/dota/trainsplit',
tile_overlap=(150, 150),
tile_shape=(600, 600))
trainsplit.split()
valsplit = DOTAImageSplitTool('../data/dota/val',
'../data/dota/valsplit',
tile_overlap=(150, 150),
tile_shape=(600, 600))
valsplit.split()
运行图片裁剪脚本
python dota_image_split.py
修改./r3det-on-mmdetection/configs/r3det/datasets/dotav1_rotational_detection.py下的代码为裁剪后的数据集地址
data_root = '/home/slz/桌面/r3det-on-mmdetection-master/data/dota/'
trainsplit_ann_folder = 'trainsplit/labelTxt'
trainsplit_img_folder = 'trainsplit/images'
valsplit_ann_folder = 'valsplit/labelTxt'
valsplit_img_folder = 'valsplit/images'
val_ann_folder = 'val/labelTxt'
val_img_folder = 'val/images'
test_img_folder = 'test/images'
在根目录运行脚本文件,其中可能会出现一些路径问题,稍加修改可以解决
#在rtools目录下运行
python3 ../tools/train.py ../configs/r3det/r3det_r50_fpn_2x_CustomizeImageSplit.py
三、测试test
在根目录创建work_dirs目录,将下载好的checkpoints放到该目录下
#在rtools目录下运行
python tools/test.py configs/r3det/r3det_r50_fpn_2x_CustomizeImageSplit.py work_dirs/r3det_r50_fpn_2x_20200616/epoch_24.pth --format-only --options submission_dir=work_dirs/r3det_r50_fpn_2x_20200616/submission
结果以test文件输出
四、可视化Visualize
在rootls目录下直接运行
python3 ./dota_result_visualize.py ../configs/r3det/r3det_r50_fpn_2x_CustomizeImageSplit.py ../work_dirs/r3det_r50_fpn_2x_20200616/epoch_24.pth
会导致随机只输出一张图片,还需手动保存。
解决方法:
修改mmdet库,以下为本机mmdet位置,不要修改项目中的mmdet
'/usr/local/lib/python3.6/dist-packages/mmdet-2.1.0+unknown-py3.6-linux-x86_64.egg/mmdet/apis/rtest.py'
修改single_gpu_mergetiles_visualize方法成如下:
def single_gpu_mergetiles_visualize(model,
data_loader,save_dir,
show_score_thr=0.3):
model.eval()
dataset = data_loader.dataset
prog_bar = mmcv.ProgressBar(len(dataset))
for i, data in enumerate(data_loader):
with torch.no_grad():
result = model(return_loss=False, rescale=True, **data)
img_show = image_merge(data)
model.module.show_result(
img_show,
result,
show=True,
out_file=save_dir+'{}.png'.format(i),
score_thr=show_score_thr)
prog_bar.update()
添加了一个save_dir参数
修改rtools目录下的dota_result_visualize.py中的main函数下调用single_gpu_mergetiles_visualize方法代码添加并修改为
save_dir='/home/slz/桌面/r3det-on-mmdetection-master/resultPNG/'
single_gpu_mergetiles_visualize(model=model, data_loader=data_loader,save_dir=save_dir, show_score_thr=0.3)
再在rtools目录下运行
python3 ./dota_result_visualize.py ../configs/r3det/r3det_r50_fpn_2x_CustomizeImageSplit.py ../work_dirs/r3det_r50_fpn_2x_20200616/epoch_24.pth
即可保存结果到resultPNG目录下
版权声明:本文为CSDN博主「Sonrikisou1997」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Sonrikisou1997/article/details/118678272
暂无评论