Skip to content

Commit

Permalink
Fixed bug in Middlebury dataset creation and loading
Browse files Browse the repository at this point in the history
  • Loading branch information
amitshaked committed Jan 20, 2017
1 parent af1d723 commit da3beb4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
1 change: 1 addition & 0 deletions scripts/mkdirs.sh
@@ -1,5 +1,6 @@
#! /bin/sh

mkdir -p tmp
mkdir -p out
mkdir -p storage
mkdir -p results
Expand Down
8 changes: 4 additions & 4 deletions scripts/preprocess_mb.py
Expand Up @@ -172,7 +172,7 @@ def tofile(fname, x):
save_pfm('tmp/disp1.pfm', disp1, 1)
save_pfm('tmp/disp0y.pfm', disp0y, 1)

subprocess.check_output('/home/amit/MiddEval3/code/computemask tmp/disp0.pfm tmp/disp0y.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())
subprocess.check_output('computemask tmp/disp0.pfm tmp/disp0y.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())

mask = cv2.imread('tmp/mask.png', 0)
disp0[mask != 255] = 0
Expand Down Expand Up @@ -220,7 +220,7 @@ def tofile(fname, x):
save_pfm('tmp/disp0.pfm', disp0, 1)
save_pfm('tmp/disp1.pfm', disp1, 1)

subprocess.check_output('/home/amit/MiddEval3/code/computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())
subprocess.check_output('computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())

mask = cv2.imread('tmp/mask.png', 0)
disp0[mask != 255] = 0
Expand Down Expand Up @@ -254,7 +254,7 @@ def tofile(fname, x):
save_pfm('tmp/disp0.pfm', disp0, 1)
save_pfm('tmp/disp1.pfm', disp1, 1)

subprocess.check_output('/home/amit/MiddEval3/code/computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())
subprocess.check_output('computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())

mask = cv2.imread('tmp/mask.png', 0)
disp0[mask != 255] = 0
Expand Down Expand Up @@ -298,7 +298,7 @@ def tofile(fname, x):

save_pfm('tmp/disp0.pfm', disp0, 1)
save_pfm('tmp/disp1.pfm', disp1, 1)
subprocess.check_output('/home/amit/MiddEval3/code/computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())
subprocess.check_output('computemask tmp/disp0.pfm tmp/disp1.pfm -1 tmp/mask.png'.split())

mask = cv2.imread('tmp/mask.png', 0)
disp0[mask != 255] = 0
Expand Down
2 changes: 1 addition & 1 deletion src/datasets/dataset.lua
Expand Up @@ -7,7 +7,7 @@ function Dataset:__init(self, opt)
cutorch.manualSeed(opt.seed)
self.__index = self
self.n_colors = opt.color == 'rgb' and 3 or 1
self:setParams()
self:setParams(opt)
self:load(opt)
if opt.a == 'train_mcn' or opt.a == 'train_gdn' then
self:prepareTrainingData(opt.subset, opt.all)
Expand Down
53 changes: 44 additions & 9 deletions src/datasets/mb.lua
@@ -1,14 +1,17 @@
Dataset = require('dataset')
Dataset = require('datasets/dataset')

local MbDataset, parent = torch.class('MbDataset',Dataset)
local MbDataset, parent = torch.class('MbDataset', 'Dataset')

function MbDataset:__init(self, opt)
parent.__init(parent, self, opt)
self.name='mb'
end

function MbDataset:setParams()
--parameters for training
local function createDataset(opt)
return MbDataset:new(opt)
end

function MbDataset:setParams(opt) --parameters for training
self.true1 = 0.5
self.false1 = 1.5
self.false2 = 6
Expand Down Expand Up @@ -83,11 +86,11 @@ function MbDataset:load(opt)
end

function MbDataset:subset(ds,tr, subset)
local tr_2014 = sample(torch.range(11, 23):long(), subset)
local tr_2006 = sample(torch.range(24, 44):long(), subset)
local tr_2005 = sample(torch.range(45, 50):long(), subset)
local tr_2003 = sample(torch.range(51, 52):long(), subset)
local tr_2001 = sample(torch.range(53, 60):long(), subset)
local tr_2014 = Dataset.sample(torch.range(11, 23):long(), subset)
local tr_2006 = Dataset.sample(torch.range(24, 44):long(), subset)
local tr_2005 = Dataset.sample(torch.range(45, 50):long(), subset)
local tr_2003 = Dataset.sample(torch.range(51, 52):long(), subset)
local tr_2001 = Dataset.sample(torch.range(53, 60):long(), subset)

local tr_subset = torch.cat(tr_2014, tr_2006)
tr_subset = torch.cat(tr_subset, tr_2005)
Expand Down Expand Up @@ -167,3 +170,35 @@ function MbDataset:getLR(img)
x1 = self.X[img][light_][{exp_,2}]
return x0, x1
end

function fromfile(fname)
-- initialize a tensor of the proper type and dimensions from the file fname
local file = io.open(fname .. '.dim')
local dim = {}
for line in file:lines() do
table.insert(dim, tonumber(line))
end
if #dim == 1 and dim[1] == 0 then
return torch.Tensor()
end

local file = io.open(fname .. '.type')
local type = file:read('*all')

local x
if type == 'float32' then
x = torch.FloatTensor(torch.FloatStorage(fname))
elseif type == 'int32' then
x = torch.IntTensor(torch.IntStorage(fname))
elseif type == 'int64' then
x = torch.LongTensor(torch.LongStorage(fname))
else
print(fname, type)
assert(false)
end

x = x:reshape(torch.LongStorage(dim))
return x
end

return createDataset

0 comments on commit da3beb4

Please sign in to comment.