【问题标题】:holoviews doesn't display PIL image formatholoviews 不显示 PIL 图像格式
【发布时间】:2020-10-09 02:57:07
【问题描述】:

我正在尝试导入 MNIST 数据集并仅使用 Holoviews 显示它。当我运行以下命令时:

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

我在 'temp = hv.Image(...)' 的行收到以下错误:

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

“image”变量是以下对象:image.show() 正确渲染图像。另外,如果我使用 matplotlib 的.imshow(),我可以获得正确的渲染。

我想要看到在 Holoviews 中呈现的图像,我希望 Holoviews.Image() 会这样做。这不是一个正确的假设吗?如果是,那么代码/方法有什么问题?

【问题讨论】:

    标签: mnist holoviews


    【解决方案1】:

    HoloViews 使用数字数组而不是图像,因此hv.Image 用于从二维数组构造图像,而不是用于显示已经是图像的事物。但是您可以从 PIL 对象中获取数值数组,例如hv.RGB(np.array(image), bounds=bounds) 将其显示为 RGB 图像或类似的东西,仅提取灰度值以传递给 hv.Image

    【讨论】:

    • Tnx! hv.Image(np.array(image), bounds=bounds) 是分辨率。我曾假设 PIL 对象已经是一个数组......是的,“阅读文档!”。
    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    相关资源
    最近更新 更多