code: def make_bounding_boxes(
      canvas_size=DEFAULT_SIZE,
      *,
      format=tv_tensors.BoundingBoxFormat.XYXY,
      num_boxes=1,
      dtype=None,
      device="cpu",
  ):
      def sample_position(values, max_value):
          # We cannot use torch.randint directly here, because it only allows integer scalars as values for low and high.
          # However, if we have batch_dims, we need tensors as limits.
          return torch.stack(
              [
                  torch.randint(max_value - v, ())
                  for v in values.tolist()
              ]
          )
  
      if isinstance(format, str):
          format = tv_tensors.BoundingBoxFormat[format]
  
      dtype = dtype or torch.float32
  
      h, w = [torch.randint(1, s, (num_boxes,)) for s in canvas_size]
      y = sample_position(h, canvas_size[0])
      x = sample_position(w, canvas_size[1])
  
      if format is tv_tensors.BoundingBoxFormat.XYWH:
          parts = (x, y, w, h)
      elif format is tv_tensors.BoundingBoxFormat.XYXY:
          x1, y1 = x, y
          x2 = x1 + w
          y2 = y1 + h
          parts = (x1, y1, x2, y2)
      elif format is tv_tensors.BoundingBoxFormat.CXCYWH:
          cx = x + w / 2
          cy = y + h / 2
          parts = (cx, cy, w, h)
      else:
          raise ValueError(f"Format {format} is not supported")
  
      return tv_tensors.BoundingBoxes(
          torch.stack(parts, dim=-1).to(dtype=dtype, device=device),
          format=format,
          canvas_size=canvas_size,
      )
  
imports: import contextlib
  import functools
  import itertools
  import os
  import pathlib
  import random
  import re
  import shutil
  import sys
  import tempfile
  import warnings
  from subprocess import CalledProcessError, check_output, STDOUT
  import numpy
  import PIL.Image
  import pytest
  import torch
  import torch.testing
  from PIL import Image
  from torch.testing._comparison import BooleanPair, NonePair, not_close_error_metas, NumberPair, TensorLikePair
  from torchvision import io, tv_tensors
  from torchvision.transforms._functional_tensor import _max_value
  from torchvision.transforms.v2.functional import to_image, to_pil_image
label_desc: Use image node_id 26 for calling a global function with example usage: make_bounding_boxes(canvas_size) and returns: tv_tensors, torch