From 0c85640e6eca09ca40b5ffefd7a31b12ab223207 Mon Sep 17 00:00:00 2001 From: Qiang Zhang Date: Mon, 29 Aug 2016 20:53:56 -0700 Subject: [PATCH 1/2] Use FloatTensor(3, 256, 256):fix(.5) as image in case of reading error for the image --- datasets/imagenet.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/datasets/imagenet.lua b/datasets/imagenet.lua index a28294ee3..b6db97e3e 100644 --- a/datasets/imagenet.lua +++ b/datasets/imagenet.lua @@ -49,7 +49,11 @@ function ImagenetDataset:_loadImage(path) assert(f, 'Error reading: ' .. tostring(path)) 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)) From ffa854309073d1b0df1a1dfa41659f02e139abe4 Mon Sep 17 00:00:00 2001 From: Qiang Zhang Date: Tue, 30 Aug 2016 21:42:03 -0700 Subject: [PATCH 2/2] Update imagenet.lua --- datasets/imagenet.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/datasets/imagenet.lua b/datasets/imagenet.lua index b6db97e3e..2b35cacb9 100644 --- a/datasets/imagenet.lua +++ b/datasets/imagenet.lua @@ -46,7 +46,11 @@ 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