def make_datumaro_dataset(
    root: str | Path,
    split: str | Split | None = None,
) -> pd.DataFrame:
    """Create a DataFrame of image samples from a Datumaro dataset.

    Args:
        root (str | Path): Path to the dataset root directory.
        split (str | Split | None, optional): Dataset split to load. Usually
            ``Split.TRAIN`` or ``Split.TEST``. Defaults to ``None``.

    Returns:
        pd.DataFrame: DataFrame containing samples with columns:
            - ``image_path``: Path to the image file
            - ``label``: Class label name
            - ``label_index``: Numeric label index
            - ``split``: Dataset split
            - ``mask_path``: Path to mask file (empty for classification)

    Example:
        >>> root = Path("./datasets/datumaro")
        >>> samples = make_datumaro_dataset(root)
        >>> samples.head()  # doctest: +NORMALIZE_WHITESPACE
           image_path  label  label_index      split mask_path
        0  path/...   Normal           0  Split.TRAIN
        1  path/...   Normal           0  Split.TRAIN
        2  path/...   Normal           0  Split.TRAIN
    """
    annotation_file = Path(root) / "annotations" / "default.json"
    with annotation_file.open() as f:
        annotations = json.load(f)

    categories = annotations["categories"]
    categories = {idx: label["name"] for idx, label in enumerate(categories["label"]["labels"])}

    samples = []
    for item in annotations["items"]:
        image_path = Path(root) / "images" / "default" / item["image"]["path"]
        label_index = item["annotations"][0]["label_id"]
        label = categories[label_index]
        samples.append({
            "image_path": str(image_path),
            "label": label,
            "label_index": label_index,
            "split": None,
            "mask_path": "",  # mask is provided in annotation file
        })
    samples_df = pd.DataFrame(
        samples,
        columns=["image_path", "label", "label_index", "split", "mask_path"],
        index=range(len(samples)),
    )
    # Create test/train split
    # By default assign all "Normal" samples to train and all "Anomalous" to test
    samples_df.loc[samples_df["label_index"] == LabelName.NORMAL, "split"] = Split.TRAIN
    samples_df.loc[samples_df["label_index"] == LabelName.ABNORMAL, "split"] = Split.TEST

    # datumaro only supports classification
    samples_df.attrs["task"] = "classification"

    # Get the data frame for the split.
    if split:
        samples_df = samples_df[samples_df.split == split].reset_index(drop=True)

    return samples_df
Create a DataFrame of image samples from a Datumaro dataset.

    Args:
        root (str | Path): Path to the dataset root directory.
        split (str | Split | None, optional): Dataset split to load. Usually
            ``Split.TRAIN`` or ``Split.TEST``. Defaults to ``None``.

    Returns:
        pd.DataFrame: DataFrame containing samples with columns:
            - ``image_path``: Path to the image file
            - ``label``: Class label name
            - ``label_index``: Numeric label index
            - ``split``: Dataset split
            - ``mask_path``: Path to mask file (empty for classification)

    Example:
        >>> root = Path("./datasets/datumaro")
        >>> samples = make_datumaro_dataset(root)
        >>> samples.head()  # doctest: +NORMALIZE_WHITESPACE
           image_path  label  label_index      split mask_path
        0  path/...   Normal           0  Split.TRAIN
        1  path/...   Normal           0  Split.TRAIN
        2  path/...   Normal           0  Split.TRAIN
    
src/anomalib/data/datasets/image/datumaro.py