(
path: Path,
shape: tuple[int, int] | None,
)
| 25 | |
| 26 | |
| 27 | def load_image( |
| 28 | path: Path, |
| 29 | shape: tuple[int, int] | None, |
| 30 | ) -> tuple[ |
| 31 | Float[Tensor, "3 height width"], # image |
| 32 | tuple[int, int], # image shape after scaling, before cropping |
| 33 | ]: |
| 34 | image = Image.open(path) |
| 35 | if shape is None: |
| 36 | pre_crop_shape = (image.height, image.width) |
| 37 | else: |
| 38 | image, pre_crop_shape = resize_to_cover(image, shape) |
| 39 | return tf.ToTensor()(image)[:3], pre_crop_shape |
| 40 | |
| 41 | |
| 42 | @dataclass |
no test coverage detected