Skip to content

Commit 870164c

Browse files
author
Laurent Erignoux
committed
Ensuring input images are multiple of 32 as lower leads to RunTimeError. Updating Readme with more information.
1 parent f283457 commit 870164c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ processed_image_dwpose = dwpose(img)
113113

114114
### Image resolution
115115

116-
In order to maintain the image aspect ratio, `detect_resolution`, `image_resolution` and images sizes need to be using multiple of `64`.
116+
In order to maintain the image aspect ratio, `detect_resolution`, `image_resolution` and calls to `resize_image` need to be using multiple of `32`.
117+
Otherwise images will be resized to work correctly.
118+
Resolution can be set to `None` to prevent resize. This may lead to RunTimeError.

src/controlnet_aux/util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def resize_image(input_image, resolution):
9191
k = float(resolution) / min(H, W)
9292
H *= k
9393
W *= k
94-
H = int(np.round(H / 64.0)) * 64
95-
W = int(np.round(W / 64.0)) * 64
94+
# We ensure image size is multiple of 32. If not this leads to RuntimeError:
95+
# The size of tensor a (X) must match the size of tensor b (Y) at non-singleton dimension Z
96+
H = int(np.round(H / 32.0)) * 32
97+
W = int(np.round(W / 32.0)) * 32
9698
img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
9799
return img
98100

0 commit comments

Comments
 (0)