-
Notifications
You must be signed in to change notification settings - Fork 844
feat(postprocess): add MEBin post-processing method #3116
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
base: main
Are you sure you want to change the base?
Conversation
* Use uv commands Signed-off-by: Ashwin Vaidya <[email protected]> * Add source activate step Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…-platform#2968) * 🚀 feat(model): make improvements for patchcore on xpu * 🔄 refactor(k_center_greedy): remove profiling code. Signed-off-by: rajeshgangireddy <[email protected]> * 🚀 feat(benchmark): add seed setting for reproducibility in run_benchmark function * 🔄 refactor(k_center_greedy): enhance device handling and remove unused benchmark scripts * 🔄 refactor(k_center_greedy): remove the unused case of multiple centers to simplify * 🐞 fix(comments): update variable names --------- Signed-off-by: rajeshgangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
Signed-off-by: oep-renovate[bot] <212772560+oep-renovate[bot]@users.noreply.github.com> Co-authored-by: oep-renovate[bot] <212772560+oep-renovate[bot]@users.noreply.github.com> Signed-off-by: StarPlatinum7 <[email protected]>
* 🚀 feat(dataset): add BMAD dataset to Anomalib (open-edge-platform#2900) * Adding BMAD dataset to Anomalib Signed-off-by: Devansh Agarwal <[email protected]> * Fixed pre-commit hook errors Signed-off-by: Devansh Agarwal <[email protected]> --------- Signed-off-by: Devansh Agarwal <[email protected]> * 🔧 refactor(data): Polish BMAD dataset (open-edge-platform#2981) * 🧹 Polish dataset 🧪 Add tests 📋 Fix documentation 🛠️ Minor fixes Signed-off-by: Ashwin Vaidya <[email protected]> * Update src/anomalib/data/datamodules/image/bmad.py Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> * Fix mask_samples Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Devansh Agarwal <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Devansh Agarwal <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…3003) * 🚀 feat(dataset): add 3D-ADAM dataset to Anomalib (open-edge-platform#2986) * 🐞 fix(utils): revert `OptionalImport` class to handle missing optional dependencies (open-edge-platform#2956) * fix(data): enable pin_memory for DataLoader instances across the codebase This commit updates various DataLoader instances in the project to enable the option, enhancing performance for data loading on GPU. Changes were made in the following files: - : Updated train and test DataLoader configurations. - : Modified datamodule DataLoader to include . - : Added to evaluation DataLoader. - : Updated DataLoader for datasets to utilize . - : Enabled for reference dataset DataLoader. - : Adjusted inference DataLoader to include . These changes aim to optimize memory usage and improve data transfer speeds during model training and inference. Signed-off-by: samet-akcay <[email protected]> * refactor(models): streamline decoder retrieval in function This commit refactors the function in to utilize a dictionary mapping for decoder architectures, improving readability and maintainability. The previous conditional checks have been replaced with a more efficient approach, enhancing the overall structure of the code. Signed-off-by: samet-akcay <[email protected]> * fix(model): update logit_scale initialization to use torch.log for consistency This commit modifies the initialization of the logit_scale parameter in the CLIP model to utilize torch.log instead of np.log. This change ensures consistency in tensor operations and improves compatibility with PyTorch's computation graph. Signed-off-by: samet-akcay <[email protected]> * fix(model): update anomaly map generation to use torch tensors for calculations This commit modifies the anomaly map generation logic to utilize PyTorch tensors instead of NumPy arrays for various calculations. This change enhances compatibility with the PyTorch computation graph and improves performance by leveraging GPU acceleration. Key updates include the conversion of statistical calculations and tensor operations to use PyTorch functions, ensuring consistency in tensor handling throughout the code. Signed-off-by: samet-akcay <[email protected]> * refactor(model): enhance anomaly map generation with PyTorch for statistical calculations This commit refactors the anomaly map generation logic to replace NumPy-based statistical calculations with PyTorch equivalents, specifically using the distribution for computing tau. Additionally, it improves precision handling by allowing the use of float64 in high precision mode. The changes streamline the computation process and maintain compatibility with the PyTorch computation graph. Signed-off-by: samet-akcay <[email protected]> * chore(license): update license year Signed-off-by: samet-akcay <[email protected]> * fix(download): enhance URL validation and update download logic This commit improves the URL validation in the download function to ensure only http and https schemes are allowed. Additionally, it adds comments to clarify the safety of using under these conditions, enhancing code readability and security awareness. Signed-off-by: samet-akcay <[email protected]> * 🗑️ chore(imports): remove OptionalImport class for optional dependency handling Signed-off-by: samet-akcay <[email protected]> * 🐛 fix(imports): Replace OptionalImport with dummy classes for missing dependencies This commit removes the OptionalImport class and introduces dummy classes for various loggers and video utilities when their respective dependencies are not installed. The changes enhance error messaging by providing clear instructions for installation, improving user experience when encountering missing packages. Affected files: - video.py - comet.py - mlflow.py - tensorboard.py - wandb.py - ollama.py Signed-off-by: samet-akcay <[email protected]> --------- Signed-off-by: samet-akcay <[email protected]> Signed-off-by: Paul McHard <[email protected]> * Added 3D-ADAM Dataset Signed-off-by: Paul McHard <[email protected]> * Added tests and example config Signed-off-by: Paul McHard <[email protected]> * 🔨 fix(semgrep): ignore uv.lock in semgrep (open-edge-platform#2972) ignore uv.lock in semgrep Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Paul McHard <[email protected]> * 🐞 fix(utils): Run CS Flow model in eval() so the weights of the model itself will not be modified (open-edge-platform#2966) fix in dryrun_find_featuremap_dims: run the model in eval() so the weights of the model itself will not be modified Signed-off-by: Paul McHard <[email protected]> * 🐛 fix(ovinferencer): Fix openvino cache directory (open-edge-platform#2979) 🐛 fix(ovinferencer): update cache folder name to 'openvino_cache' and ensure string path for set_property Signed-off-by: Paul McHard <[email protected]> * changes per PR and pre-commit checks Signed-off-by: Paul McHard <[email protected]> * resolve circular import issue Signed-off-by: Paul McHard <[email protected]> * Resolve DownloadInfo URL issue. Signed-off-by: Paul McHard <[email protected]> * Resolve DownloadInfo URL Signed-off-by: Paul McHard <[email protected]> * restore doc images ignored in error Signed-off-by: Paul McHard <[email protected]> * Removed prettier cache included in error, re-run pre-commit hooks Signed-off-by: Paul McHard <[email protected]> * explictly resolve EOF error on docs/source/examples Signed-off-by: Paul McHard <[email protected]> * resolve filename issue in adam3d test. Signed-off-by: Paul McHard <[email protected]> * Restore uv.lock Signed-off-by: Paul McHard <[email protected]> --------- Signed-off-by: samet-akcay <[email protected]> Signed-off-by: Paul McHard <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Paul McHard <[email protected]> Co-authored-by: Samet Akcay <[email protected]> Co-authored-by: Ashwin Vaidya <[email protected]> Co-authored-by: Rune <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> * revert changes to example Signed-off-by: Ashwin Vaidya <[email protected]> * revert file permissions Signed-off-by: Ashwin Vaidya <[email protected]> * 🔧 refactor(data): Polish 3dAdam dataset (open-edge-platform#3002) * Add changelog + fix dataset location Signed-off-by: Ashwin Vaidya <[email protected]> * revert changes to example Signed-off-by: Ashwin Vaidya <[email protected]> * revert file permissions Signed-off-by: Ashwin Vaidya <[email protected]> * Fix tests Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]> * revert examples Signed-off-by: Ashwin Vaidya <[email protected]> * revert file permissions Signed-off-by: Ashwin Vaidya <[email protected]> * Add imagecodecs dependency Signed-off-by: Ashwin Vaidya <[email protected]> * Apply suggestion from @samet-akcay Co-authored-by: Samet Akcay <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: samet-akcay <[email protected]> Signed-off-by: Paul McHard <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Paul McHard <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Paul McHard <[email protected]> Co-authored-by: Samet Akcay <[email protected]> Co-authored-by: Rune <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
* fix(data): enable pin_memory for DataLoader instances across the codebase This commit updates various DataLoader instances in the project to enable the option, enhancing performance for data loading on GPU. Changes were made in the following files: - : Updated train and test DataLoader configurations. - : Modified datamodule DataLoader to include . - : Added to evaluation DataLoader. - : Updated DataLoader for datasets to utilize . - : Enabled for reference dataset DataLoader. - : Adjusted inference DataLoader to include . These changes aim to optimize memory usage and improve data transfer speeds during model training and inference. Signed-off-by: samet-akcay <[email protected]> * refactor(models): streamline decoder retrieval in function This commit refactors the function in to utilize a dictionary mapping for decoder architectures, improving readability and maintainability. The previous conditional checks have been replaced with a more efficient approach, enhancing the overall structure of the code. Signed-off-by: samet-akcay <[email protected]> * fix(model): update logit_scale initialization to use torch.log for consistency This commit modifies the initialization of the logit_scale parameter in the CLIP model to utilize torch.log instead of np.log. This change ensures consistency in tensor operations and improves compatibility with PyTorch's computation graph. Signed-off-by: samet-akcay <[email protected]> * fix(model): update anomaly map generation to use torch tensors for calculations This commit modifies the anomaly map generation logic to utilize PyTorch tensors instead of NumPy arrays for various calculations. This change enhances compatibility with the PyTorch computation graph and improves performance by leveraging GPU acceleration. Key updates include the conversion of statistical calculations and tensor operations to use PyTorch functions, ensuring consistency in tensor handling throughout the code. Signed-off-by: samet-akcay <[email protected]> * refactor(model): enhance anomaly map generation with PyTorch for statistical calculations This commit refactors the anomaly map generation logic to replace NumPy-based statistical calculations with PyTorch equivalents, specifically using the distribution for computing tau. Additionally, it improves precision handling by allowing the use of float64 in high precision mode. The changes streamline the computation process and maintain compatibility with the PyTorch computation graph. Signed-off-by: samet-akcay <[email protected]> * chore(license): update license year Signed-off-by: samet-akcay <[email protected]> * fix(download): enhance URL validation and update download logic This commit improves the URL validation in the download function to ensure only http and https schemes are allowed. Additionally, it adds comments to clarify the safety of using under these conditions, enhancing code readability and security awareness. Signed-off-by: samet-akcay <[email protected]> * 📝 chore(changelog): update changelog for v2.2.0 release with added features and fixes * 🐛 fix(version): update version from 2.2.0dev to 2.2.0 * Update CHANGELOG.md Signed-off-by: Ashwin Vaidya <[email protected]> * Update changelog Signed-off-by: Ashwin Vaidya <[email protected]> * Use full PR links Signed-off-by: Ashwin Vaidya <[email protected]> * Add authors in changelog Signed-off-by: Ashwin Vaidya <[email protected]> * Update CHANGELOG.md Co-authored-by: Copilot <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: samet-akcay <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Ashwin Vaidya <[email protected]> Co-authored-by: Ashwin Vaidya <[email protected]> Co-authored-by: Copilot <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
* Remove duplicate entry Signed-off-by: Ashwin Vaidya <[email protected]> * Add missing entry Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
Update version Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…3017) 📦 update(README): Announce v2.2.0 release with new datasets, metrics, and performance improvements Signed-off-by: StarPlatinum7 <[email protected]>
🐛 fix(metrics): disable mps for torch metrics (open-edge-platform#3018) * move to cpu when device is mps --------- Signed-off-by: Ma, Xiangxiang <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
Update CODEOWNERS Signed-off-by: Ashwin Vaidya <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…-edge-platform#3046) * chore: add code owners for GitHub workflows and security policy - Add @kamillipka @mramotowski @ivanzati @AlexanderBarabanov as owners for .github/workflows/ - Add same team as owners for SECURITY.md Signed-off-by: mramotowski <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: mramotowski <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Ashwin Vaidya <[email protected]> Co-authored-by: Copilot <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…atform#3031) patchcore infer dtype from model dtype Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…atform#3036) * Fix squeeze on 1dim score Signed-off-by: blaz.rolih <[email protected]> * Add option to train without masks Signed-off-by: blaz.rolih <[email protected]> * Add JIMS separate feat extension Signed-off-by: blaz.rolih <[email protected]> * Update docs for JIMS extension Signed-off-by: blaz.rolih <[email protected]> * Remove unused get_params method Signed-off-by: blaz.rolih <[email protected]> * Add unit tests for SSN Signed-off-by: blaz.rolih <[email protected]> * Rename vars and update metrics in readme Signed-off-by: blaz.rolih <[email protected]> --------- Signed-off-by: blaz.rolih <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…m#3054) cv1.0.0i: migrate PyPI publishing to OIDC authentication Replace token-based authentication with OpenID Connect (OIDC) for enhanced security when publishing to PyPI and Test PyPI. Signed-off-by: mramotowski <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…atform#3047) (open-edge-platform#3055) * 🚀 feat(model): REFACTOR Enable Patchcore Training Half Precision (open-edge-platform#3047) * patchcore infer dtype from model dtype * lock * pre-commits Signed-off-by: Alexander Riedel <[email protected]> --------- Signed-off-by: Alexander Riedel <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Ashwin Vaidya <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> --------- Signed-off-by: Alexander Riedel <[email protected]> Signed-off-by: Ashwin Vaidya <[email protected]> Co-authored-by: Alexander Riedel <[email protected]> Co-authored-by: Rajesh Gangireddy <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…pen-edge-platform#3059) * Fixed Folder dataset to use upper case file extension * Convert provided extensions to lower case Signed-off-by: StarPlatinum7 <[email protected]>
* chore(deps): lock file maintenance Signed-off-by: oep-renovate[bot] <212772560+oep-renovate[bot]@users.noreply.github.com> * use semgrep action from geti-ci Signed-off-by: Barabanov <[email protected]> * fix pre-commit Signed-off-by: Barabanov <[email protected]> * update sha Signed-off-by: Barabanov <[email protected]> * remove local semgrep action Signed-off-by: Barabanov <[email protected]> * update sha Signed-off-by: Barabanov <[email protected]> * update semgrepignore Signed-off-by: Barabanov <[email protected]> --------- Signed-off-by: oep-renovate[bot] <212772560+oep-renovate[bot]@users.noreply.github.com> Signed-off-by: Barabanov <[email protected]> Co-authored-by: oep-renovate[bot] <212772560+oep-renovate[bot]@users.noreply.github.com> Co-authored-by: Barabanov <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…rm#3088) update renovate config Signed-off-by: Barabanov <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
…tform#3108) * Update xpu.py regarind PR open-edge-platform#3092 Added the name method to fix an issue related to a newly added feature in lightning 2.5.6 Signed-off-by: Niclas <[email protected]> * Update xpu.py Signed-off-by: Niclas <[email protected]> * Update xpu.py Signed-off-by: Niclas <[email protected]> * Update xpu.py with docstring Signed-off-by: Niclas <[email protected]> * Update xpu.py with correct docstring Signed-off-by: Niclas <[email protected]> * added name method for XPUAccelerator Signed-off-by: waschsalz <[email protected]> --------- Signed-off-by: Niclas <[email protected]> Signed-off-by: waschsalz <[email protected]> Signed-off-by: StarPlatinum7 <[email protected]>
Signed-off-by: StarPlatinum7 <[email protected]>
samet-akcay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great contribution! Overall, it looks great. I have few comments here and there.
@rajeshgangireddy, would it be an idea to merge this to a feature branch, and address the issues ourselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are some formatting issues in this file, which could be addressed by running pre-commit run -a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this file needs annotations in the class/functions etc?
| """ | ||
|
|
||
| import cv2 | ||
| import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to use torch instead of numpy? We would want everything to be a torch operation end-to-end
| >>> binarized_maps, thresholds = mebin.binarize_anomaly_maps() | ||
| """ | ||
|
|
||
| def __init__(self, anomaly_map_path_list=None, sample_rate=4, min_interval_len=4, erode=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we want to use this post-processing in an end-to-end operation in anomalib? Would we need to follow this logic?
- Save anomaly maps to file
- Load them here and apply post-processing?
Would it not be possible to use this approach without loading the heatmaps from file?
|
|
||
| self.anomaly_map_path_list = anomaly_map_path_list | ||
| # Load anomaly maps as grayscale images if paths are provided | ||
| self.anomaly_map_list = [cv2.imread(x, cv2.IMREAD_GRAYSCALE) for x in self.anomaly_map_path_list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have to load from filesystem, maybe we could use anomalib's built-in read_image util function?
|
|
||
| def get_threshold(self, anomaly_num_sequence, min_interval_len): | ||
| """ | ||
| Find the 'stable interval' in the anomaly region number sequence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Find the 'stable interval' in the anomaly region number sequence. | |
| Find the `stable interval` in the anomaly region number sequence. |
| """ | ||
| interval_result = {} | ||
| current_index = 0 | ||
| while current_index < len(anomaly_num_sequence): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we certain that nested while loops are the most efficient way of running this approach?
| """ | ||
| anomaly_maps = predictions.anomaly_map | ||
| if isinstance(anomaly_maps, torch.Tensor): | ||
| anomaly_maps = anomaly_maps.detach().cpu().numpy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we keep switching between numpy and torch. Would it be possible to just use torch instead?
📝 Description
This pull request introduces support for the MEBIN post-processing method within the Anomalib framework. The implementation includes a new post-processing algorithm that mitigates false positives and false negatives in the binarization results by identifying the threshold interval where connected components remains stable. This strategy is proposed in AnomalyNCD (CVPR2025).
✨ Changes
Select what type of change your PR is:
✅ Checklist
Before you submit your pull request, please make sure you have completed the following steps:
For more information about code review checklists, see the Code Review Checklist.