Merge pull request #1426 from sdbds/resize

Replacing CV2 resize to Pil resize
This commit is contained in:
Kohya S.
2024-09-07 10:22:52 +09:00
committed by GitHub
5 changed files with 36 additions and 15 deletions

View File

@@ -71,7 +71,7 @@ import library.model_util as model_util
import library.huggingface_util as huggingface_util
import library.sai_model_spec as sai_model_spec
import library.deepspeed_utils as deepspeed_utils
from library.utils import setup_logging
from library.utils import setup_logging, pil_resize
setup_logging()
import logging
@@ -2094,9 +2094,7 @@ class ControlNetDataset(BaseDataset):
# ), f"image size is small / 画像サイズが小さいようです: {image_info.absolute_path}"
# resize to target
if cond_img.shape[0] != target_size_hw[0] or cond_img.shape[1] != target_size_hw[1]:
cond_img = cv2.resize(
cond_img, (int(target_size_hw[1]), int(target_size_hw[0])), interpolation=cv2.INTER_LANCZOS4
)
cond_img=pil_resize(cond_img,(int(target_size_hw[1]), int(target_size_hw[0])))
if flipped:
cond_img = cond_img[:, ::-1, :].copy() # copy to avoid negative stride
@@ -2459,7 +2457,10 @@ def trim_and_resize_if_required(
if image_width != resized_size[0] or image_height != resized_size[1]:
# リサイズする
image = cv2.resize(image, resized_size, interpolation=cv2.INTER_AREA) # INTER_AREAでやりたいのでcv2でリサイズ
if image_width > resized_size[0] and image_height > resized_size[1]:
image = cv2.resize(image, resized_size, interpolation=cv2.INTER_AREA) # INTER_AREAでやりたいのでcv2でリサイズ
else:
image = pil_resize(image, resized_size)
image_height, image_width = image.shape[0:2]