code: def test_draw_segmentation_masks(colors, alpha, device):
      """This test makes sure that masks draw their corresponding color where they should"""
      num_masks, h, w = 2, 100, 100
      dtype = torch.uint8
      img = torch.randint(
          0, 256, size=(3, h, w), dtype=dtype, device=device
      )
      masks = torch.randint(
          0, 2, (num_masks, h, w), dtype=torch.bool, device=device
      )
  
      # For testing we enforce that there's no overlap between the masks. The
      # current behaviour is that the last mask's color will take priority when
      # masks overlap, but this makes testing slightly harder, so we don't really
      # care
      overlap = masks[0] & masks[1]
      masks[:, overlap] = False
  
      out = utils.draw_segmentation_masks(
          img, masks, colors=colors, alpha=alpha
      )
      assert out.dtype == dtype
      assert out is not img
  
      # Make sure the image didn't change where there's no mask
      masked_pixels = masks[0] | masks[1]
      assert_equal(img[:, ~masked_pixels], out[:, ~masked_pixels])
  
      if colors is None:
          colors = utils._generate_color_palette(num_masks)
      elif isinstance(colors, str) or isinstance(colors, tuple):
          colors = [colors]
  
      # Make sure each mask draws with its own color
      for mask, color in zip(masks, colors):
          if isinstance(color, str):
              color = ImageColor.getrgb(color)
          color = torch.tensor(color, dtype=dtype, device=device)
  
          if alpha == 1:
              assert (out[:, mask] == color[:, None]).all()
          elif alpha == 0:
              assert (out[:, mask] == img[:, mask]).all()
  
          interpolated_color = (
              img[:, mask] * (1 - alpha) + color[:, None] * alpha
          ).to(dtype)
          torch.testing.assert_close(
              out[:, mask], interpolated_color, rtol=0.0, atol=1.0
          )
  
imports: import os
  import re
  import sys
  import tempfile
  from io import BytesIO
  import numpy
  import pytest
  import torch
  import torchvision.transforms.functional
  import torchvision.utils
  from common_utils import assert_equal, cpu_and_cuda
  from PIL import __version__, Image, ImageColor
  from torchvision.transforms.v2.functional import to_dtype
label_desc: Use image node_id 14 for calling a global function with example usage: test_draw_segmentation_masks(colors, alpha, device) without return types