def __call__(self, array):
     """
     Args:
         array: the image to generate patches from.
     """
     yield from iter_patch(
         array,
         patch_size=self.patch_size,  # expand to have the channel dim
         start_pos=self.start_pos,
         copy_back=False,
         mode=self.mode,
         **self.pad_opts,
     )
Esempio n. 2
0
    def __call__(self, array: np.ndarray):
        """
        Args:
            array: the image to generate patches from.

        """
        yield from iter_patch(
            array,
            patch_size=self.patch_size,  # type: ignore
            start_pos=self.start_pos,
            copy_back=False,
            mode=self.mode,
            **self.pad_opts,
        )
Esempio n. 3
0
    def __iter__(self):
        worker_info = torch.utils.data.get_worker_info()
        iter_start = 0
        iter_end = len(self.dataset)

        if worker_info is not None:
            # split workload
            per_worker = int(math.ceil((iter_end - iter_start) / float(worker_info.num_workers)))
            worker_id = worker_info.id
            iter_start = iter_start + worker_id * per_worker
            iter_end = min(iter_start + per_worker, iter_end)

        for index in range(iter_start, iter_end):
            arrays = self.dataset[index]

            iters = [iter_patch(a, self.patch_size, self.start_pos, False, self.mode, **self.pad_opts) for a in arrays]

            yield from zip(*iters)
Esempio n. 4
0
    def __iter__(self):
        worker_info = torch.utils.data.get_worker_info()
        iter_start = 0
        iter_end = len(self.data)

        if worker_info is not None:
            # split workload
            per_worker = int(
                math.ceil(
                    (iter_end - iter_start) / float(worker_info.num_workers)))
            worker_id = worker_info.id
            iter_start = iter_start + worker_id * per_worker
            iter_end = min(iter_start + per_worker, iter_end)

        for index in range(iter_start, iter_end):
            img_paths = self.data[index]

            arrays = np.expand_dims(np.stack(
                [self.image_reader(x) for x in img_paths]),
                                    axis=(0, 1))

            #arrays = arrays / 30000.0
            #arrays = (np.log(1 + arrays) - 5.5)/5.5

            # Get mag level of file
            mag_level = get_mag_level(img_paths[0])

            # Preprocessing - 1,1,10,256,256
            arrays[0, 0, 7, :, :] = preprocess(arrays[0, 0, 7, :, :],
                                               mag_level, "C01")
            arrays[0, 0, 8, :, :] = preprocess(arrays[0, 0, 8, :, :],
                                               mag_level, "C02")
            arrays[0, 0, 9, :, :] = preprocess(arrays[0, 0, 9, :, :],
                                               mag_level, "C03")
            arrays[0, 0, :7, :, :] = preprocess(arrays[0, 0, :7, :, :],
                                                mag_level, "C04")

            iters = [
                iter_patch(a, self.patch_size, self.start_pos, False,
                           self.mode) for a in arrays
            ]

            yield from zip(*iters)