-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmain.lua
69 lines (56 loc) · 1.85 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'torch'
require 'nn'
require 'cudnn'
require 'paths'
require 'bnn'
require 'optim'
require 'gnuplot'
require 'image'
require 'xlua'
local utils = require 'utils'
local opts = require('opts')(arg)
torch.setheaptracking(true)
torch.setdefaulttensortype('torch.FloatTensor')
torch.setnumthreads(1)
local model
if opts.dataset == 'AFLWPIFA' then
print('Not available for the moment. Support will be added soon')
os.exit()
model = torch.load('models/facealignment_binary_pifa.t7')
else
model = torch.load('models/facealignment_binary_aflw.t7')
end
model:evaluate()
local fileLists = utils.getFileList(opts)
local predictions = {}
local noPoints = 68
if opts.dataset == 'AFLWPIFA' then noPoints = 34; end
local output = torch.CudaTensor(1,noPoints,64,64)
if opts.mode == 'eval' then
print('Not available for the moment. Support will be added soon')
os.exit()
xlua.progress(0,#fileLists)
end
for i = 1, #fileLists do
local img = image.load(fileLists[i].image)
local originalSize = img:size()
img = utils.crop(img, fileLists[i].center, fileLists[i].scale, 256)
img = img:cuda():view(1,3,256,256)
output:copy(model:forward(img))
output:add(utils.flip(utils.shuffleLR(opts, model:forward(utils.flip(img)))))
local preds_hm, preds_img = utils.getPreds(output, fileLists[i].center, fileLists[i].scale)
if opts.mode == 'demo' then
utils.plot(fileLists[i].image,preds_img:view(noPoints,2),torch.Tensor{originalSize[3],originalSize[2]})
io.read() -- Wait for user input
end
if opts.mode == 'eval' then
predictions[i] = preds_img:clone()
xlua.progress(i, #fileLists)
end
end
if opts.mode == 'demo' then gnuplot.closeall() end
if opts.mode == 'eval' then
predictions = torch.cat(predictions,1)
local dists = utils.calcDistance(predictions,fileLists)
utils.calculateMetrics(dists)
end