code: def test_detection_dataset(mock_image_folder, mock_detection_label):
      input_size = (1024, 1024)
  
      ds = datasets.DetectionDataset(
          img_folder=mock_image_folder,
          label_path=mock_detection_label,
          img_transforms=Resize(input_size),
      )
  
      assert len(ds) == 5
      img, target_dict = ds[0]
      target = target_dict[CLASS_NAME]
      assert isinstance(img, tf.Tensor)
      assert img.shape[:2] == input_size
      assert img.dtype == tf.float32
      # Bounding boxes
      assert isinstance(target_dict, dict)
      assert (
          isinstance(target, np.ndarray) and target.dtype == np.float32
      )
      assert np.all(
          np.logical_and(target[:, :4] >= 0, target[:, :4] <= 1)
      )
      assert target.shape[1] == 4
  
      loader = DataLoader(ds, batch_size=2)
      images, targets = next(iter(loader))
      assert isinstance(images, tf.Tensor) and images.shape == (
          2,
          *input_size,
          3,
      )
      assert isinstance(targets, list) and all(
          isinstance(elt, np.ndarray)
          for target in targets
          for elt in target.values()
      )
  
      # Rotated DS
      rotated_ds = datasets.DetectionDataset(
          img_folder=mock_image_folder,
          label_path=mock_detection_label,
          img_transforms=Resize(input_size),
          use_polygons=True,
      )
      _, r_target = rotated_ds[0]
      assert r_target[CLASS_NAME].shape[1:] == (4, 2)
  
      # File existence check
      img_name, _ = ds.data[0]
      move(
          os.path.join(ds.root, img_name),
          os.path.join(ds.root, "tmp_file"),
      )
      with pytest.raises(FileNotFoundError):
          datasets.DetectionDataset(
              mock_image_folder, mock_detection_label
          )
      move(
          os.path.join(ds.root, "tmp_file"),
          os.path.join(ds.root, img_name),
      )
  
imports: import os
  from shutil import move
  import numpy
  import pytest
  import tensorflow
  from doctr import datasets
  from doctr.datasets import DataLoader
  from doctr.file_utils import CLASS_NAME
  from doctr.transforms import Resize
label_desc: Use image node_id 4 for calling a global function with example usage: test_detection_dataset(mock_image_folder, mock_detection_label) without return types