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

Benchmarking Script #17

Merged
merged 53 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
dfee44e
Initial benchmarking script
Dec 3, 2021
c83f076
Merge branch 'development' into feature/ashwin/benchmarking_tools
Dec 3, 2021
198f11e
Finish benchmarking script.
Dec 3, 2021
1e04cb5
Fix param initialization
Dec 3, 2021
65e3361
Add tqdm
Dec 6, 2021
581c5dc
Fix license issue + add license to callbacks init
Dec 9, 2021
855db66
Add OpenVINO throughput
Dec 10, 2021
6b78c02
Merge branch 'development' into feature/ashwin/benchmarking_tools
Dec 30, 2021
9f143ac
Move pull request template to .github root
Dec 30, 2021
9e8ead8
Refactor Benchmarking script.
Jan 3, 2022
07c1b3c
Add tests
Jan 5, 2022
7924781
First round of refactor
Jan 6, 2022
eca1b7b
🔀 Merge branch 'feature/refactor' into feature/ashwin/benchmarking_tools
Jan 20, 2022
11cab37
🔀 Merge branch 'development' into feature/refactor
Jan 20, 2022
8366c1b
🔀 Merge branch 'feature/refactor' into feature/ashwin/benchmarking_tools
Jan 20, 2022
2875d58
🔥 Remove merge artefacts
Jan 20, 2022
3bdec07
Merge branch 'development' into feature/refactor
Jan 26, 2022
e59a34d
🔨 fix merge issues
Jan 26, 2022
e3a156b
🚚 Move components to model
Jan 26, 2022
a70ee32
🔥 remove artifacts from merge
Jan 26, 2022
239a670
Rename logger name
Jan 26, 2022
bb68181
🔨 Add wandb to pyproject config
Jan 26, 2022
2a40d08
Address PR comments
ashwinvaidya17 Jan 31, 2022
398aaad
Fix black version
ashwinvaidya17 Jan 31, 2022
9933862
🔀 Merge branch 'feature/refactor' into feature/ashwin/benchmarking_tools
ashwinvaidya17 Feb 1, 2022
dab9bc0
🔥 remove duplicate files + revert auc changes
ashwinvaidya17 Feb 1, 2022
e4d5b50
Fix license + minor refactor
ashwinvaidya17 Feb 1, 2022
31c2f16
Fix imports
ashwinvaidya17 Feb 1, 2022
bb633c3
Merge branch 'feature/refactor' into feature/ashwin/benchmarking_tools
ashwinvaidya17 Feb 1, 2022
d7790d0
Merge branch 'feature/ashwin/benchmarking_tools' of github.com:openvi…
Feb 1, 2022
68718be
Fix imports + seed
Feb 1, 2022
5bab555
Address PR comment + refactor script
Feb 4, 2022
c9b708b
🩹 Minor fixes
Feb 4, 2022
1322401
add spawn to context
Feb 7, 2022
472d6c1
isort
samet-akcay Feb 7, 2022
b06b517
Properly import AnomalyModule
samet-akcay Feb 7, 2022
ade82c0
Fix circular import
samet-akcay Feb 7, 2022
70041b1
Import Inference dataset
samet-akcay Feb 7, 2022
53bd2b5
address pre-commit
samet-akcay Feb 7, 2022
442636f
Rebase development
samet-akcay Feb 7, 2022
1030543
Rebase development
samet-akcay Feb 7, 2022
1be3443
Log csv to wandb
Feb 8, 2022
85eda00
🔥 remove redundant files from merge
Feb 8, 2022
2d44977
🔨 Fix linting issues
Feb 8, 2022
22455dc
🔥 remove duplicate tests from development merge
Feb 8, 2022
35dffec
fix cyclic imports reported by pylint
samet-akcay Feb 8, 2022
f8227f3
absolute import of AnomalyModule
samet-akcay Feb 8, 2022
8f37fca
Moved anomaly module and dynamic module out of base.anomaly_models
samet-akcay Feb 8, 2022
4f9d6a5
import AnomalyModule and DynamicBufferModule from anomalib.models.com…
samet-akcay Feb 8, 2022
b7ca2fe
reduced coverag percentage
samet-akcay Feb 8, 2022
89ed5a7
🔀 Merge branch 'feature/refactor' into feature/ashwin/benchmarking_tools
Feb 8, 2022
0ce4e0f
pull development and resolve conflicts
samet-akcay Feb 8, 2022
16e8b39
Move metrics calculation to benchmark.py
Feb 8, 2022
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"]
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
4 changes: 2 additions & 2 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 @@ -20,4 +20,4 @@
update_nncf_config,
)

__all__ = ["get_configurable_parameters", "update_input_size_config", "update_nncf_config"]
__all__ = ["get_configurable_parameters", "update_nncf_config", "update_input_size_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
5 changes: 5 additions & 0 deletions anomalib/deploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"]
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,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


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
7 changes: 4 additions & 3 deletions anomalib/models/dfm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +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.dfm.dfm_model import DFMModel
from anomalib import AnomalyModule
from anomalib.models.components import FeatureExtractor

from .dfm_model import DFMModel


class DfmLightning(AnomalyModule):
Expand Down
Loading