From 8ccf8f6c1ef3db4a9fa624d33647b4aca0f0eb8b Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 4 Apr 2022 06:52:50 -0700 Subject: [PATCH 01/12] bump up pytorch-lightning version --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 8276af5a5e..7c47912c1a 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -13,7 +13,7 @@ opencv-python>=4.5.3.56 opencv-contrib-python==4.5.5.62 pandas~=1.1.5 pillow==9.0.0 -pytorch-lightning==1.5.9 +pytorch-lightning==1.6.0 torch==1.8.1 torchvision==0.9.1 torchtext==0.9.1 From 1c5203d042d8bebb040282a7b58d027c8c59792c Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 4 Apr 2022 06:58:39 -0700 Subject: [PATCH 02/12] bump up to 1.6.0 or higher --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 7c47912c1a..fdc9ab5071 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -13,7 +13,7 @@ opencv-python>=4.5.3.56 opencv-contrib-python==4.5.5.62 pandas~=1.1.5 pillow==9.0.0 -pytorch-lightning==1.6.0 +pytorch-lightning=>1.6.0 torch==1.8.1 torchvision==0.9.1 torchtext==0.9.1 From 6913bf49e851a3afdcc1733681b68c0f1dcf47af Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Tue, 5 Apr 2022 12:12:56 -0700 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=9B=A0=20Fix=20typo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index fdc9ab5071..da1f734f07 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -13,7 +13,7 @@ opencv-python>=4.5.3.56 opencv-contrib-python==4.5.5.62 pandas~=1.1.5 pillow==9.0.0 -pytorch-lightning=>1.6.0 +pytorch-lightning>=1.6.0 torch==1.8.1 torchvision==0.9.1 torchtext==0.9.1 From de21af5f72fc785bece746ac96cde19e58fccc9a Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Tue, 5 Apr 2022 13:42:23 -0700 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=9B=A0=20Fix=20mypy=20issues.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/utils/callbacks/visualizer_callback.py | 3 ++- anomalib/utils/loggers/wandb.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/anomalib/utils/callbacks/visualizer_callback.py b/anomalib/utils/callbacks/visualizer_callback.py index eb00038a2a..f13079e660 100644 --- a/anomalib/utils/callbacks/visualizer_callback.py +++ b/anomalib/utils/callbacks/visualizer_callback.py @@ -28,6 +28,7 @@ from anomalib.pre_processing.transforms import Denormalize from anomalib.utils import loggers from anomalib.utils.loggers import AnomalibWandbLogger +from anomalib.utils.loggers.base import ImageLoggerBase class VisualizerCallback(Callback): @@ -68,7 +69,7 @@ def _add_images( for log_to in module.hparams.project.log_images_to: if log_to in loggers.AVAILABLE_LOGGERS: # check if logger object is same as the requested object - if log_to in logger_type and module.logger is not None: + if log_to in logger_type and module.logger is not None and isinstance(module.logger, ImageLoggerBase): module.logger.add_image( image=visualizer.figure, name=filename.parent.name + "_" + filename.name, diff --git a/anomalib/utils/loggers/wandb.py b/anomalib/utils/loggers/wandb.py index b5694ed861..ef45766574 100644 --- a/anomalib/utils/loggers/wandb.py +++ b/anomalib/utils/loggers/wandb.py @@ -86,7 +86,7 @@ def __init__( anonymous: Optional[bool] = None, version: Optional[str] = None, project: Optional[str] = None, - log_model: Optional[bool] = False, + log_model: Union[str, bool] = False, experiment=None, prefix: Optional[str] = "", sync_step: Optional[bool] = None, From 403ce71ed2161c8fa6f5366c0b57da2a7e23bf9d Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Wed, 6 Apr 2022 03:56:06 -0700 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=94=84=20Switch=20soft=20permutatio?= =?UTF-8?q?n=20to=20false=20by=20default=20since=20this=20radically=20slow?= =?UTF-8?q?s=20down=20the=20training.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/cflow/backbone.py | 9 +++++++-- anomalib/models/cflow/config.yaml | 1 + anomalib/models/cflow/model.py | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/anomalib/models/cflow/backbone.py b/anomalib/models/cflow/backbone.py index 61650e7319..d0b23c24ee 100644 --- a/anomalib/models/cflow/backbone.py +++ b/anomalib/models/cflow/backbone.py @@ -73,7 +73,9 @@ def subnet_fc(dims_in: int, dims_out: int): return nn.Sequential(nn.Linear(dims_in, 2 * dims_in), nn.ReLU(), nn.Linear(2 * dims_in, dims_out)) -def cflow_head(condition_vector: int, coupling_blocks: int, clamp_alpha: float, n_features: int) -> SequenceINN: +def cflow_head( + condition_vector: int, coupling_blocks: int, clamp_alpha: float, n_features: int, permute_soft: bool = False +) -> SequenceINN: """Create invertible decoder network. Args: @@ -81,6 +83,9 @@ def cflow_head(condition_vector: int, coupling_blocks: int, clamp_alpha: float, coupling_blocks (int): number of coupling blocks to build the decoder clamp_alpha (float): clamping value to avoid exploding values n_features (int): number of decoder features + permute_soft (bool): Whether to sample the permutation matrix :math:`R` from :math:`SO(N)`, + or to use hard permutations instead. Note, ``permute_soft=True`` is very slow + when working with >512 dimensions. Returns: SequenceINN: decoder network block @@ -95,6 +100,6 @@ def cflow_head(condition_vector: int, coupling_blocks: int, clamp_alpha: float, subnet_constructor=subnet_fc, affine_clamping=clamp_alpha, global_affine_type="SOFTPLUS", - permute_soft=True, + permute_soft=permute_soft, ) return coder diff --git a/anomalib/models/cflow/config.yaml b/anomalib/models/cflow/config.yaml index a5adb95804..068abb1608 100644 --- a/anomalib/models/cflow/config.yaml +++ b/anomalib/models/cflow/config.yaml @@ -24,6 +24,7 @@ model: condition_vector: 128 coupling_blocks: 8 clamp_alpha: 1.9 + soft_permutation: false lr: 0.0001 early_stopping: patience: 2 diff --git a/anomalib/models/cflow/model.py b/anomalib/models/cflow/model.py index a605ef5a1d..656c903ef2 100644 --- a/anomalib/models/cflow/model.py +++ b/anomalib/models/cflow/model.py @@ -141,7 +141,13 @@ def __init__(self, hparams: Union[DictConfig, ListConfig]): self.pool_dims = self.encoder.out_dims self.decoders = nn.ModuleList( [ - cflow_head(self.condition_vector, hparams.model.coupling_blocks, hparams.model.clamp_alpha, pool_dim) + cflow_head( + condition_vector=self.condition_vector, + coupling_blocks=hparams.model.coupling_blocks, + clamp_alpha=hparams.model.clamp_alpha, + n_features=pool_dim, + permute_soft=hparams.model.soft_permutation, + ) for pool_dim in self.pool_dims ] ) From 6ea7ff472508caf2a4933a02de3dfbf8dfc9fdf2 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 01:31:09 -0700 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=97=91=20Remove=20`self.automatic?= =?UTF-8?q?=5Foptimization=3DFalse`=20from=20dfkde=20to=20automatically=20?= =?UTF-8?q?set=20`trainer.global=5Fstep`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/dfkde/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/anomalib/models/dfkde/model.py b/anomalib/models/dfkde/model.py index a0cd0c6ad8..4c59b71d2e 100644 --- a/anomalib/models/dfkde/model.py +++ b/anomalib/models/dfkde/model.py @@ -100,7 +100,6 @@ def __init__(self, hparams: Union[DictConfig, ListConfig]): hparams.model.backbone, hparams.model.max_training_points, threshold_steepness, threshold_offset ) - self.automatic_optimization = False self.embeddings: List[Tensor] = [] @staticmethod From 9c7037520685ce75b17d0a3623edf32c32f1a92b Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 01:32:17 -0700 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=97=91=20Remove=20`self.automatic?= =?UTF-8?q?=5Foptimization=3DFalse`=20from=20dfm=20to=20automatically=20se?= =?UTF-8?q?t=20`trainer.global=5Fstep`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/dfm/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/anomalib/models/dfm/model.py b/anomalib/models/dfm/model.py index 944c885677..28a3d22bb7 100644 --- a/anomalib/models/dfm/model.py +++ b/anomalib/models/dfm/model.py @@ -34,7 +34,6 @@ def __init__(self, hparams: Union[DictConfig, ListConfig]): self.model: DFMModel = DFMModel( backbone=hparams.model.backbone, n_comps=hparams.model.pca_level, score_type=hparams.model.score_type ) - self.automatic_optimization = False self.embeddings: List[Tensor] = [] @staticmethod From 70da46bf2e05e4d2863c0a848f372e57bf890aa9 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 01:32:39 -0700 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=97=91=20Remove=20`self.automatic?= =?UTF-8?q?=5Foptimization=3DFalse`=20from=20padim=20to=20automatically=20?= =?UTF-8?q?set=20`trainer.global=5Fstep`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/padim/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/anomalib/models/padim/model.py b/anomalib/models/padim/model.py index ca44b09478..cf371bb1a0 100644 --- a/anomalib/models/padim/model.py +++ b/anomalib/models/padim/model.py @@ -294,7 +294,6 @@ def __init__(self, hparams: Union[DictConfig, ListConfig]): ).eval() self.stats: List[Tensor] = [] - self.automatic_optimization = False self.embeddings: List[Tensor] = [] @staticmethod From 9e865f4375840d6b7e1ea374b6baaa824a00122a Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 01:33:18 -0700 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=97=91=20Remove=20`self.automatic?= =?UTF-8?q?=5Foptimization=3DFalse`=20from=20patchcore=20to=20automaticall?= =?UTF-8?q?y=20set=20`trainer.global=5Fstep`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/patchcore/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/anomalib/models/patchcore/model.py b/anomalib/models/patchcore/model.py index 5e45bb16f4..419f728926 100644 --- a/anomalib/models/patchcore/model.py +++ b/anomalib/models/patchcore/model.py @@ -275,7 +275,6 @@ def __init__(self, hparams) -> None: backbone=hparams.model.backbone, apply_tiling=hparams.dataset.tiling.apply, ) - self.automatic_optimization = False self.embeddings: List[Tensor] = [] def configure_optimizers(self) -> None: From 07e41117c18924e55515ac50942fb49164f2e162 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 02:01:45 -0700 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=94=84=20replace=20`checkpoint=5Fca?= =?UTF-8?q?llback`=20with=20`enable=5Fcheckpointing`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/cflow/config.yaml | 2 +- anomalib/models/dfkde/config.yaml | 2 +- anomalib/models/dfm/config.yaml | 2 +- anomalib/models/ganomaly/config.yaml | 2 +- anomalib/models/padim/config.yaml | 2 +- anomalib/models/patchcore/config.yaml | 2 +- anomalib/models/stfpm/config.yaml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/anomalib/models/cflow/config.yaml b/anomalib/models/cflow/config.yaml index 4dce5832b5..1fef4efd8b 100644 --- a/anomalib/models/cflow/config.yaml +++ b/anomalib/models/cflow/config.yaml @@ -54,9 +54,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/dfkde/config.yaml b/anomalib/models/dfkde/config.yaml index c19c2d31a9..f24452d5bf 100644 --- a/anomalib/models/dfkde/config.yaml +++ b/anomalib/models/dfkde/config.yaml @@ -41,9 +41,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 # Don't validate before extracting features. - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/dfm/config.yaml b/anomalib/models/dfm/config.yaml index 9cbcd1231f..69d7ce4214 100755 --- a/anomalib/models/dfm/config.yaml +++ b/anomalib/models/dfm/config.yaml @@ -40,9 +40,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 # Don't validate before extracting features. - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/ganomaly/config.yaml b/anomalib/models/ganomaly/config.yaml index b18584a6ee..4e69fe37e3 100644 --- a/anomalib/models/ganomaly/config.yaml +++ b/anomalib/models/ganomaly/config.yaml @@ -61,9 +61,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 2 - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/padim/config.yaml b/anomalib/models/padim/config.yaml index 0370326378..bba0aae3ea 100644 --- a/anomalib/models/padim/config.yaml +++ b/anomalib/models/padim/config.yaml @@ -54,9 +54,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 # Don't validate before extracting features. - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/patchcore/config.yaml b/anomalib/models/patchcore/config.yaml index 30fbaf6118..ce565671b5 100644 --- a/anomalib/models/patchcore/config.yaml +++ b/anomalib/models/patchcore/config.yaml @@ -52,9 +52,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 # Don't validate before extracting features. - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 diff --git a/anomalib/models/stfpm/config.yaml b/anomalib/models/stfpm/config.yaml index 7ca654041a..a6c07c4cc8 100644 --- a/anomalib/models/stfpm/config.yaml +++ b/anomalib/models/stfpm/config.yaml @@ -61,9 +61,9 @@ trainer: auto_select_gpus: false benchmark: false check_val_every_n_epoch: 1 - checkpoint_callback: true default_root_dir: null deterministic: false + enable_checkpointing: true fast_dev_run: false gpus: 1 gradient_clip_val: 0 From dc0f9d302e5b60aaa0090a9425a125f93c5dc259 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 06:41:11 -0700 Subject: [PATCH 11/12] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Edit=20`check=5Fval?= =?UTF-8?q?=5Fevery=5Fn=5Fepoch`=20from=202=20=E2=9E=A1=EF=B8=8F=201=20to?= =?UTF-8?q?=20save=20the=20weights?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/ganomaly/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anomalib/models/ganomaly/config.yaml b/anomalib/models/ganomaly/config.yaml index 4e69fe37e3..46ef8daa43 100644 --- a/anomalib/models/ganomaly/config.yaml +++ b/anomalib/models/ganomaly/config.yaml @@ -60,7 +60,7 @@ trainer: auto_scale_batch_size: false auto_select_gpus: false benchmark: false - check_val_every_n_epoch: 2 + check_val_every_n_epoch: 1 default_root_dir: null deterministic: false enable_checkpointing: true From c6f0662c772241b3b2b7a1d7eef616b01dd5dd1e Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Fri, 8 Apr 2022 06:50:30 -0700 Subject: [PATCH 12/12] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Set=20`check=5Fval?= =?UTF-8?q?=5Fevery=5Fn=5Fepoch`=20to=201=20for=20`fast=5Frun`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anomalib/models/ganomaly/config.yaml | 2 +- tests/helpers/model.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/anomalib/models/ganomaly/config.yaml b/anomalib/models/ganomaly/config.yaml index 46ef8daa43..4e69fe37e3 100644 --- a/anomalib/models/ganomaly/config.yaml +++ b/anomalib/models/ganomaly/config.yaml @@ -60,7 +60,7 @@ trainer: auto_scale_batch_size: false auto_select_gpus: false benchmark: false - check_val_every_n_epoch: 1 + check_val_every_n_epoch: 2 default_root_dir: null deterministic: false enable_checkpointing: true diff --git a/tests/helpers/model.py b/tests/helpers/model.py index a1dab835df..d1c53bc10d 100644 --- a/tests/helpers/model.py +++ b/tests/helpers/model.py @@ -109,6 +109,7 @@ def setup_model_train( # Train the model. if fast_run: config.trainer.max_epochs = 1 + config.trainer.check_val_every_n_epoch = 1 trainer = Trainer(callbacks=callbacks, **config.trainer) trainer.fit(model=model, datamodule=datamodule)