Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v.0.7.0.dev150]

### Updated

- Update padim code to work properly with lightning 2.4.0
- Move unused legacy dependencies to extras

## [v0.7.0.dev143]

### Fixed
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "anomalib-orobix"
version = "0.7.0.dev143"
version = "0.7.0.dev150"
description = "Orobix anomalib fork"
authors = [
"Intel OpenVINO <help@openvino.intel.com>",
Expand All @@ -19,21 +19,23 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = ">=3.9,<3.11"
python = ">=3.10,<3.11"
einops = "~0.6"
kornia = "0.6.5"
omegaconf = "~2.3"
freia = "~0.2"
wandb = "0.12.17"
gradio = "3.0.2"

line-profiler = "3.5.1"
jsonargparse = { version = "~4.3.0", extras = ["signatures"] }

imgaug = { version = "0.4.0", optional = true }

gradio = { version = "3.0.2", optional = true }
wandb = { version = "0.12.17", optional = true }
[tool.poetry.extras]
# We make imgaug optional as it requires opencv-python instead of the headless version
augmentation = ["imgaug"]
ui = ["gradio"]
wandb = ["wandb"]

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# BLACK CONFIGURATION #
Expand Down
2 changes: 1 addition & 1 deletion src/anomalib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# SPDX-License-Identifier: Apache-2.0

anomalib_version = "0.7.0"
custom_orobix_version = "1.4.3"
custom_orobix_version = "1.5.0"

__version__ = f"{anomalib_version}.dev{custom_orobix_version.replace('.', '')}"
9 changes: 9 additions & 0 deletions src/anomalib/models/padim/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def configure_optimizers() -> None: # pylint: disable=arguments-differ
def on_train_epoch_start(self) -> None:
self.embeddings = []
self.stats = []
self.model.in_training_loop = True
return super().on_train_epoch_start()

def training_step(self, batch: dict[str, str | Tensor], *args, **kwargs) -> None:
Expand Down Expand Up @@ -109,6 +110,7 @@ def on_validation_start(self) -> None:
logger.warning("No embeddings were extracted from the training set. Skipping Gaussian fitting.")
return

self.model.in_training_loop = False
logger.info("Aggregating the embedding extracted from the training set.")

embeddings = torch.vstack(self.embeddings)
Expand All @@ -134,7 +136,14 @@ def validation_step(self, batch: dict[str, str | Tensor], *args, **kwargs) -> ST
batch["anomaly_maps"], _ = self.model(batch["image"])
return batch

def on_test_start(self):
self.model.in_training_loop = False
return super().on_test_start()

def on_predict_start(self):
self.model.in_training_loop = False
return super().on_predict_start()

class PadimLightning(Padim):
"""PaDiM: a Patch Distribution Modeling Framework for Anomaly Detection and Localization.

Expand Down
3 changes: 2 additions & 1 deletion src/anomalib/models/padim/torch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(
self.anomaly_map_generator = AnomalyMapGenerator(image_size=input_size)

self.gaussian = MultiVariateGaussian(self.n_features, self.n_patches, tied_covariance=tied_covariance)
self.in_training_loop = False

def forward(self, input_tensor: Tensor) -> Tuple[Tensor, Tensor]:
"""Forward-pass image-batch (N, C, H, W) into model to extract features.
Expand Down Expand Up @@ -160,7 +161,7 @@ def forward(self, input_tensor: Tensor) -> Tuple[Tensor, Tensor]:

anomaly_score = None

if self.training:
if self.in_training_loop:
output = embeddings
else:
output = self.anomaly_map_generator(
Expand Down
Loading