forked from cmusatyalab/openface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile-network.lua
executable file
·49 lines (38 loc) · 1.04 KB
/
profile-network.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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:')
cmd:option('-model', './models/openface/nn4.v1.t7', 'Path to model.')
cmd:option('-imgDim', 96, 'Image dimension. nn1=224, nn4=96')
cmd:option('-numIter', 500)
cmd:option('-cuda', false)
cmd:text()
opt = cmd:parse(arg or {})
-- print(opt)
net = torch.load(opt.model):float()
net:evaluate()
-- print(net)
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
times = torch.Tensor(opt.numIter)
for i=1,opt.numIter do
timer = torch.Timer()
rep = net:forward(img[i])
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)))