我正在尝试将一些字符串表保存到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 Tensors按预期写入文件。
我也尝试使用matio写入mat文件(对于MatLab)。我收到了这个错误:
bad argument #1 to 'varCreate' (cannot convert 'number' to 'const char *')
答案 0 :(得分:2)
错误是因为“label”是一个字符串表,但函数HDF5Group:_writeData
期待一种“张量”形式。
看ffi.lua
,似乎“张量”是“整数”的typedef,所以也许替换:
label = {'a', 'b','c','d'}
与 label = {1,2,3,4}
答案 1 :(得分:0)
您可以使用模块中的函数t2s(https://github.com/aryajur/tableUtils.git)生成可以保存到文件的字符串。要转换回来,只需使用功能s2t。