Skip to content

❓ <title>I trained using the data from MVTecAD, but the results were not very satisfactory. #3319

Closed

Description

@Joe-Zz421

Your Question

My training code:
`from anomalib.data import MVTecAD
from anomalib.engine import Engine
from anomalib.models import Patchcore

from pathlib import Path
from anomalib.data import Folder

Initialize PatchCore model with specific parameters

model = Patchcore(
backbone="wide_resnet50_2", # Feature extraction backbone
layers=["layer2", "layer3"], # Layers to extract features from
pre_trained=True, # Use pretrained weights
coreset_sampling_ratio=0.1,
)

datamodule = Folder(
name="bottle",
root=Path("./datasets/bottle"),
normal_dir="good",
abnormal_dir='defect',
num_workers=0,
)

Initialize training engine with specific settings

engine = Engine(
max_epochs=1, # Patchcore typically needs only one epoch
accelerator="auto", # Automatically detect GPU/CPU
devices=1, # Number of devices to use
limit_val_batches=0, # Skip validation batches
)

Train the model

engine.fit(
model=model,
datamodule=datamodule,
)
`
result:

Image

Forum Check

  • I have searched the discussions forum for an answer to my question.

Activity

  1. github-actions commented on Feb 6, 2026

    @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 Feb 9, 2026

    @rajeshgangireddy
    Contributor

    Hi @Joe-Zz421,

    Any reason why you are not using MVTeCAD datamodule over the Folder?
    Just looking at your code, I think the issue might be passing this limit_val_batches=0 to the engine.
    Can you remove this and try again?

  3. Joe-Zz421 commented on Feb 9, 2026

    @Joe-Zz421
    Author

    Thank you @rajeshgangireddy ,
    Because I don't have a good dataset at present, I used an open-source dataset for testing. After deleting "limit_val_batches=0", I could see the normal results.

  4. locked and limited conversation to collaborators on Feb 9, 2026
  5. converted this issue into a discussion #3324 on Feb 9, 2026
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