【问题标题】:torch7: Unable to load BMP imagestorch7:无法加载 BMP 图像
【发布时间】:2016-05-09 03:43:22
【问题描述】:

我正在尝试加载一些图像来训练我的 conv-net。为此,我正在使用 torch7 的“image”包。但是,在加载图像时如下:

local img_raw = image.load(train_path .. train_files[i]):mul(255)

我在尝试加载 BMP 文件时收到以下错误:

/path/to/torch/install/bin/luajit: /path/to/torch/install/share/lua/5.1/dok/inline.lua:737: <image.load> unknown image type: bmp
stack traceback:
    [C]: in function 'error'
    /path/to/torch/install/share/lua/5.1/dok/inline.lua:737: in function 'error'
    /path/to/torch/install/share/lua/5.1/image/init.lua:337: in function 'load'
    final_2.lua:310: in main chunk
    [C]: in function 'dofile'
    .../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:131: in main chunk
    [C]: at 0x00406670

有人可以建议一些方法来加载 BMP 图像以在 torch7 中进行进一步处理吗?

提前致谢。

【问题讨论】:

  • 找到支持它们的库或为image 包编写对该格式的支持?
  • 或者:使用这个Lua / Torch wrapper around graphicsmagick。或者使用 {image,graphics}magick 预先将您的图像转换为 PNG 或 PPM 格式。
  • @deltheil,谢谢。我安装了 graphicsmagick 包,但在导入脚本时遇到了问题。因此,我决定将我必须的少数 BMP 图像转换为 JPEG 格式,从而绕过了上述错误。

标签: image lua bmp torch


【解决方案1】:

为了完整起见,我将在这里抛出一些代码:

首先,安装图形魔法

$ luarocks install graphicsmagick

然后

require 'image'
gm = require 'graphicsmagick'

-- change the string
local jpg_filename = string.gsub(train_files[i],".[Bb][Mm][Pp]$",".jpg")
-- get the info so we can build the size string
local image_info = gm.info(train_path .. train_files[i])
-- convert takes a size string h x w
local size_string = image_info["height"] .. "x" .. image_info["width"]

gm.convert{
  input = train_path .. train_files[i],
  output = train_path .. jpg_filename,
  size = size_string,
  quality = 95,
  verbose = true
}
local img_raw = image.load(train_path .. jpg_filename):mul(255)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 2016-07-22
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    相关资源
    最近更新 更多