Skip to content

Commit

Permalink
Spacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gulvarol committed Nov 24, 2017
1 parent 0820b5e commit dec1ff7
Show file tree
Hide file tree
Showing 9 changed files with 737 additions and 738 deletions.
46 changes: 23 additions & 23 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ Threads.serialization('threads.sharedserialize')
-- For the data-loading details, look at donkey.lua
-------------------------------------------------------------------------------
do -- start K datathreads (donkeys)
if opt.nDonkeys > 0 then
local options = opt -- make an upvalue to serialize over to donkey threads
donkeys = Threads(
opt.nDonkeys,
function()
require 'torch'
paths.dofile('trainplot/TrainPlotter.lua')
end,
function(idx)
opt = options -- pass to all donkeys via upvalue
tid = idx
local seed = opt.manualSeed + idx
torch.manualSeed(seed)
print(string.format('Starting donkey with id: %d seed: %d', tid, seed))
paths.dofile('donkey.lua')
end
);
else -- single threaded data loading. useful for debugging
paths.dofile('donkey.lua')
donkeys = {}
function donkeys:addjob(f1, f2) f2(f1()) end
function donkeys:synchronize() end
end
if opt.nDonkeys > 0 then
local options = opt -- make an upvalue to serialize over to donkey threads
donkeys = Threads(
opt.nDonkeys,
function()
require 'torch'
paths.dofile('trainplot/TrainPlotter.lua')
end,
function(idx)
opt = options -- pass to all donkeys via upvalue
tid = idx
local seed = opt.manualSeed + idx
torch.manualSeed(seed)
print(string.format('Starting donkey with id: %d seed: %d', tid, seed))
paths.dofile('donkey.lua')
end
);
else -- single threaded data loading. useful for debugging
paths.dofile('donkey.lua')
donkeys = {}
function donkeys:addjob(f1, f2) f2(f1()) end
function donkeys:synchronize() end
end
end

nClasses = nil
Expand Down
68 changes: 34 additions & 34 deletions dataset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,41 +379,41 @@ function dataset:get(i1, i2)
end

function dataset:computeAccuracy(scores)
local N, M, P, S, X
-- Load dataLoader for videos ('self' dataLoader is for clips)
local testCacheVid = torch.load(paths.concat(opt.logRoot, opt.dataset, 'cache', opt.stream, 'testCache.t7'))
--assert(self.numSamples == scores:size(1))

-- Find clip-video correspondence
local clips = torch.Tensor(scores:size(1))
for i = 1, scores:size(1) do
N = ffi.string(torch.data(self.imagePath[i])) --v_ApplyEyeMakeup_g01_c01.avi_0017.avi
N = paths.basename(N, 'avi') --v_ApplyEyeMakeup_g01_c01.avi_0017
N = paths.basename(N, paths.extname(N)) --v_ApplyEyeMakeup_g01_c01
local N, M, P, S, X
-- Load dataLoader for videos ('self' dataLoader is for clips)
local testCacheVid = torch.load(paths.concat(opt.logRoot, opt.dataset, 'cache', opt.stream, 'testCache.t7'))
--assert(self.numSamples == scores:size(1))

-- Find clip-video correspondence
local clips = torch.Tensor(scores:size(1))
for i = 1, scores:size(1) do
N = ffi.string(torch.data(self.imagePath[i])) --v_ApplyEyeMakeup_g01_c01.avi_0017.avi
N = paths.basename(N, 'avi') --v_ApplyEyeMakeup_g01_c01.avi_0017
N = paths.basename(N, paths.extname(N)) --v_ApplyEyeMakeup_g01_c01

for j = 1, testCacheVid.numSamples do
if(N == paths.basename(ffi.string(torch.data(testCacheVid.imagePath[j])), 'avi')) then
clips[i] = j
break
end
end
end

-- Loop over videos to take mean over clip scores and compute accuracy
local acc = 0
for i = 1, testCacheVid.numSamples do
X = clips:eq(i) -- 0,1 vector of clips belonging to same video
if(X:any()) then -- normally always true
X = torch.nonzero(X) -- indices of clips belonging to same video
S = scores:index(1,X:select(2,1)) -- scores of clips from the same video
S = S:mean(1) -- mean over clips
M, P = torch.max(S, 2) -- max score -> predicted class
if(P:squeeze() == testCacheVid.imageClass[i]) then -- pred==gt
acc = acc + 1
end
end
end
return 100*acc/testCacheVid.numSamples
for j = 1, testCacheVid.numSamples do
if(N == paths.basename(ffi.string(torch.data(testCacheVid.imagePath[j])), 'avi')) then
clips[i] = j
break
end
end
end

-- Loop over videos to take mean over clip scores and compute accuracy
local acc = 0
for i = 1, testCacheVid.numSamples do
X = clips:eq(i) -- 0,1 vector of clips belonging to same video
if(X:any()) then -- normally always true
X = torch.nonzero(X) -- indices of clips belonging to same video
S = scores:index(1,X:select(2,1)) -- scores of clips from the same video
S = S:mean(1) -- mean over clips
M, P = torch.max(S, 2) -- max score -> predicted class
if(P:squeeze() == testCacheVid.imageClass[i]) then -- pred==gt
acc = acc + 1
end
end
end
return 100*acc/testCacheVid.numSamples
end

return dataset
Loading

0 comments on commit dec1ff7

Please sign in to comment.