Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Tables in Torch to file

Tags:

hdf5

torch

lua

I am trying to save some tables of strings to files in Torch. I have tried using this Torch extension by Deepmind: hdf5.

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

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

I am getting the error:

/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 are written to file as intended.

I have also tried using matio to write to mat files (for MatLab). I am getting this error:

bad argument #1 to 'varCreate' (cannot convert 'number' to 'const char *')
like image 327
Chris Parry Avatar asked Apr 24 '16 11:04

Chris Parry


1 Answers

The error is because "label" is a table of strings, but the function HDF5Group:_writeData is expecting a form of "tensor".

Looking at ffi.lua, it seems that the "tensor" is a typedef for "integer", so maybe replace:

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

with label = {1,2,3,4}

like image 91
prasoc Avatar answered Nov 01 '22 16:11

prasoc