Skip to content

Commit

Permalink
Ensuring input images are multiple of 32 as lower leads to RunTimeErr…
Browse files Browse the repository at this point in the history
…or. Updating Readme with more information.
  • Loading branch information
Laurent Erignoux committed Jan 16, 2024
1 parent f1a73cd commit 29169d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ processed_image_dwpose = dwpose(img)

### Image resolution

In order to maintain the image aspect ratio, `detect_resolution`, `image_resolution` and images sizes need to be using multiple of `64`.
In order to maintain the image aspect ratio, `detect_resolution`, `image_resolution` and calls to `resize_image` need to be using multiple of `32`.
Otherwise images will be resized to work correctly.
Resolution can be set to `None` to prevent resize. This may lead to RunTimeError.
6 changes: 4 additions & 2 deletions src/controlnet_aux/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def resize_image(input_image, resolution):
k = float(resolution) / min(H, W)
H *= k
W *= k
H = int(np.round(H / 64.0)) * 64
W = int(np.round(W / 64.0)) * 64
# We ensure image size is multiple of 32. If not this leads to RuntimeError:
# The size of tensor a (X) must match the size of tensor b (Y) at non-singleton dimension Z
H = int(np.round(H / 32.0)) * 32
W = int(np.round(W / 32.0)) * 32
img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
return img

Expand Down

0 comments on commit 29169d2

Please sign in to comment.