fix: split large channel masks to handle cv2.resize 512 limitations (#21947)

Co-authored-by: Jing Qiu <61612323+Laughing-q@users.noreply.github.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
This commit is contained in:
LYUShuai 2025-09-05 14:16:01 +08:00 committed by GitHub
parent d346c132a8
commit e843b4c713
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -244,7 +244,9 @@ def scale_image(masks, im0_shape, ratio_pad=None):
if len(masks.shape) < 2:
raise ValueError(f'"len of masks shape" should be 2 or 3, but got {len(masks.shape)}')
masks = masks[top:bottom, left:right]
masks = cv2.resize(masks, (im0_w, im0_h))
# handle the cv2.resize 512 channels limitation: https://github.com/ultralytics/ultralytics/pull/21947
masks = [cv2.resize(array, (im0_w, im0_h)) for array in np.array_split(masks, masks.shape[-1] // 512 + 1, axis=-1)]
masks = np.concatenate(masks, axis=-1) if len(masks) > 1 else masks[0]
if len(masks.shape) == 2:
masks = masks[:, :, None]