You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
OS information
OS information:
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
Code of Conduct
The text was updated successfully, but these errors were encountered: