Skip to content

❓ <title>Dinomaly heatmap issue #3035

@07prince

Description

@07prince

Your Question

i trained the Dinomaly model on my custiom dataset
this is my config ->

anomalib==2.3.0dev

seed_everything: true
trainer:
accelerator: auto
strategy: auto
devices: auto
num_nodes: 1
precision: null
logger: null
callbacks:

  • class_path: lightning.pytorch.callbacks.EarlyStopping
    init_args:
    monitor: train_loss_step
    min_delta: 0.0
    patience: 20
    verbose: false
    mode: max
    strict: true
    check_finite: true
    stopping_threshold: null
    divergence_threshold: null
    check_on_train_epoch_end: null
    log_rank_zero_only: false
    fast_dev_run: false
    max_epochs: 60
    min_epochs: null
    max_steps: -1
    min_steps: null
    max_time: null
    limit_train_batches: null
    limit_val_batches: null
    limit_test_batches: null
    limit_predict_batches: null
    overfit_batches: 0.0
    val_check_interval: null
    check_val_every_n_epoch: 1
    num_sanity_val_steps: null
    log_every_n_steps: null
    enable_checkpointing: null
    enable_progress_bar: null
    enable_model_summary: null
    accumulate_grad_batches: 1
    gradient_clip_val: null
    gradient_clip_algorithm: null
    deterministic: null
    benchmark: null
    inference_mode: true
    use_distributed_sampler: true
    profiler: null
    detect_anomaly: false
    barebones: false
    plugins: null
    sync_batchnorm: false
    reload_dataloaders_every_n_epochs: 0
    model_registry: null
    model:
    class_path: anomalib.models.Dinomaly
    init_args:
    encoder_name: dinov2reg_vit_base_14
    bottleneck_dropout: 0.2
    decoder_depth: 8
    target_layers: null
    fuse_layer_encoder: null
    fuse_layer_decoder: null
    remove_class_token: false
    pre_processor: true
    post_processor: true
    evaluator: true
    visualizer: true
    data:
    class_path: anomalib.data.Folder
    init_args:
    name: rotated_with_mask_testing
    normal_dir: train/good
    root: /home/rotated
    abnormal_dir: train/bad
    normal_test_dir: test/good
    mask_dir: train/ground_truth_binary
    normal_split_ratio: 0.2
    extensions: null
    train_batch_size: 16
    eval_batch_size: 16
    num_workers: 8
    train_augmentations: null
    val_augmentations: null
    test_augmentations: null
    augmentations: null
    test_split_mode: from_dir
    test_split_ratio: 0.2
    val_split_mode: same_as_test
    val_split_ratio: 0.5
    seed: 42

return_predictions: true

ckpt_path: /home/model.ckpt

logging:
log_graph: true
default_root_dir: results

i used the cli command to train
anomalib fit -c

(dinomaly_venv) orama@orama-H610M-K-DDR4:~/Desktop/prince/dinomaly_anomalib$ anomalib fit -c config.yaml
2025-10-17 12:41:28,276 - anomalib.models.components.base.anomalib_module - INFO - Initializing Dinomaly model.
[10/17/25 12:41:28] INFO Initializing Dinomaly model. anomalib_module.py:131
2025-10-17 12:41:29,212 - anomalib.models.image.dinomaly.components.dinov2_loader - INFO - Loaded model: dinov2reg_vit_base_14
[10/17/25 12:41:29] INFO Loaded model: dinov2reg_vit_base_14 dinov2_loader.py:71
2025-10-17 12:41:29,648 - anomalib.callbacks - INFO - Loading the callbacks
INFO Loading the callbacks init.py:114
2025-10-17 12:41:29,650 - anomalib.engine.engine - INFO - Overriding gradient_clip_val from None with 0.1 for Dinomaly
INFO Overriding gradient_clip_val from None with 0.1 for Dinomaly engine.py:102
2025-10-17 12:41:29,651 - anomalib.engine.engine - INFO - Overriding num_sanity_val_steps from None with 0 for Dinomaly
INFO Overriding num_sanity_val_steps from None with 0 for Dinomaly engine.py:102
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
HPU available: False, using: 0 HPUs
You are using a CUDA device ('NVIDIA GeForce RTX 3060') that has Tensor Cores. To properly utilize them, you should set torch.set_float32_matmul_precision('medium' | 'high') which will trade-off precision for performance. For more details, read https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html#torch.set_float32_matmul_precision
2025-10-17 12:41:29,750 - lightning.pytorch.accelerators.cuda - INFO - LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
[10/17/25 12:41:29] INFO LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0] cuda.py:61
2025-10-17 12:41:29,960 - lightning.pytorch.callbacks.model_summary - INFO -
| Name | Type | Params | Mode

0 | pre_processor | PreProcessor | 0 | train
1 | post_processor | PostProcessor | 0 | train
2 | evaluator | Evaluator | 0 | train
3 | model | DinomalyModel | 147 M | train
4 | trainable_modules | ModuleList | 61.4 M | train

61.4 M Trainable params
86.6 M Non-trainable params
147 M Total params
591.898 Total estimated model params size (MB)
385 Modules in train mode
0 Modules in eval mode
INFO model_summary.py:104
| Name | Type | Params | Mode
------------------------------------------------------------
0 | pre_processor | PreProcessor | 0 | train
1 | post_processor | PostProcessor | 0 | train
2 | evaluator | Evaluator | 0 | train
3 | model | DinomalyModel | 147 M | train
4 | trainable_modules | ModuleList | 61.4 M | train
------------------------------------------------------------
61.4 M Trainable params
86.6 M Non-trainable params
147 M Total params
591.898 Total estimated model params size (MB)
385 Modules in train mode
0 Modules in eval mode
Epoch 0: 0%| | 0/6 [00:00<?, ?it/s]/home/orama/Desktop/prince/dinomaly_anomalib/dinomaly_venv/lib/python3.10/site-packages/lightning/pytorch/utilities/data.py:79: Trying to infer the batch_size from an ambiguous collection. The batch size we found is 3. To avoid any miscalculations, use self.log(..., batch_size=batch_size).
Epoch 20: 100%|█████████████████████████████████████████████████████| 6/6 [00:14<00:00, 0.41it/s, train_loss_step=0.0647, train_loss_epoch=0.0629]
2025-10-17 12:48:39,322 - anomalib.callbacks.timer - INFO - Training took 429.37 seconds
[10/17/25 12:48:39] INFO Training took 429.37 seconds

After reviewing the results, I found that the model is able to detect defects in the data. However, the heatmaps generated are slightly shifted from the actual defect regions.

For example, in the image below, the defect is detected, but the attention in the heatmap highlights a slightly different location:

Image

how to solve this issue ?

Forum Check

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

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