-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
sbushadow.py
43 lines (41 loc) · 1.72 KB
/
sbushadow.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
'''
Function:
Implementation of SBUShadowDataset
Author:
Zhenchao Jin
'''
import os
from .base import BaseDataset
'''SBUShadowDataset'''
class SBUShadowDataset(BaseDataset):
num_classes = 2
classnames = ['__backgroud__', 'shadow']
palette = [(0, 0, 0), (255, 0, 0)]
assert num_classes == len(classnames) and num_classes == len(palette)
def __init__(self, mode, logger_handle, dataset_cfg):
super(SBUShadowDataset, self).__init__(mode=mode, logger_handle=logger_handle, dataset_cfg=dataset_cfg)
# obtain the dirs
rootdir = dataset_cfg['rootdir']
setmap_dict = {'train': 'SBUTrain4KRecoveredSmall', 'val': 'SBU-Test'}
self.image_dir = os.path.join(rootdir, setmap_dict[dataset_cfg['set']], 'ShadowImages')
self.ann_dir = os.path.join(rootdir, setmap_dict[dataset_cfg['set']], 'ShadowMasks')
# obatin imageids
self.imageids = []
for line in open(os.path.join(rootdir, dataset_cfg['set']+'.txt'), 'r').readlines():
if line.strip(): self.imageids.append(line.strip())
self.imageids = [str(_id) for _id in self.imageids]
'''getitem'''
def __getitem__(self, index):
# imageid
imageid = self.imageids[index % len(self.imageids)]
# read sample_meta
imagepath = os.path.join(self.image_dir, f'{imageid}{self.image_ext}')
annpath = os.path.join(self.ann_dir, f'{imageid}{self.ann_ext}')
sample_meta = self.read(imagepath, annpath)
sample_meta['seg_target'][sample_meta['seg_target'] > 0] = 1.
# add image id
sample_meta.update({'id': imageid})
# synctransforms
sample_meta = self.synctransforms(sample_meta)
# return
return sample_meta