holoviews doesn't display PIL image format

286 views Asked by At

I am trying to import the MNIST data set and just display it using Holoviews. When I run the following:

import holoviews as hv
from torchvision import datasets, transforms

hv.extension('bokeh')

mnist_images = datasets.MNIST('data', train=True, download=True)

image_list = []
for k, (image, label) in enumerate(mnist_images):
    if k >= 18:
        break
    image.show()
    bounds = (0,0,1,1)
    temp = hv.Image(image, bounds=bounds)
    image_list.append(temp)

layout = hv.Layout(image_list).cols(2)
layout

I get the following error at the line with 'temp = hv.Image(...)':

holoviews.core.data.interface.DataError: None of the available storage backends were able to support the supplied data format.

The 'image' variable is the following object: <PIL.Image.Image image mode=L size=28x28 at 0x7F7F28567910> and image.show() renders the image correctly. Also if I use matplotlib's .imshow() I can get a correct render.

What I want is to see the image rendered in Holoviews and I expected the Holoviews.Image() would do that. Is that not a correct assumption? If it is, then what is wrong with the code/approach?

1

There are 1 answers

1
James A. Bednar On BEST ANSWER

HoloViews works with numerical arrays rather than images, so hv.Image is for constructing an image out of a 2D array, not for showing things that are already images. But you can get numerical arrays out of PIL objects, e.g. hv.RGB(np.array(image), bounds=bounds) to display it as an RGB image or something similar to pull out just the grayscale values to pass to hv.Image.