【问题标题】:Error when saving images to an HDF5 file in Lua在 Lua 中将图像保存到 HDF5 文件时出错
【发布时间】:2018-08-10 05:03:10
【问题描述】:

尝试将 Lua 中的一堆图像转换为 HDF5 文件时,出现以下错误:

/home/ubuntu/torch/install/bin/luajit: /home/ubuntu/torch/install/share/lua/5.1/hdf5/group.lua:97: attempt to call method 'adjustForData' (a nil value)
stack traceback:
        /home/ubuntu/torch/install/share/lua/5.1/hdf5/group.lua:97: in function '_writeData'
        /home/ubuntu/torch/install/share/lua/5.1/hdf5/group.lua:307: in function '_write_or_append'
        /home/ubuntu/torch/install/share/lua/5.1/hdf5/group.lua:270: in function </home/ubuntu/torch/install/share/lua/5.1/hdf5/group.lua:269>
        /home/ubuntu/torch/install/share/lua/5.1/hdf5/file.lua:84: in function '_write_or_append'
        /home/ubuntu/torch/install/share/lua/5.1/hdf5/file.lua:58: in function 'write'

这是发生错误的地方:

for i = 1, #input_images_caffe do
   newFile:write('images', input_images_caffe[i], 'w')
end

input_image_caffe里面的图片,来自:

  local input_size = math.ceil(params.input_scale * params.image_size)
  local input_image_list = params.input_image:split(',')
  local input_images_caffe = {}
  local img_caffe
  for _, img_path in ipairs(input_image_list) do
    local img = image.load(img_path, 3)
    img = image.scale(img, input_size, 'bilinear')
    img_caffe = preprocess(img):float()
    table.insert(input_images_caffe, img_caffe)
  end

此函数用于对图像进行预处理:

function preprocess(img)
  local mean_pixel = torch.DoubleTensor({103.939, 116.779, 123.68})
  local perm = torch.LongTensor{3, 2, 1}
  img = img:index(1, perm):mul(256.0)
  mean_pixel = mean_pixel:view(3, 1, 1):expandAs(img)
  img:add(-1, mean_pixel)
  return img
end

input_images_caffe 可能包含的一些示例:

{
  1 : FloatTensor - size: 3x405x512
  2 : FloatTensor - size: 3x512x393
}

或者:

{
  1 : FloatTensor - size: 3x405x512
}

HDF5 使用以下命令创建:

  local newFile = hdf5.open(params.output_hdf5, 'w')

我正在使用torch-hdf5 库:

https://github.com/deepmind/torch-hdf5

我不确定我在这里做错了什么?

【问题讨论】:

    标签: lua hdf5 torch tensor


    【解决方案1】:

    newFile:write('images', input_images_caffe[i], 'w')

    改用newFile:write('images', input_images_caffe[i])third parameter 应该是一个(可选的)options 对象,但您传递的是一个没有 adjustForData 方法的字符串,因此您得到了错误。

    【讨论】:

    • 谢谢,解决了这个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2021-07-14
    • 2013-05-31
    相关资源
    最近更新 更多