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

fix add graph func is not called bug #632

Merged
merged 8 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mmengine/hooks/naive_visualization_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def _unpad(self, input: np.ndarray, unpad_shape: Tuple[int,
unpad_image = input[:unpad_height, :unpad_width]
return unpad_image

def before_train(self, runner) -> None:
"""Call add_graph method of visualizer.

Args:
runner (Runner): The runner of the training process.
"""
runner.visualizer.add_graph(runner.model, None)

def after_test_iter(self,
runner,
batch_idx: int,
Expand Down
17 changes: 16 additions & 1 deletion mmengine/visualization/vis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,23 @@ class WandbVisBackend(BaseVisBackend):
`wandb docs <https://docs.wandb.ai/ref/python/run#log_code>`_
for details. Defaults to None.
New in version 0.3.0.
watch_kwargs (optional, dict): Agurments for ``wandb.watch``.
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
New in version 0.4.0.
"""

def __init__(self,
save_dir: str,
init_kwargs: Optional[dict] = None,
define_metric_cfg: Optional[dict] = None,
commit: Optional[bool] = True,
log_code_name: Optional[str] = None):
log_code_name: Optional[str] = None,
watch_kwargs: Optional[dict] = None):
super().__init__(save_dir)
self._init_kwargs = init_kwargs
self._define_metric_cfg = define_metric_cfg
self._commit = commit
self._log_code_name = log_code_name
self._watch_kwargs = watch_kwargs if watch_kwargs is not None else {}

def _init_env(self):
"""Setup env for wandb."""
Expand Down Expand Up @@ -415,6 +419,17 @@ def add_config(self, config: Config, **kwargs) -> None:
self._wandb.config.update(dict(config))
self._wandb.run.log_code(name=self._log_code_name)

@force_init_env
def add_graph(self, model: torch.nn.Module, data_batch: Sequence[dict],
**kwargs) -> None:
"""Record the model graph.

Args:
model (torch.nn.Module): Model to draw.
data_batch (Sequence[dict]): Batch of data from dataloader.
"""
self._wandb.watch(model, **self._watch_kwargs)

@force_init_env
def add_image(self,
name: str,
Expand Down