-
Notifications
You must be signed in to change notification settings - Fork 3
/
subset_objectnet_im.py
36 lines (29 loc) · 1.4 KB
/
subset_objectnet_im.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
import os
import json
import shutil
import argparse
from tqdm import tqdm
def create_subset(args):
dirname = 'Objectnet/val'
os.makedirs(os.path.join(args.im100_root, dirname), exist_ok = True)
with open(args.folder_to_label, 'r') as f:
folder_to_label = json.load(f)
label_to_folder = {v:k for k,v in folder_to_label.items()}
with open(args.objectnet_to_im100_folder, 'r') as f:
objectnet_to_im100_folder = json.load(f)
for label in tqdm(objectnet_to_im100_folder):
folder_name = label_to_folder[label]
images = os.listdir(os.path.join(args.objectnet_root, folder_name))
im100_folder_name = objectnet_to_im100_folder[label]
os.makedirs(os.path.join(args.im100_root, dirname, im100_folder_name), exist_ok = True)
print(im100_folder_name)
for image in images:
shutil.copy(os.path.join(args.objectnet_root, folder_name, image), os.path.join(args.im100_root, dirname, im100_folder_name))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='ImageNetV2 Rename')
parser.add_argument('--objectnet_root', type=str, default=None)
parser.add_argument('--im100_root', type=str, default=None)
parser.add_argument('--folder_to_label', type=str, default=None)
parser.add_argument('--objectnet_to_im100_folder', type=str, default=None)
args = parser.parse_args()
create_subset(args)