Log one Image after every layer #11770
Unanswered
V-Krause
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 1 comment 7 replies
-
you can register forward hooks: class LitModel(LightningModule):
def __init__(self, ...):
super().__init__()
self.hooks = {}
....
def log_intermediate(self, name):
def wrapped(module, inp, output):
self.logger.experiment.whatever_method_logs_image(f'layer_act/{module}, out.detach(), step=self.global_step)
return wrapped
def on_train_epoch_start(self):
self.hook['conv1'] = self.conv1.register_forward_hook(self.log_intermediate('conv1'))
# same for conv2, ....
def on_validation_start(self):
if self.hooks:
for hook in list(self.hooks):
self.hooks.pop(hook).remove() I haven't actually tried this code, but if it doesn't work for you, we can explore why or look for more options. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently working on a project classifying MRI images for Alzheimer's disease. For illustration I would like to log a sample image after each layer so you can see what the different filters/layers have done to the image. I know that you can log images in Tensorboard with logger.experiment, but is there also a way to insert this between each layer? So I would like to have a series of images that starts with the initial image, then outputs one image after each layer and last but not least, outputs the result image. What would I need to do to achieve this?
Here is an excerpt from my work.
`
class AlzheimerClassifier(LightningModule):
`
Beta Was this translation helpful? Give feedback.
All reactions