2015-10-12 04:55:56 +08:00
|
|
|
#!/usr/bin/env th
|
|
|
|
--
|
|
|
|
-- Outputs the number of parameters in a network for a single image
|
|
|
|
-- in evaluation mode.
|
|
|
|
|
|
|
|
require 'torch'
|
|
|
|
require 'nn'
|
|
|
|
require 'dpnn'
|
|
|
|
|
|
|
|
torch.setdefaulttensortype('torch.FloatTensor')
|
|
|
|
|
|
|
|
local cmd = torch.CmdLine()
|
|
|
|
cmd:text()
|
|
|
|
cmd:text('Network Size.')
|
|
|
|
cmd:text()
|
|
|
|
cmd:text('Options:')
|
|
|
|
|
2016-01-13 04:46:49 +08:00
|
|
|
cmd:option('-model', './models/openface/nn4.small2.v1.t7', 'Path to model.')
|
2015-10-12 04:55:56 +08:00
|
|
|
cmd:option('-imgDim', 96, 'Image dimension. nn1=224, nn4=96')
|
2015-10-14 03:18:47 +08:00
|
|
|
cmd:option('-numIter', 500)
|
2015-10-12 04:55:56 +08:00
|
|
|
cmd:option('-cuda', false)
|
|
|
|
cmd:text()
|
|
|
|
|
2015-12-27 21:41:49 +08:00
|
|
|
local opt = cmd:parse(arg or {})
|
2015-10-12 04:55:56 +08:00
|
|
|
-- print(opt)
|
|
|
|
|
2015-12-27 21:41:49 +08:00
|
|
|
local net = torch.load(opt.model):float()
|
2015-10-12 04:55:56 +08:00
|
|
|
net:evaluate()
|
|
|
|
|
|
|
|
local img = torch.randn(opt.numIter, 1, 3, opt.imgDim, opt.imgDim)
|
|
|
|
|
|
|
|
if opt.cuda then
|
|
|
|
require 'cutorch'
|
|
|
|
require 'cunn'
|
|
|
|
net = net:cuda()
|
|
|
|
img = img:cuda()
|
|
|
|
end
|
|
|
|
|
2015-12-27 21:41:49 +08:00
|
|
|
local times = torch.Tensor(opt.numIter)
|
2015-10-12 04:55:56 +08:00
|
|
|
|
|
|
|
for i=1,opt.numIter do
|
2015-12-27 21:41:49 +08:00
|
|
|
local timer = torch.Timer()
|
|
|
|
local _ = net:forward(img[i])
|
2015-10-12 04:55:56 +08:00
|
|
|
times[i] = 1000.0*timer:time().real
|
|
|
|
end
|
|
|
|
|
|
|
|
print(string.format('Single image forward pass: %.2f ms +/- %.2f ms',
|
|
|
|
torch.mean(times), torch.std(times)))
|