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 11 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# Checklist:
## Checklist

- [ ] My code follows the [pre-commit style and check guidelines](https://openvinotoolkit.github.io/anomalib/guides/using_pre_commit.html#pre-commit-hooks) of this project.
- [ ] I have performed a self-review of my code
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ instance/
# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/build/
docs/source/_build/

# PyBuilder
.pybuilder/
target/
Expand Down
4 changes: 4 additions & 0 deletions anomalib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
# See the License for the specific language governing permissions
# and limitations under the License.

from .base import AnomalyModule

__version__ = "0.2.4"

__all__ = ["AnomalyModule"]
19 changes: 19 additions & 0 deletions anomalib/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Base classes for all anomaly components."""

# 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 .anomaly_models import AnomalyModule, DynamicBufferModule

__all__ = ["DynamicBufferModule", "AnomalyModule"]
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions anomalib/base/anomaly_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Base anomaly modules."""

# 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 .anomaly_module import AnomalyModule
from .dynamic_module import DynamicBufferModule

__all__ = ["AnomalyModule", "DynamicBufferModule"]
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
10 changes: 3 additions & 7 deletions anomalib/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Utilities to get configurable parameters."""
"""Utilities for parsing model configuration."""

# Copyright (C) 2020 Intel Corporation
#
Expand All @@ -14,10 +14,6 @@
# See the License for the specific language governing permissions
# and limitations under the License.

from .config import (
get_configurable_parameters,
update_input_size_config,
update_nncf_config,
)
from .config import get_configurable_parameters, update_nncf_config

__all__ = ["get_configurable_parameters", "update_input_size_config", "update_nncf_config"]
__all__ = ["get_configurable_parameters", "update_nncf_config"]
5 changes: 2 additions & 3 deletions anomalib/data/mvtec.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
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 import DownloadProgressBar, read_image
from anomalib.pre_processing import PreProcessor

logger = logging.getLogger(name="Dataset: MVTec")
logger.setLevel(logging.DEBUG)
Expand Down
20 changes: 20 additions & 0 deletions anomalib/data/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Helper utilities for data."""

# 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 .download_progress_bar import DownloadProgressBar
from .image import read_image

__all__ = ["read_image", "DownloadProgressBar"]
2 changes: 1 addition & 1 deletion anomalib/data/utils.py → anomalib/data/utils/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Dataset Utils."""
"""Image Utils."""

# Copyright (C) 2020 Intel Corporation
#
Expand Down
7 changes: 6 additions & 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 All @@ -13,3 +13,8 @@
# 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 .inferencers import OpenVINOInferencer, TorchInferencer
from .optimize import export_convert, get_model_metadata

__all__ = ["OpenVINOInferencer", "TorchInferencer", "export_convert", "get_model_metadata"]
10 changes: 6 additions & 4 deletions anomalib/deploy/inferencers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
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 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,
)


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 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 import AnomalyModule
from anomalib.deploy.optimize import get_model_metadata
from anomalib.models import get_model
from anomalib.pre_processing 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 import AnomalyModule


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 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 import AnomalyModule
from anomalib.models.cflow.backbone import cflow_head, positional_encoding_2d
from anomalib.models.components import FeatureExtractor

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

Expand Down
30 changes: 30 additions & 0 deletions anomalib/models/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Components used within the models."""

# 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 .dimensionality_reduction import PCA, SparseRandomProjection
from .feature_extractors import FeatureExtractor
from .sampling import KCenterGreedy
from .stats import GaussianKDE, MultiVariateGaussian

__all__ = [
"PCA",
"SparseRandomProjection",
"FeatureExtractor",
"KCenterGreedy",
"GaussianKDE",
"MultiVariateGaussian",
]
20 changes: 20 additions & 0 deletions anomalib/models/components/dimensionality_reduction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""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.

from .pca import PCA
from .random_projection import SparseRandomProjection

__all__ = ["PCA", "SparseRandomProjection"]
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.base import DynamicBufferModule


class PCA(DynamicBufferModule):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Anomalib Core Model Entities."""
"""Feature extractors."""

# Copyright (C) 2020 Intel Corporation
#
Expand All @@ -14,6 +14,6 @@
# See the License for the specific language governing permissions
# and limitations under the License.

from .anomaly_module import AnomalyModule
from .feature_extractor import FeatureExtractor

__all__ = ["AnomalyModule"]
__all__ = ["FeatureExtractor"]
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."""
"""Sampling methods."""

# Copyright (C) 2020 Intel Corporation
#
Expand All @@ -13,3 +13,7 @@
# 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,7 @@
import torch.nn.functional as F
from torch import Tensor

from anomalib.core.model.random_projection import SparseRandomProjection
from anomalib.models.components.dimensionality_reduction import SparseRandomProjection
samet-akcay marked this conversation as resolved.
Show resolved Hide resolved


class KCenterGreedy:
Expand Down
20 changes: 20 additions & 0 deletions anomalib/models/components/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""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.

from .kde import GaussianKDE
from .multi_variate_gaussian import MultiVariateGaussian

__all__ = ["GaussianKDE", "MultiVariateGaussian"]
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.base import DynamicBufferModule


class GaussianKDE(DynamicBufferModule):
Expand Down
7 changes: 4 additions & 3 deletions anomalib/models/dfkde/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +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.dfkde.normality_model import NormalityModel
from anomalib import AnomalyModule
from anomalib.models.components import FeatureExtractor

from .normality_model import NormalityModel


class DfkdeLightning(AnomalyModule):
Expand Down
3 changes: 1 addition & 2 deletions anomalib/models/dfkde/normality_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
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 import PCA, GaussianKDE


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.base import DynamicBufferModule
from anomalib.models.components import PCA


class SingleClassGaussian(DynamicBufferModule):
Expand Down
Loading