code: def make_mvtec_dataset(
      root: str | Path,
      split: str | Split | None = None,
      extensions: Sequence[str] | None = None,
  ) -> DataFrame:
      """Create MVTec AD samples by parsing the MVTec AD data file structure.
  
      The files are expected to follow the structure:
          path/to/dataset/split/category/image_filename.png
          path/to/dataset/ground_truth/category/mask_filename.png
  
      This function creates a dataframe to store the parsed information based on the following format:
      |---|---------------|-------|---------|---------------|---------------------------------------|-------------|
      |   | path          | split | label   | image_path    | mask_path                             | label_index |
      |---|---------------|-------|---------|---------------|---------------------------------------|-------------|
      | 0 | datasets/name |  test |  defect |  filename.png | ground_truth/defect/filename_mask.png | 1           |
      |---|---------------|-------|---------|---------------|---------------------------------------|-------------|
  
      Args:
          path (Path): Path to dataset
          split (str | Split | None, optional): Dataset split (ie., either train or test). Defaults to None.
          split_ratio (float, optional): Ratio to split normal training images and add to the
              test set in case test set doesn't contain any normal images.
              Defaults to 0.1.
          seed (int, optional): Random seed to ensure reproducibility when splitting. Defaults to 0.
          create_validation_set (bool, optional): Boolean to create a validation set from the test set.
              MVTec AD dataset does not contain a validation set. Those wanting to create a validation set
              could set this flag to ``True``.
  
      Examples:
          The following example shows how to get training samples from MVTec AD bottle category:
  
          >>> root = Path('./MVTec')
          >>> category = 'bottle'
          >>> path = root / category
          >>> path
          PosixPath('MVTec/bottle')
  
          >>> samples = make_mvtec_dataset(path, split='train', split_ratio=0.1, seed=0)
          >>> samples.head()
             path         split label image_path                           mask_path                   label_index
          0  MVTec/bottle train good MVTec/bottle/train/good/105.png MVTec/bottle/ground_truth/good/105_mask.png 0
          1  MVTec/bottle train good MVTec/bottle/train/good/017.png MVTec/bottle/ground_truth/good/017_mask.png 0
          2  MVTec/bottle train good MVTec/bottle/train/good/137.png MVTec/bottle/ground_truth/good/137_mask.png 0
          3  MVTec/bottle train good MVTec/bottle/train/good/152.png MVTec/bottle/ground_truth/good/152_mask.png 0
          4  MVTec/bottle train good MVTec/bottle/train/good/109.png MVTec/bottle/ground_truth/good/109_mask.png 0
  
      Returns:
          DataFrame: an output dataframe containing the samples of the dataset.
      """
      if extensions is None:
          extensions = IMG_EXTENSIONS
  
      root = Path(root)
      samples_list = [
          (str(root),) + f.parts[-3:]
          for f in root.glob(r"**/*")
          if f.suffix in extensions
      ]
      if not samples_list:
          raise RuntimeError(f"Found 0 images in {root}")
  
      samples = DataFrame(
          samples_list, columns=["path", "split", "label", "image_path"]
      )
  
      # Modify image_path column by converting to absolute path
      samples["image_path"] = (
          samples.path
          + "/"
          + samples.split
          + "/"
          + samples.label
          + "/"
          + samples.image_path
      )
  
      # Create label index for normal (0) and anomalous (1) images.
      samples.loc[
          (samples.label == "good"), "label_index"
      ] = LabelName.NORMAL
      samples.loc[
          (samples.label != "good"), "label_index"
      ] = LabelName.ABNORMAL
      samples.label_index = samples.label_index.astype(int)
  
      # separate masks from samples
      mask_samples = samples.loc[
          samples.split == "ground_truth"
      ].sort_values(by="image_path", ignore_index=True)
      samples = samples[samples.split != "ground_truth"].sort_values(
          by="image_path", ignore_index=True
      )
  
      # assign mask paths to anomalous test images
      samples["mask_path"] = ""
      samples.loc[
          (samples.split == "test")
          & (samples.label_index == LabelName.ABNORMAL),
          "mask_path",
      ] = mask_samples.image_path.values
  
      # assert that the right mask files are associated with the right test images
      if len(samples.loc[samples.label_index == LabelName.ABNORMAL]):
          assert (
              samples.loc[samples.label_index == LabelName.ABNORMAL]
              .apply(
                  lambda x: Path(x.image_path).stem
                  in Path(x.mask_path).stem,
                  axis=1,
              )
              .all()
          ), "Mismatch between anomalous images and ground truth masks. Make sure the mask files in 'ground_truth' \
                  folder follow the same naming convention as the anomalous images in the dataset (e.g. image: \
                  '000.png', mask: '000.png' or '000_mask.png')."
  
      if split:
          samples = samples[samples.split == split].reset_index(
              drop=True
          )
  
      return samples
  
file_path: anomalib/src/anomalib/data/mvtec.py
imports: from __future__ import annotations
  import logging
  from pathlib import Path
  from typing import Sequence
  import albumentations
  from pandas import DataFrame
  from anomalib.data.base import AnomalibDataModule, AnomalibDataset
  from anomalib.data.task_type import TaskType
  from anomalib.data.utils import DownloadInfo, InputNormalizationMethod, LabelName, Split, TestSplitMode, ValSplitMode, download_and_extract, get_transforms
label_desc: Use image node_id 1 for calling a global function with example usage: make_mvtec_dataset(root, split, extensions) and returns: samples