Пример #1
0
    def __getitem__(self, index):
        img = ImageHelper.read_image(
            self.img_list[index],
            tool=self.configer.get('data', 'image_tool'),
            mode=self.configer.get('data', 'input_mode'))
        img_size = ImageHelper.get_size(img)
        labelmap = ImageHelper.read_image(self.label_list[index],
                                          tool=self.configer.get(
                                              'data', 'image_tool'),
                                          mode='P')
        edgemap = ImageHelper.read_image(self.edge_list[index],
                                         tool=self.configer.get(
                                             'data', 'image_tool'),
                                         mode='P')

        edgemap[edgemap == 255] = 1
        edgemap = cv2.resize(edgemap, (labelmap.shape[-1], labelmap.shape[-2]),
                             interpolation=cv2.INTER_NEAREST)

        if self.configer.exists('data', 'label_list'):
            labelmap = self._encode_label(labelmap)

        if self.configer.exists('data',
                                'reduce_zero_label') and self.configer.get(
                                    'data', 'reduce_zero_label') == 'True':
            labelmap = self._reduce_zero_label(labelmap)

        ori_target = ImageHelper.tonp(labelmap)
        ori_target[ori_target == 255] = -1

        if self.aug_transform is not None:
            img, labelmap, edgemap = self.aug_transform(img,
                                                        labelmap=labelmap,
                                                        maskmap=edgemap)

        border_size = ImageHelper.get_size(img)

        if self.img_transform is not None:
            img = self.img_transform(img)

        if self.label_transform is not None:
            labelmap = self.label_transform(labelmap)
            edgemap = self.label_transform(edgemap)

        meta = dict(ori_img_size=img_size,
                    border_size=border_size,
                    ori_target=ori_target)
        return dict(
            img=DataContainer(img, stack=True),
            labelmap=DataContainer(labelmap, stack=True),
            maskmap=DataContainer(edgemap, stack=True),
            meta=DataContainer(meta, stack=False, cpu_only=True),
            name=DataContainer(self.name_list[index],
                               stack=False,
                               cpu_only=True),
        )
Пример #2
0
    def __getitem__(self, index):
        img = ImageHelper.read_image(
            self.img_list[index],
            tool=self.configer.get('data', 'image_tool'),
            mode=self.configer.get('data', 'input_mode'))
        img_size = ImageHelper.get_size(img)
        labelmap = ImageHelper.read_image(self.label_list[index],
                                          tool=self.configer.get(
                                              'data', 'image_tool'),
                                          mode='P')
        if self.configer.exists('data', 'label_list'):
            labelmap = self._encode_label(labelmap)

        if self.configer.exists('data', 'reduce_zero_label'):
            labelmap = self._reduce_zero_label(labelmap)

        ori_target = ImageHelper.tonp(labelmap)
        ori_target[ori_target == 255] = -1
        ori_img = ImageHelper.tonp(img)

        if self.aug_transform is not None:
            img, labelmap = self.aug_transform(img, labelmap=labelmap)

        border_size = ImageHelper.get_size(img)

        if self.img_transform is not None:
            img = self.img_transform(img)

        if self.label_transform is not None:
            labelmap = self.label_transform(labelmap)

        meta = dict(ori_img_size=img_size,
                    border_size=border_size,
                    ori_target=ori_target,
                    ori_img=ori_img)
        return dict(
            img=DataContainer(img, stack=self.is_stack),
            labelmap=DataContainer(labelmap, stack=self.is_stack),
            meta=DataContainer(meta, stack=False, cpu_only=True),
            name=DataContainer(self.name_list[index],
                               stack=False,
                               cpu_only=True),
        )
