Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/DOTA_devkit/prepare_dota1_ms.py
Views: 475
import os1import os.path as osp23from DOTA_devkit.DOTA2JSON import generate_json_labels4from DOTA_devkit.DOTA2COCO_poly import DOTA2COCOTrain, DOTA2COCOTest, wordname_1556from DOTA_devkit.ImgSplit_multi_process import splitbase as splitbase_trainval7from DOTA_devkit.SplitOnlyImage_multi_process import \8splitbase as splitbase_test91011def mkdir_if_not_exists(path):12if not osp.exists(path):13os.mkdir(path)1415def prepare_multi_scale_data(src_path, dst_path, gap=200, subsize=1024, scales=[0.5, 1.0, 1.5], num_process=32):16"""Prepare DOTA split data and labels17Args:18src_path: dataset path19dst_path: output path20gap: overlapping area21subsize: size of chip image22scales: multi-scale settings23num_process: num of processer24"""25dst_train_path = osp.join(dst_path, 'train_split')26dst_val_path = osp.join(dst_path, 'val_split')27dst_trainval_path = osp.join(dst_path, 'trainval_split')28dst_test_base_path = osp.join(dst_path, 'test_split')29dst_test_path = osp.join(dst_path, 'test_split/images')30# make dst path if not exist31mkdir_if_not_exists(dst_path)32mkdir_if_not_exists(dst_train_path)33mkdir_if_not_exists(dst_val_path)34mkdir_if_not_exists(dst_test_base_path)35mkdir_if_not_exists(dst_test_path)36# split train data37print('split train data')38split_train = splitbase_trainval(osp.join(src_path, 'train'), dst_train_path,39gap=gap, subsize=subsize, num_process=num_process)40for scale in scales:41split_train.splitdata(scale)42print('split val data')43# split val data44split_val = splitbase_trainval(osp.join(src_path, 'val'), dst_val_path,45gap=gap, subsize=subsize, num_process=num_process)46for scale in scales:47split_val.splitdata(scale)48# split test data49print('split test data')50split_test = splitbase_test(osp.join(src_path, 'test/images'), dst_test_path,51gap=gap, subsize=subsize, num_process=num_process)52for scale in scales:53split_test.splitdata(scale)5455# prepare trainval data56print('move train val to trainval')57mkdir_if_not_exists(dst_trainval_path)58os.system(59'mv {}/* {}'.format(dst_train_path, dst_trainval_path))60os.system('find '+dst_val_path+'/images/ -name "*.png" -exec mv {} ' +61dst_trainval_path + '/images/ \\;')62os.system('find '+dst_val_path+'/labelTxt/ -name "*.txt" -exec mv {} ' +63dst_trainval_path + '/labelTxt/ \\;')6465print('generate labels with json format')66generate_json_labels(dst_trainval_path, osp.join(67dst_trainval_path, 'trainval.json'))68generate_json_labels(dst_test_base_path, osp.join(69dst_test_base_path, 'test.json'), trainval=False)70print('generate labels with coco format')71DOTA2COCOTrain(dst_trainval_path,72osp.join(dst_trainval_path, 'trainval_coco_8point.json'),73wordname_15)74DOTA2COCOTest(dst_test_base_path,75osp.join(dst_test_base_path, 'test_coco_8point.json'),76wordname_15)777879if __name__ == '__main__':80# single scale81prepare_multi_scale_data('/data1/dataset_demo/DOTA_demo/',82'/data1/OrientedRepPoints/data/dota_1024', scales=[1.0], gap=200)83# multi scale84# prepare_multi_scale_data('/mnt/SSD/lwt_workdir/data/dota_new/',85# '/mnt/SSD/lwt_workdir/data/dota_1024_ms', scales=[0.5, 1.0, 1.5], gap=500)86print('done')878889