pythonpython-imaging-librarytensorboard

Tensorboard: Trying to log RGB image. TypeError: Cannot handle this data type


I am trying to log an RGB image to Tensorboard. I made sure that my image is a numpy array with the shape (206,127,3). The values inside are numpy.uint8 with a range from 0-255.

When I do:

writer.add_image("Example Image", img, epoch)

I get the error:

TypeError: Cannot handle this data type: (1, 1, 206), |u1

The error seems to come from the PIL module which is used internally by tensorboard. However, I am able to save this image manually using PIL.


Solution

  • I just found the answer in the tensorboardX documentation:

    A shape of (3, H, W) is expected instead of my shape of (H, W, 3).