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

Fix/da/image size bug #135

Merged
merged 6 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 anomalib/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule
# TODO: Remove config values. IAAALD-211
root=config.dataset.path,
category=config.dataset.category,
image_size=(config.dataset.image_size[0], config.dataset.image_size[0]),
image_size=(config.dataset.image_size[0], config.dataset.image_size[1]),
train_batch_size=config.dataset.train_batch_size,
test_batch_size=config.dataset.test_batch_size,
num_workers=config.dataset.num_workers,
Expand Down
2 changes: 1 addition & 1 deletion anomalib/models/padim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(

n_features = DIMS[backbone]["reduced_dims"]
patches_dims = torch.tensor(input_size) / DIMS[backbone]["emb_scale"]
n_patches = patches_dims.prod().int().item()
n_patches = patches_dims.ceil().prod().int().item()
self.gaussian = MultiVariateGaussian(n_features, n_patches)

if apply_tiling:
Expand Down
26 changes: 26 additions & 0 deletions tests/pre_merge/datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest

from anomalib.config import get_configurable_parameters, update_input_size_config
from anomalib.data import get_datamodule
from anomalib.data.mvtec import MVTecDataModule
from anomalib.pre_processing.transforms import Denormalize, ToNumpy
from tests.helpers.dataset import get_dataset_path
Expand Down Expand Up @@ -100,3 +102,27 @@ def test_one_channel_images(self, data_sample):
def test_representation(self):
"""Test ToNumpy() representation should return string `ToNumpy()`"""
assert str(ToNumpy()) == "ToNumpy()"


class TestConfigToDataModule:
"""Tests that check if the dataset parameters in the config achieve the desired effect."""

@pytest.mark.parametrize(
["input_size", "effective_image_size"],
[
(512, (512, 512)),
((245, 276), (245, 276)),
((263, 134), (263, 134)),
((267, 267), (267, 267)),
],
)
def test_image_size(self, input_size, effective_image_size):
"""Test if the image size parameter works as expected."""
model_name = "stfpm"
configurable_parameters = get_configurable_parameters(model_name)
configurable_parameters.dataset.image_size = input_size
configurable_parameters = update_input_size_config(configurable_parameters)

data_module = get_datamodule(configurable_parameters)
data_module.setup()
assert iter(data_module.train_dataloader()).__next__()["image"].shape[-2:] == effective_image_size