Skip to content

Commit

Permalink
Fixed inconsistency vs tensor impl
Browse files Browse the repository at this point in the history
  • Loading branch information
vfdev-5 committed Jan 17, 2024
1 parent 11428ca commit 59e7d7d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions torchvision/transforms/v2/functional/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,15 @@ def _compute_affine_output_size_python(matrix: List[float], w: int, h: int) -> T
min_val_y = min(new_pts_y) + half_h
max_val_y = max(new_pts_y) + half_h

# Truncate precision to 1e-4 to avoid ceil of Xe-15 to 1.0
# Truncate precision to 1e-4 to avoid ceil of Xe-15 to 1.0 instead of 0.0
# Adding +1 in int(min_val * inv_tol + 1) to avoid floor of X.9999 to X instead of X+1
tol = 1e-4
inv_tol = 1.0 / tol

cmax_x = math.ceil(int(max_val_x * inv_tol) * tol)
cmax_y = math.ceil(int(max_val_y * inv_tol) * tol)
cmin_x = math.floor(int(min_val_x * inv_tol) * tol)
cmin_y = math.floor(int(min_val_y * inv_tol) * tol)
cmin_x = math.floor(int(min_val_x * inv_tol + 1) * tol)
cmin_y = math.floor(int(min_val_y * inv_tol + 1) * tol)

size_x = cmax_x - cmin_x
size_y = cmax_y - cmin_y
Expand Down

0 comments on commit 59e7d7d

Please sign in to comment.