Пример #3
0
    def __getitem__(self, index):
        img = ImageHelper.read_image(
            self.img_list[index],
            tool=self.configer.get('data', 'image_tool'),
            mode=self.configer.get('data', 'input_mode'))
        img_size = ImageHelper.get_size(img)
        labelmap = ImageHelper.read_image(self.label_list[index],
                                          tool=self.configer.get(
                                              'data', 'image_tool'),
                                          mode='P')
        if self.configer.exists('data', 'label_list'):
            labelmap = self._encode_label(labelmap)
        distance_map, angle_map = self._load_maps(self.offset_list[index],
                                                  labelmap)

        if self.configer.exists('data',
                                'reduce_zero_label') and self.configer.get(
                                    'data', 'reduce_zero_label') == True:
            labelmap = self._reduce_zero_label(labelmap)

        ori_target = ImageHelper.tonp(labelmap).astype(np.int)
        ori_target[ori_target == 255] = -1
        ori_distance_map = np.array(distance_map)
        ori_angle_map = np.array(angle_map)

        if self.aug_transform is not None:
            img, labelmap, distance_map, angle_map = self.aug_transform(
                img,
                labelmap=labelmap,
                distance_map=distance_map,
                angle_map=angle_map)

        old_img = img
        border_size = ImageHelper.get_size(img)

        if self.img_transform is not None:
            img = self.img_transform(img)

        if self.label_transform is not None:
            labelmap = self.label_transform(labelmap)
            distance_map = torch.from_numpy(distance_map)
            angle_map = torch.from_numpy(angle_map)

        if set(self.configer.get('val_trans', 'trans_seq')) & set(
            ['random_crop', 'crop']):
            ori_target = labelmap.numpy()
            ori_distance_map = distance_map.numpy()
            ori_angle_map = angle_map.numpy()
            img_size = ori_target.shape[:2][::-1]

        meta = dict(ori_img_size=img_size,
                    border_size=border_size,
                    ori_target=ori_target,
                    ori_distance_map=ori_distance_map,
                    ori_angle_map=ori_angle_map,
                    basename=os.path.basename(self.label_list[index]))

        return dict(
            img=DataContainer(img, stack=self.is_stack),
            labelmap=DataContainer(labelmap, stack=self.is_stack),
            distance_map=DataContainer(distance_map, stack=self.is_stack),
            angle_map=DataContainer(angle_map, stack=self.is_stack),
            meta=DataContainer(meta, stack=False, cpu_only=True),
            name=DataContainer(self.name_list[index],
                               stack=False,
                               cpu_only=True),
        )
Пример #4
0
    def __getitem__(self, index):
        img = ImageHelper.read_image(
            self.img_list[index],
            tool=self.configer.get('data', 'image_tool'),
            mode=self.configer.get('data', 'input_mode'))
        img_size = ImageHelper.get_size(img)
        labelmap = ImageHelper.read_image(self.label_list[index],
                                          tool=self.configer.get(
                                              'data', 'image_tool'),
                                          mode='P')
        offsetmap_h = self._load_mat(self.offset_h_list[index])
        offsetmap_w = self._load_mat(self.offset_w_list[index])

        if os.environ.get('train_no_offset') and self.dataset == 'train':
            offsetmap_h = np.zeros_like(offsetmap_h)
            offsetmap_w = np.zeros_like(offsetmap_w)

        if self.configer.exists('data', 'label_list'):
            labelmap = self._encode_label(labelmap)

        if self.configer.exists('data',
                                'reduce_zero_label') and self.configer.get(
                                    'data', 'reduce_zero_label') == True:
            labelmap = self._reduce_zero_label(labelmap)

        # Log.info('use dataset {}'.format(self.configer.get('dataset')))
        ori_target = ImageHelper.tonp(labelmap).astype(np.int)
        ori_target[ori_target == 255] = -1
        ori_offset_h = np.array(offsetmap_h)
        ori_offset_w = np.array(offsetmap_w)

        if self.aug_transform is not None:
            img, labelmap, offsetmap_h, offsetmap_w = self.aug_transform(
                img,
                labelmap=labelmap,
                offset_h_map=offsetmap_h,
                offset_w_map=offsetmap_w)

        border_size = ImageHelper.get_size(img)

        if self.img_transform is not None:
            img = self.img_transform(img)

        if self.label_transform is not None:
            labelmap = self.label_transform(labelmap)
            offsetmap_h = torch.from_numpy(np.array(offsetmap_h)).long()
            offsetmap_w = torch.from_numpy(np.array(offsetmap_w)).long()

        meta = dict(
            ori_img_size=img_size,
            border_size=border_size,
            ori_target=ori_target,
            ori_offset_h=ori_offset_h,
            ori_offset_w=ori_offset_w,
        )

        return dict(
            img=DataContainer(img, stack=self.is_stack),
            labelmap=DataContainer(labelmap, stack=self.is_stack),
            offsetmap_h=DataContainer(offsetmap_h, stack=self.is_stack),
            offsetmap_w=DataContainer(offsetmap_w, stack=self.is_stack),
            meta=DataContainer(meta, stack=False, cpu_only=True),
            name=DataContainer(self.name_list[index],
                               stack=False,
                               cpu_only=True),
        )