def __init__(
        self,
        root: Path | str = "./datasets/Real-IAD",
        category: str = "audiojack",
        resolution: str | int = 256,
        augmentations: Transform | None = None,
        split: str | Split | None = None,
        json_path: str | Path = "realiad_jsons/realiad_jsons/{category}.json",
    ) -> None:
        """Initialize RealIAD dataset.

        Args:
            root: Path to root directory containing the dataset.
            category: Category name, must be one of ``CATEGORIES``.
            resolution: Image resolution, must be one of ``RESOLUTIONS`` or their integer equivalents.
                For example, both "256" and 256 are valid.
            augmentations: Augmentations that should be applied to the input images.
            split: Dataset split - usually ``Split.TRAIN`` or ``Split.TEST``.
            json_path: Path to JSON metadata file, relative to root directory.
                Can use {category} placeholder which will be replaced with the category name.
                Common paths are:
                - "realiad_jsons/realiad_jsons/{category}.json" - Base metadata (multi-view)
                - "realiad_jsons/realiad_jsons_sv/{category}.json" - Single-view metadata
                - "realiad_jsons/realiad_jsons_fuiad_0.4/{category}.json" - FUIAD v0.4 metadata
        """
        super().__init__(augmentations=augmentations)

        if category not in CATEGORIES:
            msg = f"Category {category} not found in Real-IAD dataset. Available categories: {CATEGORIES}"
            raise ValueError(msg)

        # Convert resolution to string if it's an integer
        if isinstance(resolution, int):
            resolution = str(resolution)

        if resolution not in RESOLUTIONS:
            msg = f"Resolution {resolution} not found in Real-IAD dataset. Available resolutions: {RESOLUTIONS}"
            raise ValueError(msg)

        self.root = Path(root)
        self.category = category
        self.resolution = resolution
        self.split = split

        # Format json_path if it contains {category} placeholder
        if isinstance(json_path, str):
            json_path = json_path.format(category=category)

        # Resolve JSON path
        json_file = self.root / json_path

        # Load JSON metadata
        if not json_file.exists():
            msg = f"JSON metadata file not found at {json_file}"
            raise FileNotFoundError(msg)

        with json_file.open(encoding="utf-8") as f:
            self.metadata = json.load(f)

        # Validate JSON structure
        if not isinstance(self.metadata, dict) or not any(key in self.metadata for key in ["train", "test"]):
            msg = f"Invalid JSON structure in {json_file}. Must contain 'train' and/or 'test' keys."
            raise ValueError(msg)

        # Construct the path to the category directory based on resolution
        self.root_category = self.root / f"realiad_{resolution}" / category

        # Create dataset samples
        self.samples = make_realiad_dataset(
            self.root_category,
            split=self.split,
            extensions=IMG_EXTENSIONS,
            metadata=self.metadata,
        )
Initialize RealIAD dataset.

        Args:
            root: Path to root directory containing the dataset.
            category: Category name, must be one of ``CATEGORIES``.
            resolution: Image resolution, must be one of ``RESOLUTIONS`` or their integer equivalents.
                For example, both "256" and 256 are valid.
            augmentations: Augmentations that should be applied to the input images.
            split: Dataset split - usually ``Split.TRAIN`` or ``Split.TEST``.
            json_path: Path to JSON metadata file, relative to root directory.
                Can use {category} placeholder which will be replaced with the category name.
                Common paths are:
                - "realiad_jsons/realiad_jsons/{category}.json" - Base metadata (multi-view)
                - "realiad_jsons/realiad_jsons_sv/{category}.json" - Single-view metadata
                - "realiad_jsons/realiad_jsons_fuiad_0.4/{category}.json" - FUIAD v0.4 metadata
        
src/anomalib/data/datasets/image/realiad.py