Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/pre_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
with:
python-version: "3.10"
python-version: "3.13"
- name: Install Tox
run: pip install tox
- name: Code quality checks
Expand All @@ -45,6 +45,8 @@ jobs:
include:
- python-version: "3.10"
tox-env: "py310"
- python-version: "3.13"
tox-env: "py313"
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/guides/developer/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Set up your development environment to start contributing. This involves install
1. Create and activate a new Conda environment:

```bash
conda create -n anomalib_dev python=3.10
conda create -n anomalib_dev python>=3.10
conda activate anomalib_dev
```

Expand Down
2 changes: 1 addition & 1 deletion docs/source/snippets/install/source.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use of virtual environment is highy recommended
# Using conda
yes | conda create -n anomalib_env python=3.10
yes | conda create -n anomalib_env python>=3.10
conda activate anomalib_env

# Or using your favorite virtual environment
Expand Down
97 changes: 50 additions & 47 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
Expand Down Expand Up @@ -100,19 +100,19 @@ test = [
]
# PyTorch dependency groups
cpu = [
"torch>=2.4.0,<=2.8.0",
"torch>=2.4.0",
"torchvision>=0.19.0",
]
cu118 = [
"torch>=2.4.0,<=2.8.0",
"torchvision>=0.19.0",
"torch>=2.4.0,<=2.5.1 ; python_version < '3.13'",
"torchvision>=0.19.0 ; python_version < '3.13'",
]
cu121 = [
"torch>=2.4.0,<=2.8.0",
"torchvision>=0.19.0",
"torch>=2.4.0 ; python_version < '3.13'",
"torchvision>=0.19.0 ; python_version < '3.13'",
]
cu124 = [
"torch>=2.4.0,<=2.8.0",
"torch>=2.4.0",
"torchvision>=0.19.0",
]
cu130 = [
Expand Down Expand Up @@ -238,6 +238,44 @@ pytorch-triton-xpu = [
# Enable preview features
preview = true

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 120

# Assume Python 3.10.
target-version = "py310"

# Allow imports relative to the "src" and "tests" directories.
src = ["src", "tests"]

[tool.ruff.lint]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Enable rules
select = [
"F", # Pyflakes (`F`)
Expand Down Expand Up @@ -292,6 +330,7 @@ select = [

ignore = [
# pydocstyle
"COM812",
"D107", # Missing docstring in __init__

# pylint
Expand Down Expand Up @@ -346,57 +385,21 @@ ignore = [
fixable = ["ALL"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 120

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

# Allow imports relative to the "src" and "tests" directories.
src = ["src", "tests"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 15


[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.flake8-copyright]
[tool.ruff.lint.flake8-copyright]
notice-rgx = """
# Copyright \\(C\\) (\\d{4}(-\\d{4})?) Intel Corporation
# SPDX-License-Identifier: Apache-2\\.0
"""

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"examples/notebooks/**/*" = ["CPY001"]

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
8 changes: 4 additions & 4 deletions src/anomalib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
with a focus on reproducibility and ease of use.
"""

from enum import Enum
from enum import StrEnum

__version__ = "2.3.0dev"


class LearningType(str, Enum):
class LearningType(StrEnum):
"""Learning type defining how the model learns from the dataset samples.
This enum defines the different learning paradigms supported by anomalib models:
Expand All @@ -62,7 +62,7 @@ class LearningType(str, Enum):
FEW_SHOT = "few_shot"


class TaskType(str, Enum):
class TaskType(StrEnum):
"""Task type defining the model's prediction output format.
This enum defines the different task types supported by anomalib models:
Expand All @@ -88,7 +88,7 @@ class TaskType(str, Enum):
SEGMENTATION = "segmentation"


class PrecisionType(str, Enum):
class PrecisionType(StrEnum):
"""Precision type defining the numerical precision used in model computations.
This enum defines the different precision types supported by anomalib models:
Expand Down
5 changes: 4 additions & 1 deletion src/anomalib/data/dataclasses/numpy/depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
(224, 224)
"""

from collections.abc import Callable
from dataclasses import dataclass
from typing import ClassVar

import numpy as np

Expand Down Expand Up @@ -65,6 +67,7 @@ class NumpyDepthItem(
"""


@dataclass
class NumpyDepthBatch(
BatchIterateMixin[NumpyDepthItem],
NumpyDepthBatchValidator,
Expand All @@ -87,4 +90,4 @@ class NumpyDepthBatch(
tensor-like fields.
"""

item_class = NumpyDepthItem
item_class: ClassVar[Callable] = NumpyDepthItem
5 changes: 3 additions & 2 deletions src/anomalib/data/dataclasses/torch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

from anomalib.data.dataclasses.generic import ImageT, _GenericBatch, _GenericItem

NumpyT = TypeVar("NumpyT")


class InferenceBatch(NamedTuple):
"""Batch for use in torch and inference models.
Expand All @@ -43,6 +41,9 @@ class InferenceBatch(NamedTuple):
pred_mask: torch.Tensor | None = None


NumpyT = TypeVar("NumpyT")


@dataclass
class ToNumpyMixin(Generic[NumpyT]):
"""Mixin for converting torch-based dataclasses to numpy.
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/datamodules/depth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

"""Anomalib Depth Data Modules."""

from enum import Enum
from enum import StrEnum

from .adam_3d import ADAM3D
from .folder_3d import Folder3D
from .mvtec_3d import MVTec3D


class DepthDataFormat(str, Enum):
class DepthDataFormat(StrEnum):
"""Supported Depth Dataset Types."""

MVTEC_3D = "mvtec_3d"
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/datamodules/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
... )
"""

from enum import Enum
from enum import StrEnum

from .bmad import BMAD
from .btech import BTech
Expand All @@ -46,7 +46,7 @@
from .visa import Visa


class ImageDataFormat(str, Enum):
class ImageDataFormat(StrEnum):
"""Supported Image Dataset Types.
The following dataset formats are supported:
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/datamodules/video/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
... )
"""

from enum import Enum
from enum import StrEnum

from .avenue import Avenue
from .shanghaitech import ShanghaiTech
from .ucsd_ped import UCSDped


class VideoDataFormat(str, Enum):
class VideoDataFormat(StrEnum):
"""Supported Video Dataset Types.

The following dataset formats are supported:
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/datasets/base/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from abc import ABC
from collections.abc import Callable
from enum import Enum
from enum import StrEnum

import torch
from pandas import DataFrame
Expand All @@ -36,7 +36,7 @@
from .image import AnomalibDataset


class VideoTargetFrame(str, Enum):
class VideoTargetFrame(StrEnum):
"""Target frame for a video-clip.

Used in multi-frame models to determine which frame's ground truth information
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/datasets/image/mvtecad2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""

from collections.abc import Sequence
from enum import Enum
from enum import StrEnum
from pathlib import Path

from pandas import DataFrame
Expand All @@ -40,7 +40,7 @@
from anomalib.data.utils import Split, validate_path


class TestType(str, Enum):
class TestType(StrEnum):
"""Type of test set to use.

The MVTec AD 2 dataset provides three different test sets:
Expand Down
7 changes: 1 addition & 6 deletions src/anomalib/data/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import logging
import os
import re
import sys
import tarfile
from collections.abc import Iterable
from dataclasses import dataclass
Expand Down Expand Up @@ -194,11 +193,7 @@ def safe_extract(tar_file: TarFile, root: Path, members: list[TarInfo]) -> None:
for member in members:
# check if the file already exists
if not (root / member.name).exists():
if sys.version_info[:3] >= (3, 11, 4):
# filter argument only works with python>=3.11.4
tar_file.extract(member, root, filter="data")
else:
tar_file.extract(member, root)
tar_file.extract(member, root, filter="data")


def generate_hash(file_path: str | Path, algorithm: str = "sha256") -> str:
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/data/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
import logging
import os
import re
from enum import Enum
from enum import StrEnum
from pathlib import Path

from torchvision.datasets.folder import IMG_EXTENSIONS

logger = logging.getLogger(__name__)


class DirType(str, Enum):
class DirType(StrEnum):
"""Directory type names for organizing anomaly detection datasets.

Attributes:
Expand Down
Loading
Loading