From 84ff1c6c812fe193663b2dea6b6d5f0d61081514 Mon Sep 17 00:00:00 2001 From: Antoine Simoulin Date: Mon, 15 Sep 2025 06:29:07 -0700 Subject: [PATCH 1/3] Fix lint issues --- torchvision/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index 20534dec2f6..74d209594b2 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -359,14 +359,14 @@ def draw_bounding_boxes( f"Number of boxes ({num_boxes}) and labels ({len(labels)}) mismatch. Please specify labels for each box." ) - colors = _parse_colors(colors, num_objects=num_boxes) + colors = _parse_colors(colors, num_objects=num_boxes) # type: ignore[assignment] if label_colors or fill_labels: label_colors = _parse_colors(label_colors if label_colors else "black", num_objects=num_boxes) # type: ignore[assignment] else: label_colors = colors.copy() # type: ignore[assignment] if fill_labels and label_background_colors: - label_background_colors = _parse_colors(label_background_colors, num_objects=num_boxes) + label_background_colors = _parse_colors(label_background_colors, num_objects=num_boxes) # type: ignore[assignment] else: label_background_colors = colors.copy() # type: ignore[assignment] From 84857fb51ebf2234d8b44131fba01e12aca5a61c Mon Sep 17 00:00:00 2001 From: Antoine Simoulin Date: Mon, 15 Sep 2025 06:51:11 -0700 Subject: [PATCH 2/3] fix mypy linting error --- torchvision/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index 74d209594b2..1e26b01a48c 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -404,7 +404,7 @@ def draw_bounding_boxes( if fill_labels: left, top, right, bottom = draw.textbbox((bbox[0] + margin, bbox[1] + margin), label, font=txt_font) draw.rectangle( - (left - box_margin, top - box_margin, right + box_margin, bottom + box_margin), fill=label_bg_color + (left - box_margin, top - box_margin, right + box_margin, bottom + box_margin), fill=label_bg_color # type: ignore[arg-type] ) draw.text((bbox[0] + margin, bbox[1] + margin), label, fill=label_color, font=txt_font) # type: ignore[arg-type] From 7de543d47bdb91ec8d591c02c7c4101dc00d1c45 Mon Sep 17 00:00:00 2001 From: Antoine Simoulin Date: Mon, 15 Sep 2025 07:01:48 -0700 Subject: [PATCH 3/3] fix failing tests --- test/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_utils.py b/test/test_utils.py index afdf6738d2c..46d0d96e997 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -409,7 +409,7 @@ def test_draw_segmentation_masks_errors(device): utils.draw_segmentation_masks(image=img, masks=masks_bad_shape) with pytest.raises(ValueError, match="Number of colors must be equal or larger than the number of objects"): utils.draw_segmentation_masks(image=img, masks=masks, colors=[]) - with pytest.raises(ValueError, match="`colors` must be a tuple or a string, or a list thereof"): + with pytest.raises(ValueError, match="colors must be a tuple or a string, or a list thereof"): bad_colors = np.array(["red", "blue"]) # should be a list utils.draw_segmentation_masks(image=img, masks=masks, colors=bad_colors) with pytest.raises(ValueError, match="If passed as tuple, colors should be an RGB triplet"):