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

📝 Add benchmarking notebook #353

Merged
merged 7 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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
Loading