-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_up_dota.py
44 lines (33 loc) · 1.14 KB
/
clean_up_dota.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import argparse
import os
import shutil
from tqdm import tqdm
from dota_utils import extract_annotations, extract_ids
def arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--data_dir', default='./train')
args = parser.parse_args()
return args
def main(args):
out = f'{args.data_dir}_clean'
if os.path.exists(out):
shutil.rmtree(out)
os.mkdir(out)
os.mkdir(f'{out}/images')
os.mkdir(f'{out}/annotations')
fpath = f'{args.data_dir}/images'
ids = extract_ids(fpath)
for id_ in tqdm(ids):
anno_file = f'{args.data_dir}/annotations/{id_}.txt'
image_file = f'{fpath}/{id_}.png'
bbox, labels, difficult = extract_annotations(anno_file, False)
# exclude too large images.
if os.path.getsize(image_file) < 1e+7:
# exclude no bounding box images.
if len(bbox) != 0:
shutil.copyfile(image_file,
f'{out}/images/{id_}.png')
shutil.copyfile(anno_file,
f'{out}/annotations/{id_}.txt')
if __name__ == '__main__':
main(arg_parser())