Skip to content

Commit 1ff0afc

Browse files
committed
Fix missing work_dir
1 parent c9b5996 commit 1ff0afc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

mmengine/visualization/vis_backend.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,20 @@ 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 (hasattr(self, 'cfg')
828+
and osp.isdir(getattr(self.cfg, 'work_dir', ''))):
829+
for filename in scandir(
830+
self.cfg.work_dir,
831+
self._artifact_suffix,
832+
recursive=True,
833+
):
834+
file_path = str(osp.join(self.cfg.work_dir, filename))
835+
relative_path = os.path.relpath(file_path, self.cfg.work_dir)
836+
dir_path = os.path.dirname(relative_path)
837+
file_paths[file_path] = dir_path
838+
else:
839+
warnings.warn('self.cfg.work_dir is not set, thus some '
840+
'artifacts will not be logged')
833841

834842
for file_path, dir_path in file_paths.items():
835843
self._mlflow.log_artifact(file_path, dir_path)

0 commit comments

Comments
 (0)