fix: guard against overlap >= tile_size in tiled inference

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
cmoyates 2026-03-01 06:27:31 -03:30
parent 57c3aff913
commit 3d330d0e0b
No known key found for this signature in database
GPG Key ID: F65E08480FDC22D2
2 changed files with 10 additions and 0 deletions

View File

@ -27,6 +27,10 @@ def _compute_tile_coords(
Tiles overlap by `overlap` pixels. Last tile is clamped to image boundary.
"""
if overlap >= tile_size:
msg = f"overlap ({overlap}) must be less than tile_size ({tile_size})"
raise ValueError(msg)
if image_size <= tile_size:
return [(0, image_size)]

View File

@ -32,6 +32,12 @@ def model() -> GreenFormer:
class TestTileCoords:
def test_overlap_gte_tile_size_raises(self) -> None:
with pytest.raises(ValueError, match="overlap.*must be less than tile_size"):
_compute_tile_coords(512, 256, 256)
with pytest.raises(ValueError, match="overlap.*must be less than tile_size"):
_compute_tile_coords(512, 256, 300)
def test_single_tile(self) -> None:
coords = _compute_tile_coords(200, 256, 32)
assert coords == [(0, 200)]