neptune-ai / neptune-tensorboard

Neptune - TensorBoard integration 🧩 Experiment tracking with advanced UI, collaborative features, and user access management.
https://docs.neptune.ai/integrations/tensorboard/
Apache License 2.0
13 stars 6 forks source link

Error on image dimension #40

Closed vcoyette closed 3 years ago

vcoyette commented 3 years ago

Hi Neptune team,

I am getting an error when logging an image to tensorboard after runnig neptune_tb.integrate_with_tensorflow().

The problem is that an image has to be of dimension 4 (k, h, w, c) when logged to tensorboard (see https://www.tensorflow.org/api_docs/python/tf/summary/image).

However, when tf.summary.image is called with an image of dimension 4 (shape=(1, 1200, 1200, 3) in my case), the following error is raised:

  File ".../python3.8/site-packages/neptune_tensorboard/integration/tensorflow_integration.py", line 207, in image
    experiment_getter().log_image(get_channel_name(name), x=step, y=data, description=description)
  File ".../python3.8/site-packages/neptune/experiments.py", line 539, in log_image
    image_content = get_image_content(y)
  File ".../python3.8/site-packages/neptune/internal/utils/image.py", line 43, in get_image_content
    raise ValueError("Incorrect size of numpy.ndarray. Should be 2-dimensional or"
ValueError: Incorrect size of numpy.ndarray. Should be 2-dimensional or3-dimensional with 3rd dimension of size 1, 3 or 4.

I think the limitation here is that neptune.experiment.Experiment.log_image only accepts one image. As a workaround, I replaced line 207 of neptune_tensorboard/integration/tensorflow_integration.py by:

for image in data: 
    experiment_getter().log_image(   
        get_channel_name(name), x=step, y=image, description=description
    )  

I can create a PR if you want.

Versions:

HubertJaworski commented 3 years ago

Hi!

Thanks for taking your time to track this down :)

Your approach how to handle 4-dimensional image tensors is good, but Neptune server requires X-axis to be strictly monotonic (for each x, it must be larger than the previous one), otherwise all images except the first one will be dropped with a warning.

This particular piece of code should work with previews versions of TF as well - with 2 and 3 dimensional tensors

We created #41 based on your issue and sent it to review/testing on our side, you're welcome to take part in this process and see if it works with your code correctly :)

HubertJaworski commented 3 years ago

Hi,

We released version 0.5.1 that contains a fix based on your solution.

Feel free to try it out :)

vcoyette commented 3 years ago

Hi,

Sorry I missed you last comment. It is working great for me ! Many thanks for your efficiency :)