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

Option to normalize latent interpolation images #438

Merged
merged 3 commits into from
Dec 8, 2020
Merged
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions pl_bolts/callbacks/variational.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,27 @@ class LatentDimInterpolator(Callback):
"""

def __init__(
self, interpolate_epoch_interval: int = 20, range_start: int = -5, range_end: int = 5, num_samples: int = 2
self,
interpolate_epoch_interval: int = 20,
range_start: int = -5,
range_end: int = 5,
num_samples: int = 2,
normalize=False,
):
"""
Args:
interpolate_epoch_interval: default 20
range_start: default -5
range_end: default 5
num_samples: default 2
normalize: default False
"""
super().__init__()
self.interpolate_epoch_interval = interpolate_epoch_interval
self.range_start = range_start
self.range_end = range_end
self.num_samples = num_samples
self.normalize = normalize

def on_epoch_end(self, trainer, pl_module):
if (trainer.current_epoch + 1) % self.interpolate_epoch_interval == 0:
Expand All @@ -48,7 +55,7 @@ def on_epoch_end(self, trainer, pl_module):

num_images = (self.range_end - self.range_start) ** 2
num_rows = int(math.sqrt(num_images))
grid = torchvision.utils.make_grid(images, nrow=num_rows)
grid = torchvision.utils.make_grid(images, nrow=num_rows, normalize=self.normalize)
str_title = f'{pl_module.__class__.__name__}_latent_space'
trainer.logger.experiment.add_image(str_title, grid, global_step=trainer.global_step)

Expand Down