Save visualizer images on all processes - #1694
Conversation
There was a problem hiding this comment.
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_onlyfromVisualizer.add_imageso it executes on all ranks. - Added a test to ensure
add_imageupdates 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.
| 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() |
| def add_image(self, name: str, image: np.ndarray, step: int = 0) -> None: | ||
| """Record the image. | ||
|
|
Signed-off-by: Marchematics <Marchematics@163.com>
|
Updated the regression test to reset the rank mock after Visualizer construction. LocalVisBackend now keeps rank 0 filenames unchanged and appends |
Signed-off-by: Marchematics <Marchematics@163.com>
|
Also removed the duplicate |
Save visualizer images on all processes.