(
original_shape: tuple[int, int],
cfg: CroppingCfg,
)
| 80 | |
| 81 | |
| 82 | def get_image_shape( |
| 83 | original_shape: tuple[int, int], |
| 84 | cfg: CroppingCfg, |
| 85 | ) -> tuple[int, int]: |
| 86 | # If the image shape is exact, return it. |
| 87 | if isinstance(cfg.image_shape, tuple): |
| 88 | return cfg.image_shape |
| 89 | |
| 90 | # Otherwise, the image shape is assumed to be an approximate number of pixels. |
| 91 | h, w = original_shape |
| 92 | scale = (cfg.image_shape / (h * w)) ** 0.5 |
| 93 | return (round(h * scale), round(w * scale)) |
| 94 | |
| 95 | |
| 96 | def crop_and_resize_batch_for_model( |
no outgoing calls
no test coverage detected