-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_val_data.py
32 lines (27 loc) · 1.1 KB
/
preprocess_val_data.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
from glob import glob
import argparse
from shutil import move
from os.path import join, basename
from os import makedirs
import numpy as np
parser = argparse.ArgumentParser('Export model', add_help=False)
parser.add_argument('-i', '--input', type=str, help='Input (directory).')
parser.add_argument('-o', '--output', type=str, help='Output (directory).')
parser.add_argument('-n', '--num', type=int, help='Number of items.')
parser.add_argument('-s', '--seed', default=None, type=int, help='Random seed.')
args = parser.parse_args()
files = sorted(glob(join(args.input, 'images', '*.*')))
if args.seed is not None:
np.random.seed(args.seed)
sel = np.random.choice(files, args.num, replace=False)
makedirs(join(args.output, 'images'), exist_ok=True)
makedirs(join(args.output, 'labels'), exist_ok=True)
for f in sel:
f_, = glob(join(args.input, 'labels', '.'.join(basename(f).split('.')[:-1]) + '*'))
f_dst = join(args.output, 'images', basename(f))
f_dst_ = join(args.output, 'labels', basename(f_))
print(f, '-->', f_dst)
move(f, f_dst)
print(f_, '-->', f_dst_)
move(f_, f_dst_)
print()