From 95234da737bd85656d34abc7e17e097139bd2a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20N=C3=A1cher?= Date: Mon, 10 Jun 2024 15:48:39 +0200 Subject: [PATCH 1/3] fix: ensure that custom callbacks are stored in default_root_dir --- src/anomalib/engine/engine.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/anomalib/engine/engine.py b/src/anomalib/engine/engine.py index 05b1d1d6af..d7ee3ffb1e 100644 --- a/src/anomalib/engine/engine.py +++ b/src/anomalib/engine/engine.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 import logging +import os from collections.abc import Iterable from pathlib import Path from typing import Any @@ -409,6 +410,15 @@ def _setup_anomalib_callbacks(self) -> None: """Set up callbacks for the trainer.""" _callbacks: list[Callback] = [RichProgressBar(), RichModelSummary()] + # Update dirpath of each cached callback preppending "default_root_dir" + # (which was updated in _setup_workspace() method) + for cached_callback in self._cache.args["callbacks"]: + if hasattr(cached_callback, "dirpath"): + callback_dirpath = Path(cached_callback.dirpath) + common_prefix = Path(os.path.commonpath([str(self._cache.args["default_root_dir"]), str(callback_dirpath)])) + callback_dirpath = callback_dirpath.relative_to(common_prefix) + cached_callback.dirpath = self._cache.args["default_root_dir"] / callback_dirpath + # Add ModelCheckpoint if it is not in the callbacks list. has_checkpoint_callback = any(isinstance(c, ModelCheckpoint) for c in self._cache.args["callbacks"]) if has_checkpoint_callback is False: From 194274965d60ba17a409547b8289532b7433c2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20N=C3=A1cher?= Date: Mon, 10 Jun 2024 15:48:39 +0200 Subject: [PATCH 2/3] fix: ensure that custom callbacks are stored in default_root_dir --- src/anomalib/engine/engine.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/anomalib/engine/engine.py b/src/anomalib/engine/engine.py index 485ab8e66e..67b5d77468 100644 --- a/src/anomalib/engine/engine.py +++ b/src/anomalib/engine/engine.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 import logging +import os from collections.abc import Iterable from pathlib import Path from typing import Any @@ -409,6 +410,15 @@ def _setup_anomalib_callbacks(self) -> None: """Set up callbacks for the trainer.""" _callbacks: list[Callback] = [RichProgressBar(), RichModelSummary()] + # Update dirpath of each cached callback preppending "default_root_dir" + # (which was updated in _setup_workspace() method) + for cached_callback in self._cache.args["callbacks"]: + if hasattr(cached_callback, "dirpath"): + callback_dirpath = Path(cached_callback.dirpath) + common_prefix = Path(os.path.commonpath([str(self._cache.args["default_root_dir"]), str(callback_dirpath)])) + callback_dirpath = callback_dirpath.relative_to(common_prefix) + cached_callback.dirpath = self._cache.args["default_root_dir"] / callback_dirpath + # Add ModelCheckpoint if it is not in the callbacks list. has_checkpoint_callback = any(isinstance(c, ModelCheckpoint) for c in self._cache.args["callbacks"]) if has_checkpoint_callback is False: From 9709840538c88eea87a5b12a436b4bc8f2ab67ef Mon Sep 17 00:00:00 2001 From: carlosnacher Date: Wed, 17 Jul 2024 07:49:07 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362856e3ec..d638410712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,12 +78,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - 🐞 Fix keys in data configs to fit AnomalibDataModule parameters by @abc-125 in https://github.com/openvinotoolkit/anomalib/pull/2032 - 🐞 Fix Export docstring in CLI by @ashwinvaidya17 in https://github.com/openvinotoolkit/anomalib/pull/2058 - 🐞 Fix UFlow links by @ashwinvaidya17 in https://github.com/openvinotoolkit/anomalib/pull/2059 +- 🐞 Fix custom callbacks dirpath to be the same as default root dir by @CarlosNacher in https://github.com/openvinotoolkit/anomalib/pull/2194 ### New Contributors - @seyeon923 made their first contribution in https://github.com/openvinotoolkit/anomalib/pull/1966 - @rglkt made their first contribution in https://github.com/openvinotoolkit/anomalib/pull/1956 - @DoMaLi94 made their first contribution in https://github.com/openvinotoolkit/anomalib/pull/1847 +- @CarlosNacher made their first contribution in https://github.com/openvinotoolkit/anomalib/pull/2194 **Full Changelog**: https://github.com/openvinotoolkit/anomalib/compare/v1.0.1...v1.1.0