Skip to content

Commit 49ff210

Browse files
committed
Fix missing work_dir
1 parent c9b5996 commit 49ff210

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

mmengine/visualization/vis_backend.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,24 @@ def close(self) -> None:
824824
return
825825

826826
file_paths = dict()
827-
for filename in scandir(self.cfg.work_dir, self._artifact_suffix,
828-
True):
829-
file_path = osp.join(self.cfg.work_dir, filename)
830-
relative_path = os.path.relpath(file_path, self.cfg.work_dir)
831-
dir_path = os.path.dirname(relative_path)
832-
file_paths[file_path] = dir_path
827+
if (
828+
hasattr(self, 'cfg')
829+
and osp.isdir(getattr(self.cfg, 'work_dir', ''))
830+
):
831+
for filename in scandir(
832+
self.cfg.work_dir,
833+
self._artifact_suffix,
834+
recursive=True,
835+
):
836+
file_path = str(osp.join(self.cfg.work_dir, filename))
837+
relative_path = os.path.relpath(file_path, self.cfg.work_dir)
838+
dir_path = os.path.dirname(relative_path)
839+
file_paths[file_path] = dir_path
840+
else:
841+
warnings.warn(
842+
'self.cfg.work_dir is not set, thus some '
843+
'artifacts will not be logged'
844+
)
833845

834846
for file_path, dir_path in file_paths.items():
835847
self._mlflow.log_artifact(file_path, dir_path)

0 commit comments

Comments
 (0)