From 870164cdebfc9bea23335aa625b0090588df9703 Mon Sep 17 00:00:00 2001 From: Laurent Erignoux Date: Tue, 16 Jan 2024 14:35:00 +0800 Subject: [PATCH] Ensuring input images are multiple of 32 as lower leads to RunTimeError. Updating Readme with more information. --- README.md | 4 +++- src/controlnet_aux/util.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91b0ca6..449a187 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/controlnet_aux/util.py b/src/controlnet_aux/util.py index 79ba7f1..d94c159 100644 --- a/src/controlnet_aux/util.py +++ b/src/controlnet_aux/util.py @@ -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