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

Fix packaging and Address pre-commit updates. #2173

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
Expand All @@ -15,7 +15,7 @@ repos:

# Ruff version.
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.5"
rev: "v0.5.0"
hooks:
# Run the linter.
- id: ruff
Expand All @@ -27,35 +27,35 @@ repos:

# python static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.0"
rev: "v1.10.1"
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-setuptools]
exclude: "tests"

# add bandit for security checks
- repo: https://github.com/PyCQA/bandit
rev: 1.7.7
rev: 1.7.9
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

# notebooks.
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.8.5
hooks:
- id: nbqa-ruff
# Ignore unsorted imports. This is because jupyter notebooks can import
# packages in a different order than the rest of the codebase.
args: ["--ignore=D100,D407,I001"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
rev: v0.41.0
hooks:
- id: markdownlint
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- Remove deprecated `pkg_resources` dependencies, install `packaging` instead by @davnn in (<https://github.com/openvinotoolkit/anomalib/pull/2082>)
- WinCLIP: set device in text embedding collection and apply forward pass with no grad, by @djdameln in https://github.com/openvinotoolkit/anomalib/pull/1984
- πŸ”¨ Move all export functionalities to AnomalyModule as base methods by @thinhngo-x in (<https://github.com/openvinotoolkit/anomalib/pull/1803>)
- ⬆️ Update torch and lightning package versions by @samet-akcay in https://github.com/openvinotoolkit/anomalib/pull/1949
- πŸ”¨ Use default model-specific eval transform when only train_transform specified by @djdameln(https://github.com/djdameln) in (<https://github.com/openvinotoolkit/anomalib/pull/1953>)
Expand Down
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We welcome contributions from everyone. If you're interested in helping out, ple
Here is a list of contributors of Anomalib:

<a href="https://github.com/openvinotoolkit/anomalib/graphs/contributors">
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" />
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" alt="Contributors to openvinotoolkit/anomalib" />
</a>

## πŸ™ Acknowledgements
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

<img src="https://github.com/raw/openvinotoolkit/anomalib/main/docs/source/_static/images/logos/anomalib-wide-blue.png" width="600px">
<img src="https://github.com/raw/openvinotoolkit/anomalib/main/docs/source/_static/images/logos/anomalib-wide-blue.png" width="600px" alt="Anomalib Logo">

**A library for benchmarking, developing and deploying deep learning anomaly detection algorithms**

Expand Down Expand Up @@ -30,7 +30,7 @@
Anomalib is a deep learning library that aims to collect state-of-the-art anomaly detection algorithms for benchmarking on both public and private datasets. Anomalib provides several ready-to-use implementations of anomaly detection algorithms described in the recent literature, as well as a set of tools that facilitate the development and implementation of custom models. The library has a strong focus on visual anomaly detection, where the goal of the algorithm is to detect and/or localize anomalies within images or videos in a dataset. Anomalib is constantly updated with new algorithms and training/inference extensions, so keep checking!

<p align="center">
<img src="https://github.com/raw/openvinotoolkit/anomalib/main/docs/source/_static/images/readme.png" width="1000">
<img src="https://github.com/raw/openvinotoolkit/anomalib/main/docs/source/_static/images/readme.png" width="1000" alt="A prediction made by anomalib">
</p>

## Key features
Expand Down Expand Up @@ -304,5 +304,5 @@ For those who would like to contribute to the library, see [CONTRIBUTING.md](CON
Thank you to all of the people who have already made a contribution - we appreciate your support!

<a href="https://github.com/openvinotoolkit/anomalib/graphs/contributors">
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" />
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" alt="Contributors to openvinotoolkit/anomalib" />
</a>
4 changes: 2 additions & 2 deletions notebooks/500_use_cases/501_dobot/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dobot Use Case Tutorial

| Notebook | | |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
| Notebook | Link |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Training a Model | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) |
| Inference with the Model | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501b_inference_with_a_robotic_arm.ipynb) |

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"jsonargparse[signatures]>=4.27.7",
"docstring_parser", # CLI help-formatter
"rich_argparse", # CLI help-formatter
"packaging"
]

[project.optional-dependencies]
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from importlib import import_module
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from enum import Enum
from typing import Any
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/nncf/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import subprocess # nosec B404
from pathlib import Path
from typing import TYPE_CHECKING, Any
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/nncf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from copy import copy
from typing import TYPE_CHECKING, Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from typing import Any

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from typing import Any

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/tiler_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from collections.abc import Sequence

import lightning.pytorch as pl
Expand Down
10 changes: 3 additions & 7 deletions src/anomalib/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

import logging

from pkg_resources import Requirement
from packaging.version import parse
from rich.console import Console
from rich.logging import RichHandler

from anomalib.cli.utils.installation import (
get_requirements,
get_torch_install_args,
parse_requirements,
)
from anomalib.cli.utils.installation import get_requirements, get_torch_install_args, parse_requirements

logger = logging.getLogger("pip")
logger.setLevel(logging.WARNING) # setLevel: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET
Expand Down Expand Up @@ -50,7 +46,7 @@ def anomalib_install(option: str = "full", verbose: bool = False) -> int:
elif option in requirements_dict:
requirements.extend(requirements_dict[option])
elif option is not None:
requirements.append(Requirement.parse(option))
requirements.append(parse(option))

# Parse requirements into torch and other requirements.
# This is done to parse the correct version of torch (cpu/cuda).
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/cli/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging

from jsonargparse import Namespace
Expand Down
28 changes: 16 additions & 12 deletions src/anomalib/cli/utils/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import re
from importlib.metadata import requires
from pathlib import Path
from typing import TYPE_CHECKING
from warnings import warn

from pkg_resources import Requirement
from packaging.version import parse

if TYPE_CHECKING:
from packaging.requirements import Requirement

AVAILABLE_TORCH_VERSIONS = {
"2.0.0": {"torchvision": "0.15.1", "cuda": ("11.7", "11.8")},
Expand Down Expand Up @@ -50,7 +54,7 @@ def get_requirements(module: str = "anomalib") -> dict[str, list[Requirement]]:
if isinstance(requirement_extra, list) and len(requirement_extra) > 1:
extra = requirement_extra[-1].split("==")[-1].strip("'\"")
_requirement_name = requirement_extra[0]
_requirement = Requirement.parse(_requirement_name)
_requirement = parse(_requirement_name)
if extra in extra_requirement:
extra_requirement[extra].append(_requirement)
else:
Expand All @@ -73,12 +77,12 @@ def parse_requirements(

Examples:
>>> requirements = [
... Requirement.parse("torch==1.13.0"),
... Requirement.parse("onnx>=1.8.1"),
... parse("torch==1.13.0"),
... parse("onnx>=1.8.1"),
... ]
>>> parse_requirements(requirements=requirements)
(Requirement.parse("torch==1.13.0"),
Requirement.parse("onnx>=1.8.1"))
(parse("torch==1.13.0"),
parse("onnx>=1.8.1"))

Returns:
tuple[str, list[str], list[str]]: Tuple of torch and other requirements.
Expand Down Expand Up @@ -293,9 +297,9 @@ def add_hardware_suffix_to_torch(
Defaults to False.

Examples:
>>> from pkg_resources import Requirement
>>> from packaging.requirements import Requirement
>>> req = "torch>=1.13.0, <=2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> requirement.name, requirement.specs
('torch', [('>=', '1.13.0'), ('<=', '2.0.1')])

Expand All @@ -304,13 +308,13 @@ def add_hardware_suffix_to_torch(

``with_available_torch_build=True`` will use the latest available PyTorch build.
>>> req = "torch==2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> add_hardware_suffix_to_torch(requirement, with_available_torch_build=True)
'torch==2.0.1+cu118'

It is possible to pass the ``hardware_suffix`` manually.
>>> req = "torch==2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> add_hardware_suffix_to_torch(requirement, hardware_suffix="cu121")
'torch==2.0.1+cu111'

Expand Down Expand Up @@ -364,7 +368,7 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]:
RuntimeError: If the OS is not supported.

Example:
>>> from pkg_resources import Requirement
>>> from packaging.requirements import Requirement
>>> requriment = "torch>=1.13.0"
>>> get_torch_install_args(requirement)
['--extra-index-url', 'https://download.pytorch.org/whl/cpu',
Expand All @@ -374,7 +378,7 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]:
list[str]: The install arguments.
"""
if isinstance(requirement, str):
requirement = Requirement.parse(requirement)
requirement = parse(requirement)

# NOTE: This does not take into account if the requirement has multiple versions
# such as torch<2.0.1,>=1.13.0
Expand Down
3 changes: 1 addition & 2 deletions src/anomalib/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
)


class UnknownDatamoduleError(ModuleNotFoundError):
...
class UnknownDatamoduleError(ModuleNotFoundError): ...


def get_datamodule(config: DictConfig | ListConfig | dict) -> AnomalibDataModule:
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from .datamodule import AnomalibDataModule
from .dataset import AnomalibDataset
from .depth import AnomalibDepthDataset
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/base/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from abc import ABC, abstractmethod
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from enum import Enum

from .folder_3d import Folder3D
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/folder_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from pathlib import Path

from pandas import DataFrame, isna
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/mvtec_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from collections.abc import Sequence
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from enum import Enum

from .btech import BTech
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/image/visa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# Subset splitting code adapted from https://github.com/amazon-science/spot-diff
# Original licence: Apache-2.0


import csv
import logging
import shutil
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from pathlib import Path
from typing import Any

Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/augmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import math
import random
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import torch

from anomalib.utils.cv import connected_components_cpu, connected_components_gpu
Expand Down
Loading
Loading