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

Add: fix image transform to float #1902

Merged
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
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Before you submit your pull request, please make sure you have completed the fol
- [ ] πŸ“š I have made the necessary updates to the documentation (if applicable).
- [ ] πŸ§ͺ I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the [Code Review Checklist](../docs/source/markdown/guides/developer/code_review_checklist.md).
For more information about code review checklists, see the [Code Review Checklist](https://github.com/openvinotoolkit/anomalib/blob/main/docs/source/markdown/guides/developer/code_review_checklist.md).
7 changes: 7 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ jobs:
with:
name: coverage
path: .tox/coverage.xml
md-dead-link-check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: AlexanderDokuchaev/[email protected]
with:
config: pyproject.toml
8 changes: 8 additions & 0 deletions .github/workflows/pre_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ jobs:
else
./codecov -t "${CODECOV_TOKEN}" --sha $COMMIT_ID -U $HTTP_PROXY -f .tox/coverage.xml
fi

md-dead-link-check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: AlexanderDokuchaev/[email protected]
with:
config: pyproject.toml
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ However, make sure to address any pre-commit issues before finalizing your pull

### Making Changes

1. **Write Code:** Follow the project's coding standards and write your code with clear intent. Ensure your code is well-documented and includes examples where appropriate. For code quality we use ruff, whose configuration is in [`pyproject.toml`](https://github.com/openvinotoolkit/anomalib/blob/main/pyproject.toml) file.
1. **Write Code:** Follow the project's coding standards and write your code with clear intent. Ensure your code is well-documented and includes examples where appropriate. For code quality we use ruff, whose configuration is in [`pyproject.toml`](pyproject.toml) file.

2. **Add Tests:** If your code includes new functionality, add corresponding tests using [pytest](https://docs.pytest.org/en/7.4.x/) to maintain coverage and reliability.

Expand All @@ -99,7 +99,7 @@ However, make sure to address any pre-commit issues before finalizing your pull
pytest tests/
```

5. **Update the Changelog:** For significant changes, add a summary to the [CHANGELOG](https://github.com/openvinotoolkit/anomalib/blob/main/CHANGELOG.md).
5. **Update the Changelog:** For significant changes, add a summary to the [CHANGELOG](CHANGELOG.md).

6. **Check Licensing:** Ensure you own the code or have rights to use it, adhering to appropriate licensing.

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Key Features](#key-features) β€’
[Docs](https://anomalib.readthedocs.io/en/latest/) β€’
[Notebooks](notebooks) β€’
[License](https://github.com/openvinotoolkit/anomalib/blob/main/LICENSE)
[License](LICENSE)

[![python](https://img.shields.io/badge/python-3.7%2B-green)]()
[![pytorch](https://img.shields.io/badge/pytorch-1.8.1%2B-orange)]()
Expand Down Expand Up @@ -52,7 +52,7 @@ Installing the library with pip is the easiest way to get started with anomalib.
pip install anomalib
```

This will install Anomalib CLI using the [installer](requirements/installer.txt) dependecies. Anomalib CLI is a command line interface for training, inference, benchmarking, and hyperparameter optimization. If you want to use the library as a Python package, you can install the library with the following command:
This will install Anomalib CLI using the [installer](requirements/installer.txt) dependencies. Anomalib CLI is a command line interface for training, inference, benchmarking, and hyperparameter optimization. If you want to use the library as a Python package, you can install the library with the following command:

```bash
# Get help for the installation arguments
Expand All @@ -78,7 +78,7 @@ anomalib install --option openvino
To install from source, you need to clone the repository and install the library using pip via editable mode.

```bash
# Use of virtual environment is highy recommended
# Use of virtual environment is highly recommended
# Using conda
yes | conda create -n anomalib_env python=3.10
conda activate anomalib_env
Expand All @@ -92,7 +92,7 @@ cd anomalib
pip install -e .
```

This will install Anomalib CLI using the [installer](requirements/installer.txt) dependecies. Anomalib CLI is a command line interface for training, inference, benchmarking, and hyperparameter optimization. If you want to use the library as a Python package, you can install the library with the following command:
This will install Anomalib CLI using the [installer](requirements/installer.txt) dependencies. Anomalib CLI is a command line interface for training, inference, benchmarking, and hyperparameter optimization. If you want to use the library as a Python package, you can install the library with the following command:

```bash
# Get help for the installation arguments
Expand Down Expand Up @@ -259,7 +259,7 @@ You first need to modify the `config.yaml` file to enable logging. The following

Anomalib provides a benchmarking tool to evaluate the performance of the anomaly detection models on a given dataset. The benchmarking tool can be used to evaluate the performance of the models on a given dataset, or to compare the performance of multiple models on a given dataset.

Each model in anomalib is benchmarked on a set of datasets, and the results are available in `src/anomalib/models/<model_name>README.md`. For example, the MVTec AD results for the Patchcore model are available in the corresponding [README.md](https://github.com/openvinotoolkit/anomalib/tree/main/src/anomalib/models/patchcore#mvtec-ad-dataset) file.
Each model in anomalib is benchmarked on a set of datasets, and the results are available in `src/anomalib/models/<type>/<model_name>/README.md`. For example, the MVTec AD results for the Patchcore model are available in the corresponding [README.md](src/anomalib/models/image/patchcore/README.md#mvtec-ad-dataset) file.

<details>
<summary>Benchmarking via API</summary>
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/announcements/recognition.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Anomalib is committed to excellence and innovation in open-source software devel
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8330/badge)](https://www.bestpractices.dev/projects/8330)

- **Date:** January 25, 2024
- **Details:** Anomalib recived the passing grade for the [Open Source Initiative Best Practices Badge](https://opensource.org/best-practices-badge). This badge recognizes our commitment to high-quality coding standards and community engagement.
- **Details:** Anomalib received the passing grade for the [Open Source Initiative Best Practices Badge](https://opensource.org/best-practices-badge). This badge recognizes our commitment to high-quality coding standards and community engagement.

[Learn more about this award](https://opensource.org/best-practices-badge)
:::
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/get_started/anomalib.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ By using the configuration file above, you can run the experiment with the follo

Anomalib provides a benchmarking tool to evaluate the performance of the anomaly detection models on a given dataset. The benchmarking tool can be used to evaluate the performance of the models on a given dataset, or to compare the performance of multiple models on a given dataset.

Each model in anomalib is benchmarked on a set of datasets, and the results are available in `src/anomalib/models/<model_name>README.md`. For example, the MVTec AD results for the Patchcore model are available in the corresponding [README.md](https://github.com/openvinotoolkit/anomalib/tree/main/src/anomalib/models/patchcore#mvtec-ad-dataset) file.
Each model in anomalib is benchmarked on a set of datasets, and the results are available in `src/anomalib/models/<model_name>README.md`. For example, the MVTec AD results for the Patchcore model are available in the corresponding [README.md](https://github.com/openvinotoolkit/anomalib/tree/main/src/anomalib/models/image/patchcore#mvtec-ad-dataset) file.

::::{tab-set}

Expand Down
12 changes: 6 additions & 6 deletions notebooks/100_datamodules/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Anomalib DataModules Tutorial

| Notebook | GitHub | Colab |
| -------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BTech | [101_btech](100_datamodules/101_btech.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/101_btech.ipynb) |
| MVTec | [102_mvtec](100_datamodules/102_mvtec.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/102_mvtec.ipynb) |
| Folder | [103_folder](100_datamodules/103_folder.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/103_folder.ipynb) |
| Tiling | [104_tiling](100_datamodules/104_tiling.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/104_tiling.ipynb) |
| Notebook | GitHub | Colab |
| -------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BTech | [101_btech](101_btech.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/101_btech.ipynb) |
| MVTec | [102_mvtec](102_mvtec.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/102_mvtec.ipynb) |
| Folder | [103_folder](103_folder.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/103_folder.ipynb) |
| Tiling | [104_tiling](104_tiling.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/100_datamodules/104_tiling.ipynb) |

## Notebook Contents

Expand Down
4 changes: 2 additions & 2 deletions notebooks/500_use_cases/501_dobot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ d. Then, replace those coordinates in the notebook

### Data acquisition and inferencing

For data acquisition and inferencing we will use [501b notebook](https://github.com/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501_dobot/501b_inference_with_a_robotic_arm.ipynb). There we need to identify the `acquisition` flag, **True** for _acquisition mode_ and **False** for _inferencing mode_. In acquisition mode be aware of the _normal_ or _abnormal_ folder we want to create, in this mode the notebook will save every image in the anomalib/datasets/cubes/{FOLDER} for further training. In inferencing mode the notebook won't save images, it will run the inference and show the results.
For data acquisition and inferencing we will use [501b notebook](501b_inference_with_a_robotic_arm.ipynb). There we need to identify the `acquisition` flag, **True** for _acquisition mode_ and **False** for _inferencing mode_. In acquisition mode be aware of the _normal_ or _abnormal_ folder we want to create, in this mode the notebook will save every image in the anomalib/datasets/cubes/{FOLDER} for further training. In inferencing mode the notebook won't save images, it will run the inference and show the results.

_Note_: If you dont have the robot you could jump to the another notebook [501a](https://github.com/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) and download the dataset from this [link](https://github.com/openvinotoolkit/anomalib/releases/tag/dobot)
_Note_: If you dont have the robot you could jump to the another notebook [501a](501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) and download the dataset from this [link](https://github.com/openvinotoolkit/anomalib/releases/tag/dobot)

### Training

Expand Down
25 changes: 9 additions & 16 deletions notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,15 @@ To install Python, Git and other required tools, [OpenVINO Notebooks](https://gi
| -------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Model | [201_fastflow](200_models/201_fastflow.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/200_models/201_fastflow.ipynb) |

## 3. Benchmarking and Hyperparameter Optimization
## 3. OpenVINO Optimization

| Notebook | GitHub | Colab |
| -------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Benchmarking | [301_benchmarking](300_benchmarking/301_benchmarking.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/300_benchmarking/301_benchmarking.ipynb) |
| HPO with wandb | [302_hpo_wandb](300_benchmarking/302_hpo_wandb.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/300_benchmarking/302_hpo_wandb.ipynb) |
| Notebook | GitHub | Colab |
| ------------ | -------------------------------------------------- | ----- |
| Quantization | [401_NNCF](/notebooks/400_openvino/401_nncf.ipynb) | |

## 4. OpenVINO Optimization
## 4. Use cases

| Notebook | GitHub | Colab |
| ------------ | ------------------------------------------------------------------------------------------------------- | ----- |
| Quantization | [401_NNCF](https://github.com/openvinotoolkit/anomalib/blob/main/notebooks/400_openvino/401_nncf.ipynb) | |

## 3. Use cases

| Notebook | GitHub | Colab |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| Dobot Dataset Creation | [501a_training](https://github.com/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) | |
| Training | [501b_training](https://github.com/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501b_inference_with_a_robotic_arm.ipynb) | |
| Notebook | GitHub | Colab |
| ---------------------- | ------------------------------------------------------------------------------------------------------------- | ----- |
| Dobot Dataset Creation | [501a_training](/notebooks/500_use_cases/501_dobot/501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) | |
| Training | [501b_training](/notebooks/500_use_cases/501_dobot/501b_inference_with_a_robotic_arm.ipynb) | |
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,13 @@ source = ["src", ".tox/*/site-packages"]
# NBQA CONFIGURATION #
[tool.nbqa.addopts]
ruff = ["--ignore=E402"]

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# LINK CHECKER CONFIGURATION #
[tool.md_dead_link_check]
exclude_links = [
"https://github.com/openvinotoolkit/anomalib/settings/actions/runners/new",
"https://openvinotoolkit.github.io/anomalib/*", # Remove it after publish documentation
]
exclude_files = ["docs/*"]
force_get_requests_for_links = ["https://secure.ethicspoint.com/*"]
2 changes: 2 additions & 0 deletions src/anomalib/data/base/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import torch
from pandas import DataFrame
from torchvision.transforms.v2 import Transform
from torchvision.transforms.v2.functional import to_dtype_video
from torchvision.tv_tensors import Mask

from anomalib import TaskType
Expand Down Expand Up @@ -153,6 +154,7 @@ def __getitem__(self, index: int) -> dict[str, str | torch.Tensor]:
msg = "self.indexer must be an instance of ClipsIndexer."
raise TypeError(msg)
item = self.indexer.get_item(index)
item["image"] = to_dtype_video(video=item["image"], scale=True)
# include the untransformed image for visualization
item["original_image"] = item["image"].to(torch.uint8)

Expand Down
6 changes: 4 additions & 2 deletions src/anomalib/deploy/inferencers/openvino_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from PIL import Image

from anomalib import TaskType
from anomalib.data.utils.label import LabelName
from anomalib.utils.visualization import ImageResult

from .base_inferencer import Inferencer
Expand Down Expand Up @@ -253,7 +254,7 @@ def post_process(self, predictions: np.ndarray, metadata: dict | DictConfig | No

# Initialize the result variables.
anomaly_map: np.ndarray | None = None
pred_label: float | None = None
pred_label: LabelName | None = None
pred_mask: float | None = None

# If predictions returns a single value, this means that the task is
Expand All @@ -270,7 +271,8 @@ def post_process(self, predictions: np.ndarray, metadata: dict | DictConfig | No
# label to the prediction if the prediction score is greater
# than the image threshold.
if "image_threshold" in metadata:
pred_label = pred_score >= metadata["image_threshold"]
pred_idx = pred_score >= metadata["image_threshold"]
pred_label = LabelName.ABNORMAL if pred_idx else LabelName.NORMAL

if task == TaskType.CLASSIFICATION:
_, pred_score = self._normalize(pred_scores=pred_score, metadata=metadata)
Expand Down
Loading
Loading