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

Fixed Reverse Distillation export to ONNX #1990

Merged
merged 8 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 1 deletion src/anomalib/deploy/inferencers/openvino_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def predict(

# Resize image to model input size if not dynamic
if self.input_blob.partial_shape[2].is_static and self.input_blob.partial_shape[3].is_static:
image = cv2.resize(image, tuple(self.input_blob.shape[2:][::-1]))
image = cv2.resize(image, tuple(list(self.input_blob.shape)[2:][::-1]))

# Normalize numpy array to range [0, 1]
if image.dtype != np.float32:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from enum import Enum

import torch
from kornia.filters import gaussian_blur2d
from omegaconf import ListConfig
from torch import nn
from torch.nn import functional as F # noqa: N812

from anomalib.models.components import GaussianBlur2d


class AnomalyMapGenerationMode(str, Enum):
"""Type of mode when generating anomaly imape."""
Expand Down Expand Up @@ -87,8 +88,7 @@ def forward(self, student_features: list[torch.Tensor], teacher_features: list[t
elif self.mode == AnomalyMapGenerationMode.ADD:
anomaly_map += distance_map

return gaussian_blur2d(
anomaly_map,
return GaussianBlur2d(
kernel_size=(self.kernel_size, self.kernel_size),
sigma=(self.sigma, self.sigma),
)
)(anomaly_map.to(student_features[0].device))
4 changes: 2 additions & 2 deletions tests/integration/model/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def test_export(
dataset_path (Path): Root to dataset from fixture.
project_path (Path): Path to temporary project folder from fixture.
"""
if model_name in ("reverse_distillation", "rkde"):
if model_name == "rkde":
# TODO(ashwinvaidya17): Restore this test after fixing the issue
# https://github.com/openvinotoolkit/anomalib/issues/1513
pytest.skip(f"{model_name} fails to convert to ONNX and OpenVINO")
pytest.skip(f"{model_name} fails to convert to OpenVINO")

model, dataset, engine = self._get_objects(
model_name=model_name,
Expand Down
Loading