-
-
Notifications
You must be signed in to change notification settings - Fork 692
WeightsHistHandler should plot all weights (incl those without grad) #2328
Copy link
Copy link
Labels
Description
🚀 Feature
Currently, WeightsHistHandler do not log weights without grad:
ignite/ignite/contrib/handlers/tensorboard_logger.py
Lines 434 to 435 in a168476
| if p.grad is None: | |
| continue |
Let's put an option to enable logging all weights. Maybe, we can make it even without option and just log everything ?
Meanwhile, here is a workaround code for TensorboardLogger:
from ignite.contrib.handlers import TensorboardLogger
from ignite.contrib.handlers.tensorboard_logger import WeightsHistHandler
class FixedWeightsHistHandler(WeightsHistHandler):
def __call__(self, engine, logger, event_name):
if not isinstance(logger, TensorboardLogger):
raise RuntimeError("Handler 'WeightsHistHandler' works only with TensorboardLogger")
global_step = engine.state.get_event_attrib_value(event_name)
tag_prefix = f"{self.tag}/" if self.tag else ""
for name, p in self.model.named_parameters():
name = name.replace(".", "/")
logger.writer.add_histogram(
tag=f"{tag_prefix}weights/{name}", values=p.data.detach().cpu().numpy(), global_step=global_step,
)Reactions are currently unavailable