【问题标题】:Saving Dask DataFrame with image column to HDF5将带有图像列的 Dask DataFrame 保存到 HDF5
【发布时间】:2020-03-01 08:04:31
【问题描述】:

我正在尝试将不同大小的图像加载到 Dask DataFrame 列中,并将数据帧保存为 HDF5 文件格式。

这是标准方法:

import glob

import dask.dataframe as dd
import pandas as pd
import numpy as np
from skimage.io import imread


dir = '/Users/petioptrv/Downloads/mask'
filenames = glob.glob(dir + '/*.png')[:5]

df = pd.DataFrame({"paths": filenames})
ddf = dd.from_pandas(df, npartitions=2)
ddf['images'] = ddf['paths'].apply(imread, meta=('images', np.uint8))
ddf.to_hdf('test.h5', '/data')

我收到以下错误消息:

...
  File "/Users/petioptrv/miniconda3/envs/dask/lib/python3.7/site-packages/pandas/io/pytables.py", line 2214, in set_atom_string
    item=item, type=inferred_type
TypeError: Cannot serialize the column [images] because
its data contents are [mixed] object dtype

本质上,PyTables 检测到该列具有 object dtype 并检查它是否属于 str 类型。不是,所以会抛出异常。

我可以通过将图像打开为字节数组并将其转换为字符串来破解它,但这远非理想情况。

【问题讨论】:

  • 当你说“Spark”时,你的意思是“Dask”吗?
  • 是的,Dask DataFrame。感谢您指出这一点!修正了问题和描述。

标签: image dataframe dask hdf5


【解决方案1】:

尝试按照this 问题中的建议指定data_columns

ddf.to_hdf('test.h5', '/data', format = 'table', data_columns = ['images'])

【讨论】:

  • 感谢您的建议。试过了,但没有运气
猜你喜欢
  • 2019-01-16
  • 2020-04-14
  • 2019-10-30
  • 2015-03-08
  • 1970-01-01
  • 2019-02-05
  • 1970-01-01
  • 2017-01-06
  • 2018-08-10
相关资源
最近更新 更多