Skip to content

Commit

Permalink
generate correct prob for RNN
Browse files Browse the repository at this point in the history
add more gitignore
  • Loading branch information
chihyaoma committed Mar 28, 2017
1 parent fb9b554 commit f788f1f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
2 changes: 1 addition & 1 deletion RNN/.gitignore
Expand Up @@ -2,4 +2,4 @@ gen/
runjob-fullVideo.sh
log/
trash/

.DS_Store
8 changes: 5 additions & 3 deletions RNN/main.lua
Expand Up @@ -45,7 +45,7 @@ cmd:option('-silent', false, 'don`t print anything to stdout')
cmd:option('-uniform', 0.1, 'initialize parameters using uniform distribution between -uniform and uniform. -1 means default initialization')
cmd:option('-seqCriterion', false, 'use SequencerCriterion or not. Note to use smaller LR')
-- recurrent layer
cmd:option('-lstm', true, 'use Long Short Term Memory (nn.LSTM instead of nn.Recurrent)')
cmd:option('-lstm', false, 'use Long Short Term Memory (nn.LSTM instead of nn.Recurrent)')
cmd:option('-bn', false, 'use batch normalization. Only supported with --lstm')
cmd:option('-gru', false, 'use Gated Recurrent Units (nn.GRU instead of nn.Recurrent)')
cmd:option('-numSegment', 3, 'number of segments for each video')
Expand Down Expand Up @@ -128,6 +128,9 @@ local data = require 'data-ucf101'
local train = require 'train'
local test = require 'test'

-- initialize bestAcc
bestAcc = 0

if opt.testOnly then
-- Begin testing with trained model
test(data.testData, data.testTarget)
Expand All @@ -137,8 +140,7 @@ end
------------------------------------------------------------
-- Run
------------------------------------------------------------
-- initialize bestAcc
bestAcc = 0


print(sys.COLORS.red .. '==> training!')
for iteration = 1, opt.maxEpoch do
Expand Down
9 changes: 7 additions & 2 deletions RNN/test.lua
Expand Up @@ -42,11 +42,16 @@ local prob = {}
predsFrames = torch.Tensor(opt.batchSize, nClass, opt.rho - opt.numSegment + 1)
-- end

local logsoftmax = nn.LogSoftMax()

if opt.cuda == true then
inputs = inputs:cuda()
targets = targets:cuda()
logsoftmax = logsoftmax:cuda()
end



-- test function
function test(testData, testTarget)

Expand Down Expand Up @@ -162,7 +167,7 @@ function test(testData, testTarget)
end

preds = model:forward(inputsSegments)
preds:exp()
preds = logsoftmax:forward(preds):exp()
end

-- discard the redundant predictions and targets
Expand Down Expand Up @@ -233,7 +238,7 @@ function test(testData, testTarget)
torch.save(opt.save .. '/prob.txt', prob,'ascii')

if opt.saveModel == true then
if confusion.totalValid * 100 >= 92 then
if confusion.totalValid * 100 >= 94.2 then
checkpoints.save(epoch-1, model, optimState, bestModel, confusion.totalValid*100)
end
end
Expand Down

0 comments on commit f788f1f

Please sign in to comment.