forked from YunseokJANG/l2l-da
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny_imagenet_val_format.py
32 lines (26 loc) · 982 Bytes
/
tiny_imagenet_val_format.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
# script modified from https://raw.githubusercontent.com/tjmoon0104/pytorch-tiny-imagenet/master/val_format.py
import io
import glob
import os
from shutil import move
from os.path import join
from os import listdir, rmdir
target_folder = './datasets/tinyimagenet/val/'
val_dict = {}
with open('./datasets/tinyimagenet/val/val_annotations.txt', 'r') as f:
for line in f.readlines():
split_line = line.split('\t')
val_dict[split_line[0]] = split_line[1]
paths = glob.glob('./datasets/tinyimagenet/val/images/*')
for path in paths:
file = path.split('/')[-1]
folder = val_dict[file]
if not os.path.exists(target_folder + str(folder)):
os.mkdir(target_folder + str(folder))
os.mkdir(target_folder + str(folder) + '/images')
for path in paths:
file = path.split('/')[-1]
folder = val_dict[file]
dest = target_folder + str(folder) + '/images/'+ str(file)
move(path, dest)
rmdir('./datasets/tinyimagenet/val/images')