1

I have images which have saved in the desk. The data saved as follow: 4 main folders (1,2,3 and 4) each folder has 26 subfolders ( these subfolders represent the class of images (A, B, C, D, ..,Z)). Each of these subfolder contains more than 500 images. However, I am looking for file or code in torch that can read these images. In MATLAB I could wrote a code but here I find it confuse. Could you please advise me.

4

1 回答 1

1

您可以做的是使用Penlight (安装Torch 时会安装该库)。

Penlightpl.dir使扫描(子)文件夹中的文件变得容易。例如,您可以做的是:

local pl = require('pl.import_into')()
local t = {}
for i,f in ipairs(pl.dir.getallfiles('/data/foo', '*.jpg')) do
    t[i] = { f, pl.path.basename(pl.path.dirname(f)) }
end

这将创建一个对列表(文件名、类标签 = "A" 或 "B" ...)。当然,您可以随意更改文件模式 ( *.jpg) 或省略它(在这种情况下,Penlight 将简单地列出所有文件)。您还可以即时加载图像:

t[i] = { image.load(f), pl.path.basename(pl.path.dirname(f)) }

或者在操作之后立即执行此操作t

于 2015-07-16T07:41:16.587 回答