-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathreorganize_sunseg.py
62 lines (46 loc) · 3.57 KB
/
reorganize_sunseg.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os, shutil, glob
from tqdm import tqdm
SUN_root = f"{os.getenv('DATASET_PATH')}/SUN-SEG/SUN-Positive/"
SUNSEG_root = f"{os.getenv('DATASET_PATH')}/SUN-SEG/SUN-SEG-Annotation/"
SUN_split_dict = {}
SUNSEG_split_dict = {}
SUNSEG_dataset_dict = {}
image_list = []
# SUN_list = glob.glob(SUN_root + '*/*.jpg')
SUNSEG_test_list = glob.glob(SUNSEG_root + 'Test*/*/GT/*/*.png')
SUNSEG_train_list = glob.glob(SUNSEG_root + 'TrainDataset/GT/*/*.png')
SUNSEG_list = SUNSEG_test_list + SUNSEG_train_list
SUN_list = [os.path.join(SUN_root, name.split('/')[-2].split('_')[0] if len(name.split('/')[-2].split('_')) > 1 else name.split('/')[-2], name.split('/')[-1].replace('.png', '')) for name in SUNSEG_list]
for SUN_path, SUNSEG_path in zip(SUN_list, SUNSEG_list):
"""
@func: Get SUN and SUN-SEG case-to-image structure in a dictionary
"""
SUN_case_name, SUN_image_name = SUN_path.split('/')[-2], SUN_path.split('/')[-1]
SUNSEG_dataset_name, SUNSEG_case_name, SUNSEG_image_name = SUNSEG_path.split('SUN-SEG-Annotation/')[1].split('/GT')[0], SUNSEG_path.split('/')[-2], SUNSEG_path.split('/')[-1].rstrip('.png')
SUN_split_dict[SUN_image_name] = SUN_case_name
SUNSEG_split_dict[SUNSEG_image_name] = SUNSEG_case_name
SUNSEG_dataset_dict[SUNSEG_image_name] = SUNSEG_dataset_name
image_list.append(SUN_image_name)
for image in tqdm(image_list):
"""
@func: Change original SUN's structure
"""
SUN_case = SUN_split_dict[image]
SUNSEG_case = SUNSEG_split_dict[image]
dataset_split = SUNSEG_dataset_dict[image]
os.makedirs(os.path.join(SUNSEG_root, dataset_split, 'Frame', SUNSEG_case), exist_ok=True)
shutil.move(os.path.join(SUN_root, SUN_case, image + '.jpg'),
os.path.join(SUNSEG_root, dataset_split, 'Frame', SUNSEG_case, image + '.jpg'))
# combine Seen/Unseen to same directory
os.makedirs(os.path.join(os.getenv('DATASET_PATH'), 'SUN-SEG/SUN-SEG-Annotation', 'TestEasyDataset', 'combine/Frame'), exist_ok=True)
os.makedirs(os.path.join(os.getenv('DATASET_PATH'), 'SUN-SEG/SUN-SEG-Annotation', 'TestEasyDataset', 'combine/GT'), exist_ok=True)
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/Seen/Frame/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/combine/Frame/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/Unseen/Frame/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/combine/Frame/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/Seen/GT/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/combine/GT/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/Unseen/GT/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestEasyDataset/combine/GT/')
os.makedirs(os.path.join(os.getenv('DATASET_PATH'), 'SUN-SEG/SUN-SEG-Annotation', 'TestHardDataset', 'combine/Frame'), exist_ok=True)
os.makedirs(os.path.join(os.getenv('DATASET_PATH'), 'SUN-SEG/SUN-SEG-Annotation', 'TestHardDataset', 'combine/GT'), exist_ok=True)
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/Seen/Frame/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/combine/Frame/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/Unseen/Frame/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/combine/Frame/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/Seen/GT/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/combine/GT/')
os.system('mv $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/Unseen/GT/* $DATASET_PATH/SUN-SEG/SUN-SEG-Annotation/TestHardDataset/combine/GT/')