Skip to content

Commit

Permalink
can striding be removed? (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Interpause committed Jan 31, 2023
1 parent 39924c1 commit 2358931
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def b64_to_img(enc: str):


def sddebz_highres_fix(
base_size: int, max_size: int, orig_width: int, orig_height: int, just_stride=False
base_size: int,
max_size: int,
orig_width: int,
orig_height: int,
just_stride=False,
stride=1,
):
"""Calculate an appropiate image resolution given the base input size of the
model and max input size allowed.
Expand Down Expand Up @@ -198,15 +203,18 @@ def sddebz_highres_fix(
Tuple[int, int]: Appropiate (width, height) to use for the model.
"""

def rnd(r, x, z=64):
def rnd(r, x):
"""Scale dimension x with stride z while attempting to preserve aspect ratio r."""
return z * ceil(r * x / z)
return stride * ceil(r * x / stride)

ratio = orig_width / orig_height

# don't apply correction; just stride to 64
# don't apply correction; just stride
if just_stride:
width, height = ceil(orig_width / 64) * 64, ceil(orig_height / 64) * 64
width, height = (
ceil(orig_width / stride) * stride,
ceil(orig_height / stride) * stride,
)
# height is smaller dimension
elif orig_width > orig_height:
width, height = rnd(ratio, base_size), base_size
Expand Down

0 comments on commit 2358931

Please sign in to comment.