Skip to content

Commit

Permalink
Merge pull request #12 from fmassa/list_imgs
Browse files Browse the repository at this point in the history
Improve robustness of DataLoaderRaw for non-image files
  • Loading branch information
karpathy committed Nov 25, 2015
2 parents 02ad2e2 + 26f2e52 commit 4b0fad3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions misc/DataLoaderRaw.lua
Expand Up @@ -30,14 +30,22 @@ function DataLoaderRaw:__init(opt)
else
-- read in all the filenames from the folder
print('listing all images in directory ' .. opt.folder_path)
local function isImage(f)
local supportedExt = {'.jpg','.JPEG','.JPG','.png','.PNG','.ppm','.PPM'}
for _,ext in pairs(supportedExt) do
local _, end_idx = f:find(ext)
if end_idx and end_idx == f:len() then
return true
end
end
return false
end
local n = 1
for file in lfs.dir(opt.folder_path) do
for file in paths.files(opt.folder_path, isImage) do
local fullpath = path.join(opt.folder_path, file)
if lfs.attributes(fullpath,"mode") == "file" then
table.insert(self.files, fullpath)
table.insert(self.ids, tostring(n)) -- just order them sequentially
n=n+1
end
table.insert(self.files, fullpath)
table.insert(self.ids, tostring(n)) -- just order them sequentially
n=n+1
end
end

Expand Down

0 comments on commit 4b0fad3

Please sign in to comment.