Skip to content

Conversation

samet-akcay
Copy link
Contributor

📝 Description

  • Added backward compatibility methods keys() and __getitem__() to NumpyBatch and Batch dataclasses to provide dictionary-like access to batch fields
  • Updated docstring examples in dataclass base files to use correct class names and tensor shapes
  • Enhanced visualization system with improved image handling and error handling

Data Classes Changes

  • Added keys(include_none: bool = True) -> list[str] method to both NumpyBatch and Batch classes
  • Added __getitem__(key: str) -> Any method to both classes for dictionary-like access
  • Updated docstring examples to use correct class names (NumpyBatch and Batch instead of generic names)
  • Fixed tensor shape examples to match expected formats (HWC for numpy, CHW for torch)

Visualization Changes

  • Enhanced ImageVisualizer with additional methods and improved error handling
  • Updated imports and type hints for better type safety
  • Improved robustness of visualization pipeline

Backward Compatibility

  • All changes are backward compatible
  • New methods provide additional functionality without breaking existing APIs
  • Docstring examples now accurately reflect the actual class usage

✨ Changes

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 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).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

…base

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 <samet.akcay@intel.com>
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 <samet.akcay@intel.com>
…nsistency

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 <samet.akcay@intel.com>
…lculations

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 <samet.akcay@intel.com>
…istical 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 <samet.akcay@intel.com>
Signed-off-by: samet-akcay <samet.akcay@intel.com>
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 <samet.akcay@intel.com>
…Batch classes

This commit updates the copyright year in the Numpy and Torch base files to reflect 2024-2025. Additionally, it introduces a new `keys` method in both the `NumpyBatch` and `Batch` classes, allowing users to retrieve field names with an option to include or exclude fields with None values. The `__getitem__` method is also added to enable dictionary-like access to field values.

Signed-off-by: [Your Name] <[Your Email]>
Signed-off-by: samet-akcay <samet.akcay@intel.com>
Copy link
Contributor

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! two super minor comments

This commit updates the ImageVisualizer class to handle dataset name and category attributes more robustly by using None as the default value instead of empty strings. This change enhances clarity and ensures that the filename generation logic remains consistent when these attributes are not present.

Signed-off-by: Samet Akcay samet.akcay@intel.com
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 27.27273% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/anomalib/visualization/image/visualizer.py 27.27% 16 Missing ⚠️
src/anomalib/data/dataclasses/numpy/base.py 27.27% 8 Missing ⚠️
src/anomalib/data/dataclasses/torch/base.py 27.27% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ashwinvaidya17 ashwinvaidya17 added this to the v2.2.0 milestone Sep 15, 2025
This commit refactors the ImageVisualizer class by renaming the `visualize_image` method to `visualize`, streamlining the interface for users. The updated method signature and examples in the docstring reflect this change, ensuring consistency in how predictions are visualized. Additionally, the copyright year has been updated to 2024-2025.

Signed-off-by: Samet Akcay <samet.akcay@intel.com>
…et-akcay/anomalib into docs/data/add-backward-compatibility
@samet-akcay samet-akcay merged commit 1fd6ce2 into open-edge-platform:main Sep 15, 2025
14 checks passed
@samet-akcay samet-akcay deleted the docs/data/add-backward-compatibility branch September 15, 2025 11:49
alexriedel1 pushed a commit to alexriedel1/anomalib that referenced this pull request Oct 6, 2025
… examples (open-edge-platform#2950)

* 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 <samet.akcay@intel.com>

* 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 <samet.akcay@intel.com>

* 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 <samet.akcay@intel.com>

* 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 <samet.akcay@intel.com>

* 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 <samet.akcay@intel.com>

* chore(license): update license year

Signed-off-by: samet-akcay <samet.akcay@intel.com>

* 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 <samet.akcay@intel.com>

* 🔧 chore: update copyright year and add keys method to NumpyBatch and Batch classes

This commit updates the copyright year in the Numpy and Torch base files to reflect 2024-2025. Additionally, it introduces a new `keys` method in both the `NumpyBatch` and `Batch` classes, allowing users to retrieve field names with an option to include or exclude fields with None values. The `__getitem__` method is also added to enable dictionary-like access to field values.

Signed-off-by: [Your Name] <[Your Email]>

* fix mypy

Signed-off-by: samet-akcay <samet.akcay@intel.com>

* refactor: improve dataset name and category handling in ImageVisualizer

This commit updates the ImageVisualizer class to handle dataset name and category attributes more robustly by using None as the default value instead of empty strings. This change enhances clarity and ensures that the filename generation logic remains consistent when these attributes are not present.

Signed-off-by: Samet Akcay samet.akcay@intel.com

* refactor: unify visualization method naming in ImageVisualizer

This commit refactors the ImageVisualizer class by renaming the `visualize_image` method to `visualize`, streamlining the interface for users. The updated method signature and examples in the docstring reflect this change, ensuring consistency in how predictions are visualized. Additionally, the copyright year has been updated to 2024-2025.

Signed-off-by: Samet Akcay <samet.akcay@intel.com>

---------

Signed-off-by: samet-akcay <samet.akcay@intel.com>
Signed-off-by: [Your Name] <[Your Email]>
Signed-off-by: Samet Akcay samet.akcay@intel.com
Signed-off-by: Samet Akcay <samet.akcay@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants