Skip to content

✨ Add a custom dataset class in anomalib.data #2893

Closed

Description

@mdciri

Problem Description

How do I train a model using my own dataset? how do I create my dataset such that it is compatible with engine.fit()?
In this way, everyone will more likely use this library to train a model with using a custom dataset.

Proposed Solution

from anomalib.data import CustomDataModule
from anomalib.models import Patchcore
from anomalib.engine import Engine

# Initialize components
datamodule = CustomDataModule(???)
model = Patchcore()
engine = Engine()

# Train the model
engine.fit(datamodule=datamodule, model=model)

Alternatives Considered

No response

Additional Context

No response

Activity

  1. github-actions commented on Aug 18, 2025

    @github-actions

    Thanks for submitting this issue! It has been added to our triage queue. A maintainer will review it shortly.

  2. rajeshgangireddy commented on Aug 19, 2025

    @rajeshgangireddy
    Contributor

    Hi @mdciri
    You can use the Folder module to create a data module.
    A simple example looks like this :

    from anomalib.data import Folder
    from anomalib.models import Patchcore
    from anomalib.engine import Engine
    
    
    dataset_folder = "path/to/dataset"
    
    datamodule = Folder(
        name="DatasetName",  # A unique name for your dataset
        root=dataset_folder,  # Root directory containing 'normal' and 'abnormal' folders
        normal_dir="train/normal",  # Name of the folder containing normal images
        abnormal_dir = "test/abnormal",
        normal_test_dir = "test/normal",
        # explore other inputs to this
        train_batch_size=32,
        eval_batch_size=32,
        num_workers=8,
    )
    
    datamodule.setup()
    
    model = Patchcore()
    engine = Engine()
    engine.fit(datamodule=datamodule, model=model)
    
    

    Would that help you ?

  3. locked and limited conversation to collaborators on Aug 19, 2025
  4. converted this issue into a discussion #2897 on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions