Skip to content

Commit

Permalink
Drop export tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianboguszewski committed Dec 22, 2023
1 parent 17ba515 commit a3e0c3d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 130 deletions.
152 changes: 70 additions & 82 deletions tests/integration/model/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,90 +18,11 @@
from anomalib.utils.types import TaskType


def models() -> set[str]:
def models() -> list[str]:
"""Return all available models except ai_vad."""
return get_available_models()


def _get_objects(
model_name: str,
dataset_path: Path,
project_path: Path,
) -> tuple[AnomalyModule, AnomalibDataModule, Engine]:
"""Return model, dataset, and engine objects.
Args:
model_name (str): Name of the model to train
dataset_path (Path): Path to the root of dummy dataset
project_path (Path): path to the temporary project folder
Returns:
tuple[AnomalyModule, AnomalibDataModule, Engine]: Returns the created objects for model, dataset,
and engine
"""
# select task type
if model_name in ("rkde", "ai_vad"):
task_type = TaskType.DETECTION
elif model_name in ("ganomaly", "dfkde"):
task_type = TaskType.CLASSIFICATION
else:
task_type = TaskType.SEGMENTATION

# set extra model args
# TODO(ashwinvaidya17): Fix these Edge cases
# https://github.com/openvinotoolkit/anomalib/issues/1478

extra_args = {}
if model_name == "patchcore":
extra_args["input_size"] = (256, 256)
elif model_name in ("rkde", "dfkde"):
extra_args["n_pca_components"] = 2

# select dataset
if model_name == "ai_vad":
# aivad expects UCSD dataset
dataset = UCSDped(
root=dataset_path / "ucsdped",
category="dummy",
task=task_type,
train_batch_size=1,
eval_batch_size=1,
)
else:
# EfficientAd requires that the batch size be lesser than the number of images in the dataset.
# This is so that the LR step size is not 0.
dataset = MVTec(
root=dataset_path / "mvtec",
category="dummy",
task=task_type,
train_batch_size=1,
eval_batch_size=1,
)

model = get_model(model_name, **extra_args)
engine = Engine(
logger=False,
default_root_dir=project_path,
max_epochs=1,
devices=1,
pixel_metrics=["F1Score", "AUROC"],
task=task_type,
callbacks=[
ModelCheckpoint(
dirpath=f"{project_path}/{model_name}/dummy/weights",
monitor=None,
filename="last",
save_last=True,
auto_insert_metric_name=False,
),
],
# TODO(ashwinvaidya17): Fix these Edge cases
# https://github.com/openvinotoolkit/anomalib/issues/1478
max_steps=70000 if model_name == "efficient_ad" else -1,
)
return model, dataset, engine


class TestAPI:
"""Do sanity check on all models."""

Expand All @@ -114,7 +35,7 @@ def test_fit(self, model_name: str, dataset_path: Path, project_path: Path) -> N
dataset_path (Path): Root to dataset from fixture.
project_path (Path): Path to temporary project folder from fixture.
"""
model, dataset, engine = _get_objects(
model, dataset, engine = self._get_objects(
model_name=model_name,
dataset_path=dataset_path,
project_path=project_path,
Expand All @@ -130,9 +51,76 @@ def test_test(self, model_name: str, dataset_path: Path, project_path: Path) ->
dataset_path (Path): Root to dataset from fixture.
project_path (Path): Path to temporary project folder from fixture.
"""
model, dataset, engine = _get_objects(
model, dataset, engine = self._get_objects(
model_name=model_name,
dataset_path=dataset_path,
project_path=project_path,
)
engine.test(model=model, datamodule=dataset, ckpt_path=f"{project_path}/{model_name}/dummy/weights/last.ckpt")

def _get_objects(
self,
model_name: str,
dataset_path: Path,
project_path: Path,
) -> tuple[AnomalyModule, AnomalibDataModule, Engine]:
"""Return model, dataset, and engine objects.
Args:
model_name (str): Name of the model to train
dataset_path (Path): Path to the root of dummy dataset
project_path (Path): path to the temporary project folder
Returns:
tuple[AnomalyModule, AnomalibDataModule, Engine]: Returns the created objects for model, dataset,
and engine
"""
# select task type
if model_name in ("rkde", "ai_vad"):
task_type = TaskType.DETECTION
elif model_name in ("ganomaly", "dfkde"):
task_type = TaskType.CLASSIFICATION
else:
task_type = TaskType.SEGMENTATION

# set extra model args
# TODO(ashwinvaidya17): Fix these Edge cases
# https://github.com/openvinotoolkit/anomalib/issues/1478

extra_args = {}
if model_name == "patchcore":
extra_args["input_size"] = (256, 256)
elif model_name in ("rkde", "dfkde"):
extra_args["n_pca_components"] = 2

# select dataset
if model_name == "ai_vad":
# aivad expects UCSD dataset
dataset = UCSDped(root=dataset_path / "ucsdped", category="dummy", task=task_type)
else:
# EfficientAd requires that the batch size be lesser than the number of images in the dataset.
# This is so that the LR step size is not 0.
dataset = MVTec(root=dataset_path / "mvtec", category="dummy", task=task_type, train_batch_size=2)

model = get_model(model_name, **extra_args)
engine = Engine(
logger=False,
default_root_dir=project_path,
max_epochs=1,
devices=1,
pixel_metrics=["F1Score", "AUROC"],
task=task_type,
callbacks=[
ModelCheckpoint(
dirpath=f"{project_path}/{model_name}/dummy/weights",
monitor=None,
filename="last",
save_last=True,
auto_insert_metric_name=False,
),
],
# TODO(ashwinvaidya17): Fix these Edge cases
# https://github.com/openvinotoolkit/anomalib/issues/1478
max_steps=70000 if model_name == "efficient_ad" else -1,
)
return model, dataset, engine
48 changes: 0 additions & 48 deletions tests/unit/deploy/test_export.py

This file was deleted.

0 comments on commit a3e0c3d

Please sign in to comment.