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

Refactor #87

Merged
merged 24 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
23 changes: 0 additions & 23 deletions anomalib/config/__init__.py

This file was deleted.

6 changes: 3 additions & 3 deletions anomalib/data/mvtec.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
from torch.utils.data.dataset import Dataset
from torchvision.datasets.folder import VisionDataset

from anomalib.data.transforms import PreProcessor
from anomalib.data.utils import read_image
from anomalib.utils.download_progress_bar import DownloadProgressBar
from anomalib.data.utils.download_progress_bar import DownloadProgressBar
from anomalib.pre_processing import PreProcessor
from anomalib.utils.image import read_image
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved

logger = logging.getLogger(name="Dataset: MVTec")
logger.setLevel(logging.DEBUG)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for configuration getters/setters."""
"""Helper utilities for data."""

# Copyright (C) 2020 Intel Corporation
#
Expand Down
2 changes: 1 addition & 1 deletion anomalib/deploy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Utilities for inference and deployment."""
"""Functions for Inference and model deployment."""

# Copyright (C) 2020 Intel Corporation
#
Expand Down
12 changes: 7 additions & 5 deletions anomalib/deploy/inferencers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
from omegaconf import DictConfig, OmegaConf
from torch import Tensor

from anomalib.data.utils import read_image
from anomalib.utils.normalization.cdf import normalize as normalize_cdf
from anomalib.utils.normalization.cdf import standardize
from anomalib.utils.normalization.min_max import normalize as normalize_min_max
from anomalib.utils.post_process import superimpose_anomaly_map
from anomalib.post_processing.normalization.cdf import normalize as normalize_cdf
from anomalib.post_processing.normalization.cdf import standardize
from anomalib.post_processing.normalization.min_max import (
normalize as normalize_min_max,
)
from anomalib.post_processing.post_process import superimpose_anomaly_map
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
from anomalib.utils.image import read_image


class Inferencer(ABC):
Expand Down
2 changes: 1 addition & 1 deletion anomalib/deploy/inferencers/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from omegaconf import DictConfig, ListConfig
from openvino.inference_engine import IECore # pylint: disable=no-name-in-module

from anomalib.data.transforms.pre_process import PreProcessor
from anomalib.pre_processing.pre_process import PreProcessor

from .base import Inferencer

Expand Down
4 changes: 2 additions & 2 deletions anomalib/deploy/inferencers/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from omegaconf import DictConfig, ListConfig
from torch import Tensor

from anomalib.core.model import AnomalyModule
from anomalib.data.transforms.pre_process import PreProcessor
from anomalib.deploy.optimize import get_model_metadata
from anomalib.models import get_model
from anomalib.models.components.anomaly_models import AnomalyModule
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
from anomalib.pre_processing.pre_process import PreProcessor

from .base import Inferencer

Expand Down
2 changes: 1 addition & 1 deletion anomalib/deploy/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import torch
from torch import Tensor

from anomalib.core.model.anomaly_module import AnomalyModule
from anomalib.models.components.anomaly_models import AnomalyModule
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved


def get_model_metadata(model: AnomalyModule) -> Dict[str, Tensor]:
Expand Down
2 changes: 1 addition & 1 deletion anomalib/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from omegaconf import DictConfig, ListConfig
from torch import load

from anomalib.core.model import AnomalyModule
from anomalib.models.components.anomaly_models import AnomalyModule


def get_model(config: Union[DictConfig, ListConfig]) -> AnomalyModule:
Expand Down
1 change: 0 additions & 1 deletion anomalib/models/cflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ All results gathered with seed `42`.
![Sample Result 2](../../../docs/source/images/cflow/results/1.png "Sample Result 2")

![Sample Result 3](../../../docs/source/images/cflow/results/2.png "Sample Result 3")

4 changes: 2 additions & 2 deletions anomalib/models/cflow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from pytorch_lightning.callbacks import EarlyStopping
from torch import Tensor, nn, optim

from anomalib.core.model import AnomalyModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.models.cflow.backbone import cflow_head, positional_encoding_2d
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.feature_extractors import FeatureExtractor

