def __getitem__(self, idx):
    image_path = os.path.join(self.root_dir, self.list_sample[idx]['fpath_img'])
    img = Image.open(image_path).convert('RGB')
    r = self.list_sample[idx]['height']
    c = self.list_sample[idx]['width']
    name = self.list_sample[idx]['fpath_img'].replace('ADEChallengeData2016/images/', '')
    if (self.period == 'train'):
        name = name.replace('train/', '')
    if ('val' in self.period):
        name = name.replace('validation/', '')
    assert (self.period != 'test')
    name = name.replace('.jpg', '')
    sample = {'image': img, 'name': name, 'row': r, 'col': c}
    if ((self.period == 'train') or (self.period == 'val')):
        seg_path = os.path.join(self.root_dir, self.list_sample[idx]['fpath_segm'])
        seg = Image.open(seg_path)
        sample['segmentation'] = seg
        assert (img.size[0] == seg.size[0])
        assert (img.size[1] == seg.size[1])
    if (self.transform is not None):
        (img, target) = self.transform(img, seg)
    return (img, target)
def __getitem__(self, idx):
    image_path = os.path.join(self.root_dir, self.list_sample[idx]['fpath_img'])
    img = Image.open(image_path).convert('RGB')
    r = self.list_sample[idx]['height']
    c = self.list_sample[idx]['width']
    name = self.list_sample[idx]['fpath_img'].replace('ADEChallengeData2016/images/', )
    if (self.period == 'train'):
        name = name.replace('train/', )
    if ('val' in self.period):
        name = name.replace('validation/', )
    assert (self.period != 'test')
    name = name.replace('.jpg', )
    sample = {'image': img, 'name': name, 'row': r, 'col': c}
    if ((self.period == 'train') or (self.period == 'val')):
        seg_path = os.path.join(self.root_dir, self.list_sample[idx]['fpath_segm'])
        seg = Image.open(seg_path)
        sample['segmentation'] = seg
        assert (img.size[0] == seg.size[0])
        assert (img.size[1] == seg.size[1])
    if (self.transform is not None):
        (img, target) = self.transform(img, seg)
    return (img, target)