예제 #1
0
    def __getitem__(self, index):
        if self.image_source == 'memory':
            load_func = self.load_from_memory
        elif self.image_source == 'disk':
            load_func = self.load_from_disk
        else:
            raise NotImplementedError(
                "Possible loading options: 'memory' and 'disk'!")

        Xi = load_func(self.X, index, filetype='png', grayscale=False)

        if self.y is not None:
            Mi = self.load_target(self.y, index, load_func)
            Xi, *Mi = from_pil(Xi, *Mi)
            Xi, *Mi = self.image_augment_with_target(Xi, *Mi)
            Xi = self.image_augment(Xi)
            Xi, *Mi = to_pil(Xi, *Mi)

            if self.mask_transform is not None:
                Mi = [self.mask_transform(m) for m in Mi]

            if self.image_transform is not None:
                Xi = self.image_transform(Xi)

            Mi = torch.cat(Mi, dim=0)
            return Xi, Mi
        else:
            Xi = from_pil(Xi)
            Xi = self.image_augment(Xi)
            Xi = to_pil(Xi)

            if self.image_transform is not None:
                Xi = self.image_transform(Xi)
            return Xi
예제 #2
0
    def __getitem__(self, index):
        if self.image_source == 'memory':
            load_func = self.load_from_memory
        elif self.image_source == 'disk':
            load_func = self.load_from_disk
        else:
            raise NotImplementedError(
                "Possible loading options: 'memory' and 'disk'!")

        Xi = load_func(self.X, index, filetype='png', grayscale=False)
        Xi = from_pil(Xi)

        if self.image_augment is not None:
            Xi = self.image_augment(Xi)

        if self.tta_params is not None:
            tta_transform_specs = self.tta_params[index]
            Xi = self.tta_transform(Xi, tta_transform_specs)
        Xi = to_pil(Xi)

        if self.image_transform is not None:
            Xi = self.image_transform(Xi)

        return Xi
예제 #3
0
 def read_json(self, path):
     with open(path, 'r') as file:
         data = json.load(file)
     masks = [to_pil(binary_from_rle(rle)) for rle in data]
     return masks
예제 #4
0
 def load_target(self, data_source, index, load_func):
     Mi = load_func(data_source, index, filetype='png', grayscale=True)
     Mi = from_pil(Mi)
     target = [to_pil(Mi == class_nr) for class_nr in [0, 1]]
     return target