-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_datalist.py
32 lines (24 loc) · 960 Bytes
/
create_datalist.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
import os
import argparse
from random import shuffle
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--folder_path")
return parser.parse_args()
def write_file(prefix: str, filename: str, image_list) -> None:
with open(filename, 'w') as f:
for image in image_list:
image_name = os.path.join(prefix, image)
f.write(f"{image_name}\n")
def main():
args = parse_args()
image_list = [filename for filename in os.listdir(args.folder_path)
if filename[-4:] != ".txt"]
validation_count = int(len(image_list) * 0.1)
print(f"Training set count: {len(image_list) - validation_count}")
print(f"Validation set count: {validation_count}")
shuffle(image_list)
write_file(args.folder_path, 'valid.txt', image_list[:validation_count])
write_file(args.folder_path, 'train.txt', image_list[validation_count:])
if __name__ == "__main__":
main()