【问题标题】:Writing Tables in Torch to file在 Torch 中将表写入文件
【发布时间】:2016-08-17 18:24:10
【问题描述】:

我正在尝试将一些字符串表保存到 Torch 中的文件中。我试过使用 Deepmind 的 Torch 扩展:hdf5。

require 'hdf5'
label = {'a', 'b','c','d'}

local myFile = hdf5.open(features_repo .. 't.h5', 'w')
myFile:write('label', label)
myFile:close()

我收到错误:

/home/user/torch/install/bin/luajit: ...e/user/torch/install/share/lua/5.1/hdf5/group.lua:222: torch-hdf5: writing data of type string is not supported

Torch 张量按预期写入文件。

我也尝试使用matio 写入 mat 文件(用于 MatLab)。我收到此错误:

bad argument #1 to 'varCreate' (cannot convert 'number' to 'const char *')

【问题讨论】:

    标签: lua hdf5 torch


    【解决方案1】:

    您可以使用模块 (https://github.com/aryajur/tableUtils.git) 中的函数 t2s 生成可以保存到文件的字符串。要转换回来,只需使用函数 s2t。

    【讨论】:

      【解决方案2】:

      错误是因为“标签”是一个字符串表,但函数HDF5Group:_writeData 需要一种“张量”形式。

      查看ffi.lua,似乎“张量”是“整数”的typedef,所以也许替换:

      label = {'a', 'b','c','d'}
      

      与 标签 = {1,2,3,4}

      【讨论】:

      • 不幸的是,我需要保存字符串。
      猜你喜欢
      • 2016-10-20
      • 2016-09-02
      • 2019-02-02
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多