Skip to content

Commit

Permalink
Fix model tiling when one dimension needs only one tile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Gouvine authored and Gabriel Gouvine committed Apr 21, 2021
1 parent 5ac2ff0 commit 091f1a4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
def get_windows(tot_size, chop_size, chop_overlap):
stride = chop_size - chop_overlap
starts = list(range(0, tot_size - chop_overlap, stride))
starts[-1] = min(starts[-1], tot_size - stride)
starts[-1] = min(starts[-1], tot_size - stride) # Right-side
starts[-1] = max(starts[-1], 0) # Left-side, if there's only one element
return starts


Expand All @@ -25,8 +26,9 @@ def chop_and_forward(model, x, scale, chop_size, chop_overlap):
result = torch.zeros(result_shape, device=x.device)
for i, x_s in enumerate(x_starts):
for j, y_s in enumerate(y_starts):
x_e = x_s + chop_size
y_e = y_s + chop_size
# Range (saturated for when only one tile fits)
x_e = min(x_s + chop_size, width)
y_e = min(y_s + chop_size, height)
# Run model on the tile
out = model(x[:, :, x_s:x_e, y_s:y_e])
# Compute margins
Expand Down

0 comments on commit 091f1a4

Please sign in to comment.