Beispiel #1
0
    def gen(self, au=True, crop_size=64, iteration=None):

        while True:
            data_yield = [
                self.index % self.n, (self.index + self.step) % self.n if
                (self.index + self.step) < self.n else self.n
            ]
            self.index = (self.index + self.step) % self.n

            list_images_base = self.list_images_all[
                data_yield[0]:data_yield[1]]
            list_gt_base = self.list_gt_all[data_yield[0]:data_yield[1]]

            list_images_base = pre_processing.my_PreProc(
                list_images_base)  # 图片增强预处理

            list_images_aug = []
            list_gt_aug = []
            for image, gt in zip(list_images_base, list_gt_base):
                if au:
                    if crop_size == prepare_dataset.DESIRED_DATA_SHAPE[0]:
                        for _ in range(self.repeat):
                            image, gt = data_augmentation.random_augmentation(
                                image, gt)
                            list_images_aug.append(image)
                            list_gt_aug.append(gt)
                    else:
                        image, gt = data_augmentation.random_augmentation(
                            image, gt)
                        list_images_aug.append(image)
                        list_gt_aug.append(gt)
                else:
                    list_images_aug.append(image)
                    list_gt_aug.append(gt)

            list_images = []
            list_gt = []

            if crop_size == prepare_dataset.DESIRED_DATA_SHAPE[0]:
                list_images = list_images_aug
                list_gt = list_gt_aug
            else:
                for image, gt in zip(list_images_aug, list_gt_aug):
                    for _ in range(self.repeat):
                        image_, gt_ = random_crop(image, gt, crop_size)

                        list_images.append(image_)
                        list_gt.append(gt_)
            outs = {}
            for iteration_id in range(iteration):
                outs.update({f'out1{iteration_id + 1}': np.array(list_gt)})
            outs.update({'final_out': np.array(list_gt)})

            yield np.array(list_images), outs
Beispiel #2
0
    def gen(self, au=True, crop_size=48, iteration=None):

        while True:
            data_yield = [self.index % self.n,
                          (self.index + self.step) % self.n if (self.index + self.step) < self.n else self.n]
            self.index = (self.index + self.step) % self.n

            list_images_base = self.list_images_all[data_yield[0]:data_yield[1]]
            list_gt_base = self.list_gt_all[data_yield[0]:data_yield[1]]
            list_gt_onehot_base = self.list_gt_all_onehot[data_yield[0]:data_yield[1]]

            list_images_aug = []
            list_gt_aug = []
            list_gt_onehot_aug = []
            image_id = -1
            for image, gt in zip(list_images_base, list_gt_base):
                image_id += 1
                gt2 = list_gt_onehot_base[image_id]
                if au:
                    if crop_size == prepare_dataset.DESIRED_DATA_SHAPE[0]:
                        for _ in range(self.repeat):
                            image, gt, gt2 = data_augmentation.random_augmentation(image, gt, gt2)
                            list_images_aug.append(image)
                            list_gt_aug.append(gt)
                            list_gt_onehot_aug.append(gt2)
                    else:
                        image, gt, gt2 = data_augmentation.random_augmentation(image, gt, gt2)
                        list_images_aug.append(image)
                        list_gt_aug.append(gt)
                        list_gt_onehot_aug.append(gt2)
                else:
                    list_images_aug.append(image)
                    list_gt_aug.append(gt)
                    list_gt_onehot_aug.append(gt2)

            list_images = []
            list_gt = []
            list_gt_onehot = []
            image_id = -1
            if crop_size == prepare_dataset.DESIRED_DATA_SHAPE[0]:
                list_images = list_images_aug
                list_gt = list_gt_aug
                list_gt_onehot = list_gt_onehot_aug
            else:
                for image, gt in zip(list_images_aug, list_gt_aug):
                    image_id += 1
                    for _ in range(self.repeat):
                        image_, gt_, gt_onehot_ = random_crop(image, gt, list_gt_onehot_aug[image_id], crop_size)

                        list_images.append(image_)
                        list_gt.append(gt_)
                        list_gt_onehot.append(gt_onehot_)

            outs = {}
            for iteration_id in range(iteration):
                outs.update({f'out1{iteration_id + 1}': np.array(list_gt)[:,0]})
            outs.update({'seg_final_out': np.array(list_gt)[:,0]})
            # outs.update({'crossing_final_out': np.array(list_gt)[:,1]})
            outs.update({'cls_art_final_out': np.array(list_gt)[:,2]})
            outs.update({'cls_vei_final_out': np.array(list_gt)[:,3]})
            for iteration_id in range(iteration):
                outs.update({f'out1_cls_art{iteration_id + 1}': np.array(list_gt)[:,2]})
            for iteration_id in range(iteration):
                outs.update({f'out1_cls_vei{iteration_id + 1}': np.array(list_gt)[:,3]})
            yield np.array(list_images), outs