__all__ = ["AnomalyMapGenerator", "CflowModel", "CflowLightning"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module holds common components such as callbacks, custom modules and utils."""
"""Components used within the models."""

# Copyright (C) 2020 Intel Corporation
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Anomalib Core Model Entities."""
"""Anomalib library for research and benchmarking."""

# Copyright (C) 2020 Intel Corporation
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from torch import Tensor, nn
from torchmetrics import F1, MetricCollection

from anomalib.core.metrics import (
from anomalib.utils.metrics import (
AUROC,
AdaptiveThreshold,
AnomalyScoreDistribution,
Expand Down
15 changes: 15 additions & 0 deletions anomalib/models/components/dimensionality_reduction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Algorithms for decomposition and dimensionality reduction."""

# Copyright (C) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import torch
from torch import Tensor

from anomalib.core.model.dynamic_module import DynamicBufferModule
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
from anomalib.models.components.anomaly_models.dynamic_module import DynamicBufferModule


class PCA(DynamicBufferModule):
Expand Down
19 changes: 19 additions & 0 deletions anomalib/models/components/feature_extractors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Feature extractors."""

# Copyright (C) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.

from .feature_extractor import FeatureExtractor

__all__ = ["FeatureExtractor"]
19 changes: 19 additions & 0 deletions anomalib/models/components/sampling/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Sampling methods."""

# Copyright (C) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.

from .k_center_greedy import KCenterGreedy

__all__ = ["KCenterGreedy"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import torch.nn.functional as F
from torch import Tensor

from anomalib.core.model.random_projection import SparseRandomProjection
from anomalib.models.components.dimensionality_reduction.random_projection import (
SparseRandomProjection,
)


class KCenterGreedy:
Expand Down
15 changes: 15 additions & 0 deletions anomalib/models/components/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Statistical functions."""

# Copyright (C) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import torch
from torch import Tensor

from anomalib.core.model.dynamic_module import DynamicBufferModule
from anomalib.models.components.anomaly_models.dynamic_module import DynamicBufferModule


class GaussianKDE(DynamicBufferModule):
Expand Down
6 changes: 4 additions & 2 deletions anomalib/models/dfkde/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
from omegaconf.dictconfig import DictConfig
from omegaconf.listconfig import ListConfig

from anomalib.core.model import AnomalyModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.feature_extractors.feature_extractor import (
FeatureExtractor,
)
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
from anomalib.models.dfkde.normality_model import NormalityModel


Expand Down
4 changes: 2 additions & 2 deletions anomalib/models/dfkde/normality_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import torch
from torch import Tensor, nn

from anomalib.core.model.kde import GaussianKDE
from anomalib.core.model.pca import PCA
from anomalib.models.components.dimensionality_reduction.pca import PCA
from anomalib.models.components.stats.kde import GaussianKDE
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved


class NormalityModel(nn.Module):
Expand Down
4 changes: 2 additions & 2 deletions anomalib/models/dfm/dfm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import torch
from torch import Tensor, nn

from anomalib.core.model.dynamic_module import DynamicBufferModule
from anomalib.core.model.pca import PCA
from anomalib.models.components.anomaly_models.dynamic_module import DynamicBufferModule
from anomalib.models.components.dimensionality_reduction.pca import PCA


class SingleClassGaussian(DynamicBufferModule):
Expand Down
6 changes: 4 additions & 2 deletions anomalib/models/dfm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
from omegaconf import DictConfig, ListConfig
from torch import Tensor

from anomalib.core.model import AnomalyModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.feature_extractors.feature_extractor import (
FeatureExtractor,
)
from anomalib.models.dfm.dfm_model import DFMModel


Expand Down
10 changes: 6 additions & 4 deletions anomalib/models/padim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
from omegaconf import DictConfig, ListConfig
from torch import Tensor, nn

from anomalib.core.model import AnomalyModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.core.model.multi_variate_gaussian import MultiVariateGaussian
from anomalib.data.tiler import Tiler
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.feature_extractors.feature_extractor import (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from anomalib.models.components.feature_extractors import FeatureExtractor

FeatureExtractor,
)
from anomalib.models.components.stats.multi_variate_gaussian import MultiVariateGaussian
from anomalib.pre_processing.tiler import Tiler

__all__ = ["PadimLightning"]

Expand Down
10 changes: 5 additions & 5 deletions anomalib/models/patchcore/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from omegaconf import ListConfig
from torch import Tensor, nn

from anomalib.core.model import AnomalyModule
from anomalib.core.model.dynamic_module import DynamicBufferModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.core.model.k_center_greedy import KCenterGreedy
from anomalib.data.tiler import Tiler
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.anomaly_models.dynamic_module import DynamicBufferModule
from anomalib.models.components.feature_extractors import FeatureExtractor
from anomalib.models.components.sampling import KCenterGreedy
from anomalib.pre_processing.tiler import Tiler


class AnomalyMapGenerator:
Expand Down
8 changes: 5 additions & 3 deletions anomalib/models/stfpm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
from pytorch_lightning.callbacks import EarlyStopping
from torch import Tensor, nn, optim

from anomalib.core.model import AnomalyModule
from anomalib.core.model.feature_extractor import FeatureExtractor
from anomalib.data.tiler import Tiler
from anomalib.models.components.anomaly_models import AnomalyModule
from anomalib.models.components.feature_extractors.feature_extractor import (
FeatureExtractor,
)
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
from anomalib.pre_processing.tiler import Tiler

__all__ = ["Loss", "AnomalyMapGenerator", "STFPMModel", "StfpmLightning"]

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions anomalib/pre_processing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Utilities for pre-processing the input before passing to the model."""

# Copyright (C) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.

from .pre_process import PreProcessor
from .tiler import Tiler

__all__ = ["PreProcessor", "Tiler"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
# and limitations under the License.

from .custom import Denormalize, ToNumpy
from .pre_process import PreProcessor

__all__ = ["Denormalize", "PreProcessor", "ToNumpy"]
__all__ = ["Denormalize", "ToNumpy"]
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_callbacks(config: Union[ListConfig, DictConfig]) -> List[Callback]:
if config.optimization.nncf.apply:
# NNCF wraps torch's jit which conflicts with kornia's jit calls.
# Hence, nncf is imported only when required
nncf_module = import_module("anomalib.core.callbacks.nncf_callback")
nncf_module = import_module("anomalib.utils.callbacks.nncf_callback")
nncf_callback = getattr(nncf_module, "NNCFCallback")
callbacks.append(
nncf_callback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from torch.distributions import LogNormal

from anomalib.models import get_model
from anomalib.utils.normalization.cdf import normalize, standardize
from anomalib.post_processing.normalization.cdf import normalize, standardize


class CdfNormalizationCallback(Callback):
Expand Down
Loading