From 0c457bae8f177b2af01a68edea488e8d898102ed Mon Sep 17 00:00:00 2001 From: isaac-vidas <80056737+isaac-vidas@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:23:11 -0500 Subject: [PATCH] Handle grayscale images in expand2square (#97) --- python/sglang/srt/mm_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/mm_utils.py b/python/sglang/srt/mm_utils.py index 4fdd5eb51..d444ff0b7 100644 --- a/python/sglang/srt/mm_utils.py +++ b/python/sglang/srt/mm_utils.py @@ -163,7 +163,9 @@ def expand2square(pil_img, background_color): width, height = pil_img.size if width == height: return pil_img - elif width > height: + if pil_img.mode == "L": + pil_img = pil_img.convert("RGB") + if width > height: result = Image.new(pil_img.mode, (width, width), background_color) result.paste(pil_img, (0, (width - height) // 2)) return result