Skip to content

Save visualizer images on all processes - #1694

Open
Marchematics wants to merge 3 commits into
open-mmlab:mainfrom
Marchematics:contrib/visualizer-image-non-master
Open

Save visualizer images on all processes#1694
Marchematics wants to merge 3 commits into
open-mmlab:mainfrom
Marchematics:contrib/visualizer-image-non-master

Conversation

@Marchematics

Copy link
Copy Markdown

Save visualizer images on all processes.

Copilot AI lite review requested due to automatic review settings August 30, 2026 15:27
@CLAassistant

CLAassistant commented Aug 30, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR changes Visualizer.add_image to run on non-main processes (by removing the @master_only decorator) and adds a unit test to validate that images are still recorded when is_main_process() is false.

Changes:

  • Removed @master_only from Visualizer.add_image so it executes on all ranks.
  • Added a test to ensure add_image updates backends even on non-main processes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
mmengine/visualization/visualizer.py Removes rank-0-only gating for add_image.
tests/test_visualizer/test_visualizer.py Adds coverage for add_image behavior on non-main processes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +559 to +567
visualizer = Visualizer(
vis_backends=copy.deepcopy(self.vis_backend_cfg),
save_dir='temp_dir')

visualizer.add_image('img', self.image)

for name in ['mock1', 'mock2']:
assert visualizer._vis_backends[name]._add_image is True
is_main_process.assert_not_called()
Comment on lines 1085 to 1087
def add_image(self, name: str, image: np.ndarray, step: int = 0) -> None:
"""Record the image.

Signed-off-by: Marchematics <Marchematics@163.com>
@Marchematics

Copy link
Copy Markdown
Author

Updated the regression test to reset the rank mock after Visualizer construction. LocalVisBackend now keeps rank 0 filenames unchanged and appends _rankN for other ranks, avoiding multi-process overwrites.

Signed-off-by: Marchematics <Marchematics@163.com>
@Marchematics

Copy link
Copy Markdown
Author

Also removed the duplicate isfile mock flagged by the lint job; this was preventing the full pre-commit run from starting.

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.

3 participants