Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Use FloatTensor(3, 256, 256):fill(.5) as image in case of reading error #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions datasets/imagenet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ function ImagenetDataset:_loadImage(path)
-- image format. In that case, use image.decompress on a ByteTensor.
if not ok then
local f = io.open(path, 'r')
assert(f, 'Error reading: ' .. tostring(path))
if not f then
print('unable to read file: ' .. tostring(path))
-- In this bad case, just fill a mean image.
return torch.FloatTensor(3, 256, 256):fill(.5)
end
local data = f:read('*a')
f:close()

if data == nil then
print('unable to read file: ' .. tostring(path))
-- In this bad case, just fill a mean image.
return torch.FloatTensor(3, 256, 256):fill(.5)
end
local b = torch.ByteTensor(string.len(data))
ffi.copy(b:data(), data, b:size(1))

Expand Down