Skip to content

Commit

Permalink
Refactor configure_callbacks method in AnomalibModule to dynamica…
Browse files Browse the repository at this point in the history
…lly include available callbacks (pre-processor, post-processor, evaluator, visualizer) based on their existence. Update docstring for clarity on return values.
  • Loading branch information
samet-akcay committed Dec 9, 2024
1 parent e11c663 commit fab2bb6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/anomalib/models/components/base/anomaly_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,19 @@ def _setup(self) -> None:
"""

def configure_callbacks(self) -> Sequence[Callback] | Callback:
"""Configure default callbacks for AnomalibModule."""
return [self.pre_processor] if self.pre_processor else []
"""Configure default callbacks for AnomalibModule.
Returns:
List of callbacks that includes the pre-processor, post-processor, evaluator,
and visualizer if they are available and inherit from Callback.
"""
callbacks: list[Callback] = []
callbacks.extend(
component
for component in (self.pre_processor, self.post_processor, self.evaluator, self.visualizer)
if isinstance(component, Callback)
)
return callbacks

def forward(self, batch: torch.Tensor, *args, **kwargs) -> InferenceBatch:
"""Perform the forward-pass by passing input tensor to the module.
Expand Down

0 comments on commit fab2bb6

Please sign in to comment.