forked from SincereXu404/food_cls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.py
48 lines (34 loc) · 1.23 KB
/
prepare.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
45
46
47
48
import numpy as np
import os
from tqdm import tqdm
import argparse
def prepare_data(src_path, out_path):
cls_paths = [src_path + '/' + str(i) for i in range(cls_num)]
fo = open(out_path, 'w')
for idx, cls_path in enumerate(tqdm(cls_paths)):
files = os.listdir(cls_path)
for file in files:
image_path = cls_path + os.sep + file
info = image_path + '\t' + str(idx) + '\n'
fo.write(info)
fo.close()
def parse_args():
parser = argparse.ArgumentParser(description='MiSLAS training (Stage-1)')
parser.add_argument('--src',
help='path to src data',
required=True,
type=str)
parser.add_argument('--out',
help='path to save txt',
required=True,
type=str)
args = parser.parse_args()
return args
if __name__ == '__main__':
''' e.g.: python prepare.py --src ./data/food/train --out ./data/food/train.txt '''
''' : python prepare.py --src ./data/food/val --out ./data/food/val.txt '''
args = parse_args()
cls_num = 101
src_path = args.src
out_path = args.out
prepare_data(src_path, out_path)