Args: data: an image dataset to extract patches from. patch_func: converts an input image (item from dataset) into a sequence of image patches. patch_func(dataset[idx]) must return a sequence of patches (length `samples_per_image`). sample
(
self, data: Sequence, patch_func: Callable, samples_per_image: int = 1, transform: Callable | None = None
)
| 405 | """ |
| 406 | |
| 407 | def __init__( |
| 408 | self, data: Sequence, patch_func: Callable, samples_per_image: int = 1, transform: Callable | None = None |
| 409 | ) -> None: |
| 410 | """ |
| 411 | Args: |
| 412 | data: an image dataset to extract patches from. |
| 413 | patch_func: converts an input image (item from dataset) into a sequence of image patches. |
| 414 | patch_func(dataset[idx]) must return a sequence of patches (length `samples_per_image`). |
| 415 | samples_per_image: `patch_func` should return a sequence of `samples_per_image` elements. |
| 416 | transform: transform applied to each patch. |
| 417 | """ |
| 418 | super().__init__(data=data, transform=None) |
| 419 | |
| 420 | self.patch_func = patch_func |
| 421 | if samples_per_image <= 0: |
| 422 | raise ValueError("sampler_per_image must be a positive integer.") |
| 423 | self.samples_per_image = int(samples_per_image) |
| 424 | self.patch_transform = transform |
| 425 | |
| 426 | def __len__(self) -> int: |
| 427 | return len(self.data) * self.samples_per_image # type: ignore |