Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeCamp2023-327]Control whether methods of the Visualizer are executed only in the main process through a parameter #1350

Closed
wants to merge 2 commits into from

Conversation

DeliMm
Copy link

@DeliMm DeliMm commented Sep 10, 2023

Motivation

Control whether methods of the Visualizer are executed only in the main process through a parameter. See more details in #1081

Modification

To implement these functions, I add a parameter img_only_master to visualizer through vis_backend. And I modified these files :

  • modified mmengine/dist/utils.py
  • modified mmengine/visualization/vis_backend.py
  • modified mmengine/visualization/visualizer.py

During runtime, it is determined whether to retain only the images in the main GPU by checking if img_only_master is passed and examining its corresponding value. The following are modified master_only functions:

def master_only(func: Callable) -> Callable:
    """Decorate those methods which should be executed in master process.

    Args:
        func (callable): Function to be decorated.

    Returns:
        callable: Return decorated function.
    """

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        if ('img_only_master' in kwargs
                and kwargs['img_only_master'] is False) or is_main_process():
            return func(*args, **kwargs)	           
    return wrapper

When we build the runner, we can use this method to pass in img_only_master.

visualizer=dict(
            type='Visualizer',
            vis_backends=[
                dict(
                    type='LocalVisBackend',
                    save_dir='./vis',
                    img_only_master=False)
            ]),

When we use add_image in the training process, we also need to pass the extra parameter: img_only_master=runner.visualizer.img_only_master

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Sep 10, 2023

CLA assistant check
All committers have signed the CLA.

@DeliMm DeliMm closed this Sep 11, 2023
@DeliMm DeliMm deleted the gxl/fix_visualizer branch September 11, 2023 04:52
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.

None yet

2 participants