Skip to content

Commit

Permalink
🏷️ Refactor Datamodule names (#354)
Browse files Browse the repository at this point in the history
* Refactored MVTec datamodule

* 🏷️  Rename BTech datamodule

* 🏷️  Rename Folder datamodule

* 🛠 Fix the config files for draem and fastflow
  • Loading branch information
samet-akcay committed Jun 9, 2022
1 parent e6c66fa commit b2d6f62
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 46 deletions.
18 changes: 9 additions & 9 deletions anomalib/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from omegaconf import DictConfig, ListConfig
from pytorch_lightning import LightningDataModule

from .btech import BTechDataModule
from .folder import FolderDataModule
from .btech import BTech
from .folder import Folder
from .inference import InferenceDataset
from .mvtec import MVTecDataModule
from .mvtec import MVTec


def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule:
Expand All @@ -37,7 +37,7 @@ def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule
datamodule: LightningDataModule

if config.dataset.format.lower() == "mvtec":
datamodule = MVTecDataModule(
datamodule = MVTec(
# TODO: Remove config values. IAAALD-211
root=config.dataset.path,
category=config.dataset.category,
Expand All @@ -52,7 +52,7 @@ def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule
create_validation_set=config.dataset.create_validation_set,
)
elif config.dataset.format.lower() == "btech":
datamodule = BTechDataModule(
datamodule = BTech(
# TODO: Remove config values. IAAALD-211
root=config.dataset.path,
category=config.dataset.category,
Expand All @@ -67,7 +67,7 @@ def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule
create_validation_set=config.dataset.create_validation_set,
)
elif config.dataset.format.lower() == "folder":
datamodule = FolderDataModule(
datamodule = Folder(
root=config.dataset.path,
normal_dir=config.dataset.normal_dir,
abnormal_dir=config.dataset.abnormal_dir,
Expand Down Expand Up @@ -97,8 +97,8 @@ def get_datamodule(config: Union[DictConfig, ListConfig]) -> LightningDataModule

__all__ = [
"get_datamodule",
"BTechDataModule",
"FolderDataModule",
"BTech",
"Folder",
"InferenceDataset",
"MVTecDataModule",
"MVTec",
]
18 changes: 9 additions & 9 deletions anomalib/data/btech.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def make_btech_dataset(
return samples


class BTech(VisionDataset):
class BTechDataset(VisionDataset):
"""BTech PyTorch Dataset."""

def __init__(
Expand All @@ -166,10 +166,10 @@ def __init__(
create_validation_set: Create a validation subset in addition to the train and test subsets
Examples:
>>> from anomalib.data.btech import BTech
>>> from anomalib.data.btech import BTechDataset
>>> from anomalib.data.transforms import PreProcessor
>>> pre_process = PreProcessor(image_size=256)
>>> dataset = BTech(
>>> dataset = BTechDataset(
... root='./datasets/BTech',
... category='leather',
... pre_process=pre_process,
Expand Down Expand Up @@ -257,7 +257,7 @@ def __getitem__(self, index: int) -> Dict[str, Union[str, Tensor]]:
return item


class BTechDataModule(LightningDataModule):
class BTech(LightningDataModule):
"""BTechDataModule Lightning Data Module."""

def __init__(
Expand Down Expand Up @@ -291,8 +291,8 @@ def __init__(
create_validation_set: Create a validation subset in addition to the train and test subsets
Examples
>>> from anomalib.data import BTechDataModule
>>> datamodule = BTechDataModule(
>>> from anomalib.data import BTech
>>> datamodule = BTech(
... root="./datasets/BTech",
... category="leather",
... image_size=256,
Expand Down Expand Up @@ -398,7 +398,7 @@ def setup(self, stage: Optional[str] = None) -> None:
"""
logger.info("Setting up train, validation, test and prediction datasets.")
if stage in (None, "fit"):
self.train_data = BTech(
self.train_data = BTechDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_train,
Expand All @@ -409,7 +409,7 @@ def setup(self, stage: Optional[str] = None) -> None:
)

if self.create_validation_set:
self.val_data = BTech(
self.val_data = BTechDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_val,
Expand All @@ -419,7 +419,7 @@ def setup(self, stage: Optional[str] = None) -> None:
create_validation_set=self.create_validation_set,
)

self.test_data = BTech(
self.test_data = BTechDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_val,
Expand Down
10 changes: 5 additions & 5 deletions anomalib/data/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def __getitem__(self, index: int) -> Dict[str, Union[str, Tensor]]:
return item


class FolderDataModule(LightningDataModule):
class Folder(LightningDataModule):
"""Folder Lightning Data Module."""

def __init__(
Expand Down Expand Up @@ -359,8 +359,8 @@ def __init__(
Examples:
Assume that we use Folder Dataset for the MVTec/bottle/broken_large category. We would do:
>>> from anomalib.data import FolderDataModule
>>> datamodule = FolderDataModule(
>>> from anomalib.data import Folder
>>> datamodule = Folder(
... root="./datasets/MVTec/bottle/test",
... normal="good",
... abnormal="broken_large",
Expand All @@ -379,7 +379,7 @@ def __init__(
The dataset expects that mask annotation filenames must be same as the original filename.
To this end, we modified mask filenames in MVTec AD bottle category.
Now we could try folder data module using the mvtec bottle broken large category
>>> datamodule = FolderDataModule(
>>> datamodule = Folder(
... root="./datasets/bottle/test",
... normal="good",
... abnormal="broken_large",
Expand All @@ -401,7 +401,7 @@ def __init__(
By default, Folder Data Module does not create a validation set. If a validation set
is needed it could be set as follows:
>>> datamodule = FolderDataModule(
>>> datamodule = Folder(
... root="./datasets/bottle/test",
... normal="good",
... abnormal="broken_large",
Expand Down
18 changes: 9 additions & 9 deletions anomalib/data/mvtec.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def make_mvtec_dataset(
return samples


class MVTec(VisionDataset):
class MVTecDataset(VisionDataset):
"""MVTec AD PyTorch Dataset."""

def __init__(
Expand All @@ -189,10 +189,10 @@ def __init__(
create_validation_set: Create a validation subset in addition to the train and test subsets
Examples:
>>> from anomalib.data.mvtec import MVTec
>>> from anomalib.data.mvtec import MVTecDataset
>>> from anomalib.data.transforms import PreProcessor
>>> pre_process = PreProcessor(image_size=256)
>>> dataset = MVTec(
>>> dataset = MVTecDataset(
... root='./datasets/MVTec',
... category='leather',
... pre_process=pre_process,
Expand Down Expand Up @@ -280,7 +280,7 @@ def __getitem__(self, index: int) -> Dict[str, Union[str, Tensor]]:
return item


class MVTecDataModule(LightningDataModule):
class MVTec(LightningDataModule):
"""MVTec AD Lightning Data Module."""

def __init__(
Expand Down Expand Up @@ -314,8 +314,8 @@ def __init__(
create_validation_set: Create a validation subset in addition to the train and test subsets
Examples
>>> from anomalib.data import MVTecDataModule
>>> datamodule = MVTecDataModule(
>>> from anomalib.data import MVTec
>>> datamodule = MVTec(
... root="./datasets/MVTec",
... category="leather",
... image_size=256,
Expand Down Expand Up @@ -404,7 +404,7 @@ def setup(self, stage: Optional[str] = None) -> None:
"""
logger.info("Setting up train, validation, test and prediction datasets.")
if stage in (None, "fit"):
self.train_data = MVTec(
self.train_data = MVTecDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_train,
Expand All @@ -415,7 +415,7 @@ def setup(self, stage: Optional[str] = None) -> None:
)

if self.create_validation_set:
self.val_data = MVTec(
self.val_data = MVTecDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_val,
Expand All @@ -425,7 +425,7 @@ def setup(self, stage: Optional[str] = None) -> None:
create_validation_set=self.create_validation_set,
)

self.test_data = MVTec(
self.test_data = MVTecDataset(
root=self.root,
category=self.category,
pre_process=self.pre_process_val,
Expand Down
7 changes: 5 additions & 2 deletions anomalib/models/draem/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ metrics:
project:
seed: 42
path: ./results
log_images_to: ["local"]
logger: false # options: [tensorboard, wandb, csv] or combinations.

logging:
log_images_to: ["local"] # options: [wandb, tensorboard, local]. Make sure you also set logger with using wandb or tensorboard.
logger: [] # options: [tensorboard, wandb, csv] or combinations.
log_graph: false # Logs the model graph to respective logger.

optimization:
openvino:
Expand Down
9 changes: 6 additions & 3 deletions anomalib/models/fastflow/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ metrics:
adaptive: true

project:
seed: 0
seed: 42
path: ./results
log_images_to: [local]
logger: false # options: [tensorboard, wandb, csv] or combinations.

logging:
log_images_to: ["local"] # options: [wandb, tensorboard, local]. Make sure you also set logger with using wandb or tensorboard.
logger: [] # options: [tensorboard, wandb, csv] or combinations.
log_graph: false # Logs the model graph to respective logger.

# PL Trainer Args. Don't add extra parameter here.
trainer:
Expand Down
13 changes: 4 additions & 9 deletions tests/pre_merge/datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
import pytest

from anomalib.config import update_input_size_config
from anomalib.data import (
BTechDataModule,
FolderDataModule,
MVTecDataModule,
get_datamodule,
)
from anomalib.data import BTech, Folder, MVTec, get_datamodule
from anomalib.pre_processing.transforms import Denormalize, ToNumpy
from tests.helpers.config import get_test_configurable_parameters
from tests.helpers.dataset import TestDataset, get_dataset_path


@pytest.fixture(autouse=True)
def mvtec_data_module():
datamodule = MVTecDataModule(
datamodule = MVTec(
root=get_dataset_path(dataset="MVTec"),
category="leather",
image_size=(256, 256),
Expand All @@ -36,7 +31,7 @@ def mvtec_data_module():
@pytest.fixture(autouse=True)
def btech_data_module():
"""Create BTech Data Module."""
datamodule = BTechDataModule(
datamodule = BTech(
root=get_dataset_path(dataset="BTech"),
category="01",
image_size=(256, 256),
Expand All @@ -54,7 +49,7 @@ def btech_data_module():
def folder_data_module():
"""Create Folder Data Module."""
root = get_dataset_path(dataset="bottle")
datamodule = FolderDataModule(
datamodule = Folder(
root=root,
normal_dir="good",
abnormal_dir="broken_large",
Expand Down

0 comments on commit b2d6f62

Please sign in to comment.