Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/anomalib/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
Fre,
Ganomaly,
GeneralAD,
InpFormer,
Padim,
Patchcore,
Patchflow,
Expand Down Expand Up @@ -119,6 +120,7 @@ class UnknownModelError(ModuleNotFoundError):
"Fuvas",
"Ganomaly",
"GeneralAD",
"InpFormer",
"L2BT",
"Padim",
"Patchcore",
Expand Down
2 changes: 2 additions & 0 deletions src/anomalib/models/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from .fre import Fre
from .ganomaly import Ganomaly
from .general_ad import GeneralAD
from .inp_former import InpFormer
from .l2bt import L2BT
from .padim import Padim
from .patchcore import Patchcore
Expand Down Expand Up @@ -91,6 +92,7 @@
"Fre",
"Ganomaly",
"GeneralAD",
"InpFormer",
"L2BT",
"Padim",
"Patchcore",
Expand Down
29 changes: 29 additions & 0 deletions src/anomalib/models/image/inp_former/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0

Some files in this folder are based on the original INP-Former implementation by Wei Luo

Original license
----------------

MIT License

Copyright (c) 2025 Wei Luo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions src/anomalib/models/image/inp_former/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Exploring Intrinsic Normal Prototypes within a Single Image for Universal Anomaly Detection

This is the implementation of the [INP-Former](https://arxiv.org/abs/2503.02424) paper.

Model Type: Segmentation
43 changes: 43 additions & 0 deletions src/anomalib/models/image/inp_former/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""INP-Former: Anomaly Detection via Intrinsic Normal Prototypes.

The INP-Former model implements an encoder-decoder architecture for anomaly detection
that extracts Intrinsic Normal Prototypes (INPs) directly from each test image, rather
than relying on prototypes stored from the training set. Features from a frozen
pre-trained Vision Transformer encoder are aggregated by an INP Extractor (cross-attention
with learnable query tokens) into a small set of INPs per image, fused through a
bottleneck, and reconstructed by an INP-Guided Decoder that uses the INPs as keys and
values to constrain its output to normal patterns.

Anomaly detection is performed by computing the per-token discrepancy between encoder
and decoder features at multiple scales. Because the INPs are derived from the test
image itself, the normality reference is naturally aligned with the input, making the
model effective across single-class, multi-class, and few-shot anomaly detection
settings.

Example:
>>> from anomalib.models.image import InpFormer
>>> model = InpFormer()

The model can be used with any of the supported datasets and task modes in
anomalib. It combines pre-trained Vision Transformer features with image-specific
prototype extraction for robust, well-aligned anomaly detection.

Notes:
- Uses a frozen pre-trained Vision Transformer as the backbone encoder
- Intrinsic Normal Prototypes are extracted dynamically from each image
- INP Coherence Loss ensures prototypes faithfully represent normal features
- Soft Mining Loss upweights hard-to-reconstruct tokens during training
- Supports both anomaly detection and localization tasks
- Requires significant GPU memory due to Vision Transformer architecture

See Also:
:class:`anomalib.models.image.inp_former.lightning_model.InpFormer`:
Lightning implementation of the INP-Former model.
"""

from anomalib.models.image.inp_former.lightning_model import InpFormer

__all__ = ["InpFormer"]
17 changes: 17 additions & 0 deletions src/anomalib/models/image/inp_former/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""Components module for INP-Former model.
This module provides all the necessary components for the INP-Former
architecture.
"""

# Layer components
from .layers import AggregationBlock, PrototypeBlock

__all__ = [
# Layers
"AggregationBlock",
"PrototypeBlock",
]
Loading