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

DRAEM MODEL - Heatmap shows everything is detected as anomaly #2529

Open
Paucaster3 opened this issue Jan 21, 2025 · 0 comments
Open

DRAEM MODEL - Heatmap shows everything is detected as anomaly #2529

Paucaster3 opened this issue Jan 21, 2025 · 0 comments

Comments

@Paucaster3
Copy link

Hi, I've been performing some tests with DRAEM model, as it is one of the best performing according to Deep Industrial Image Anomaly Detection: A Survey.

When predicting some tests images (with synthetic defects, as I don't have real samples), the resulting heatmap indicates that the entire image is abnormal.

I'm trying to understand the result, as it has no sense, as the images come from the same distribution. Am I missing something?

Training sample

Image

Predicted sample

Image

Training script

datamodule = Folder(
    name="container-dataset",
    root=DATASET_PATH,
    normal_dir="normal",
    abnormal_dir="abnormal",
    mask_dir="masks",
    normal_split_ratio=0.2,
    train_batch_size=BATCH_SIZE,
    eval_batch_size=BATCH_SIZE,
)

# Model
model = Draem(
    enable_sspcab=False,
    sspcab_lambda=0.1,
    anomaly_source_path=None,
    beta=(0.1, 1.0),
)

# Engine
engine = Engine(
    task=TaskType.SEGMENTATION,  # Since DRAEM performs segmentation for anomaly localization
    image_metrics=["AUPR", "AUROC"],  # Metrics for image-level evaluation
    pixel_metrics=["AUPR", "AUROC"],  # Metrics for pixel-level evaluation
    max_epochs=NUM_EPOCHS,
    accelerator="gpu",
    default_root_dir=RESULTS_PATH,
    log_every_n_steps=10,
)

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

engine.export(model=model, export_type=ExportType.TORCH, export_root=RESULTS_PATH)

Prediction script

model = TorchInferencer(path_model)
   
metadata = {
    "image_threshold": 0.9, # threshold to label image as anomaly
    "pixel_threshold": 0.9, # threshold to label pixel as anomaly
    "task": "segmentation", # to return also boxes and box labels
}
result = model.predict(image_path, metadata=metadata)
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

1 participant