Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Trained EfficientAd network can't detect any anomaly #2538

Open
1 task done
westwind1027 opened this issue Jan 23, 2025 · 2 comments
Open
1 task done

[Bug]: Trained EfficientAd network can't detect any anomaly #2538

westwind1027 opened this issue Jan 23, 2025 · 2 comments

Comments

@westwind1027
Copy link

Describe the bug

I trained an EfficientAd network by following the instruction of "https://anomalib.readthedocs.io/en/latest/markdown/get_started/anomalib.html"

I only changed “train_batch_size” to 1 in training code.

Training code

from anomalib.data import MVTec
from anomalib.engine import Engine
from anomalib.models import EfficientAd

datamodule = MVTec(
root="./datasets/MVTec", # Path to download/store the dataset
category="bottle", # MVTec category to use
train_batch_size=1, # Number of images per training batch
eval_batch_size=32, # Number of images per validation/test batch
num_workers=8, # Number of parallel processes for data loading
)

model = EfficientAd()

engine = Engine(max_epochs=10) # Train for 10 epochs

engine.fit(datamodule=datamodule, model=model)

After training finished, I got a trained "model.ckpt" in results folder. Then, I want to check if it can work as expected. So, I followed the instruction of "Lightning Inference" to inference an anomaly bottle image which belongs to MVTec dataset. I changed "dataset path" to an anomaly bottle image path, and changed "ckpt_path" to my trained "model.ckpt" in lightning inference code.

But I got an empty list "predictions" when I ran the inference code. No anomaly were found. I don't know why the trained "model.ckpt" can't work.

Lightning inference code

from pathlib import Path

from anomalib.data import PredictDataset
from anomalib.engine import Engine
from anomalib.models import EfficientAd

model = EfficientAd()
engine = Engine()

dataset = PredictDataset(
path=Path("path/to/test/images"),
image_size=(256, 256),
)

predictions = engine.predict(
model=model,
dataset=dataset,
ckpt_path="path/to/model.ckpt",
)

if predictions is not None:
for prediction in predictions:
image_path = prediction.image_path
anomaly_map = prediction.anomaly_map # Pixel-level anomaly heatmap
pred_label = prediction.pred_label # Image-level label (0: normal, 1: anomalous)
pred_score = prediction.pred_score # Image-level anomaly score

Dataset

MVTec

Model

Other (please specify in the field below)

Steps to reproduce the behavior

  1. install anomalib with: pip install anomalib==2.0.0b2
  2. run training code as the instruction of "https://anomalib.readthedocs.io/en/latest/markdown/get_started/anomalib.html".
  3. run lightning inference code as the instruction of "https://anomalib.readthedocs.io/en/latest/markdown/get_started/anomalib.html".
  4. get an empty "predictions" when inference an anomaly bottle image.

OS information

OS information:

  • OS: win11 pro
  • Python version: 3.11.9
  • Anomalib version: 2.0.0b2
  • PyTorch version: 2.3.1+cu121
  • CUDA/cuDNN version: 12.6
  • GPU models and configuration: 1x GeForce RTX 4080

Expected behavior

There should be some anomaly data in "predictions".

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

2.0.0b2

Configuration YAML

default yaml configuration.

Logs

No logs.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@alexriedel1
Copy link
Contributor

Whats the length of your dataset: len(dataset)?

@westwind1027
Copy link
Author

Whats the length of your dataset: len(dataset)?

len(dataset) is 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants