|
- import sys
- import os
- import subprocess
- import shutil
-
- # os.chdir(sys.path[0])
-
- if __name__ == '__main__':
-
- base_dir = os.path.dirname(__file__)
-
- orignal_data = base_dir + '/dataset/datasets_hw'
- mmrotate_dota = base_dir + '/dataset/DOTA'
- run_path = base_dir + '/mmrotate'
-
- # data to dota
- '''
- if not os.path.isdir(mmrotate_dota):
- os.makedirs(mmrotate_data,exist_ok=True)
- os.symlink(orignal_data,mmrotate_dota)
- '''
- path_create = ['train', 'val', 'test']
- for target_path in path_create:
- # os.makedirs(mmrotate_dota + os.sep + target_path + os.sep + 'images',exist_ok=True)
- os.makedirs(mmrotate_dota + os.sep + target_path + os.sep + 'labelTxt', exist_ok=True)
- try:
- shutil.copytree(orignal_data + os.sep + target_path + os.sep + 'images',
- mmrotate_dota + os.sep + target_path + os.sep + 'images')
- except FileExistsError:
- pass
-
- for dirName, subDirs, files in os.walk(orignal_data):
-
- for filename in files:
- if not filename.endswith('.txt'):
- continue
- else:
- target_read = dirName + os.sep + filename
- target_write = mmrotate_dota + target_read.replace(orignal_data, '')
- target_write = target_write.replace('annotations', 'labelTxt')
-
- dota_string = 'imagesource:BUAA\ngsd:0\n'
-
- with open(target_read, 'r') as f:
- for line in f:
- number, level, category, _1, _2, _3, _4, x1, y1, x2, y2, x3, y3, x4, y4 = line.strip(
- '\n').split(' ')
- dota_string += f'{x1} {y1} {x2} {y2} {x3} {y3} {x4} {y4} {category} 0\n'
- # print(line.strip('\n').split(' '))
-
- with open(target_write, 'w') as f:
- f.write(dota_string)
-
- exit(1)
- # split data
- os.chdir(run_path)
-
- commands = [
- 'python mmrotate/tools/data/dota/split/img_split.py --base-json mmrotate/tools/data/dota/split/split_configs/ss_train.json',
- 'python mmrotate/tools/data/dota/split/img_split.py --base-json mmrotate/tools/data/dota/split/split_configs/ss_val.json',
- 'python mmrotate/tools/data/dota/split/img_split.py --base-json mmrotate/tools/data/dota/split/split_configs/ss_test.json',
- ]
- for command in commands:
- os.system(command)
|