Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
- fix issues in tensorboard logger
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Aug 16, 2018
1 parent 1859638 commit 5757090
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions inferno/trainers/callbacks/logging/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def log_object(self, tag, object_,
allow_image_logging,
allow_histogram_logging)
return

# FIXME this can throw ugly warnings
# Check whether object is a scalar
if tu.is_scalar_tensor(object_) and allow_scalar_logging:
# Log scalar
Expand All @@ -211,9 +213,10 @@ def log_object(self, tag, object_,
# Add a channel axis and log as images
self.log_image_or_volume_batch(tag, object_[:, None, ...],
self.trainer.iteration_count)
elif tu.is_image_or_volume_tensor(object_) and allow_image_logging:
# Log images
self.log_image_or_volume_batch(tag, object_, self.trainer.iteration_count)
elif tu.is_image_or_volume_tensor(object_):
if allow_image_logging:
# Log images
self.log_image_or_volume_batch(tag, object_, self.trainer.iteration_count)
elif tu.is_vector_tensor(object_) and allow_histogram_logging:
# Log histograms
values = tu.unwrap(object_, as_numpy=True)
Expand Down Expand Up @@ -388,12 +391,15 @@ def log_images(self, tag, images, step, image_format='CHW'):
if image.shape[-1] == 1:
image = image[..., [0, 0, 0]]
image = self._normalize_image(image)
# print(image.dtype, image.shape)
self.writer.add_image(tag, img_tensor=image, global_step=step)

@staticmethod
def _normalize_image(image):
normalized_image = image - image.min()
normalized_image = normalized_image / normalized_image.max()
maxval = normalized_image.max()
if maxval > 0:
normalized_image = normalized_image / maxval
return normalized_image

def log_histogram(self, tag, values, step, bins=1000):
Expand Down

0 comments on commit 5757090

Please sign in to comment.