This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathcomputeProposals.lua
92 lines (74 loc) · 2.68 KB
/
computeProposals.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--[[----------------------------------------------------------------------------
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
Run full scene inference in sample image
------------------------------------------------------------------------------]]
require 'torch'
require 'cutorch'
require 'image'
--------------------------------------------------------------------------------
-- parse arguments
local cmd = torch.CmdLine()
cmd:text()
cmd:text('evaluate deepmask/sharpmask')
cmd:text()
cmd:argument('-model', 'path to model to load')
cmd:text('Options:')
cmd:option('-img','data/testImage.jpg' ,'path/to/test/image')
cmd:option('-gpu', 1, 'gpu device')
cmd:option('-np', 5,'number of proposals to save in test')
cmd:option('-si', -2.5, 'initial scale')
cmd:option('-sf', .5, 'final scale')
cmd:option('-ss', .5, 'scale step')
cmd:option('-dm', false, 'use DeepMask version of SharpMask')
local config = cmd:parse(arg)
--------------------------------------------------------------------------------
-- various initializations
torch.setdefaulttensortype('torch.FloatTensor')
cutorch.setDevice(config.gpu)
local coco = require 'coco'
local maskApi = coco.MaskApi
local meanstd = {mean = { 0.485, 0.456, 0.406 }, std = { 0.229, 0.224, 0.225 }}
--------------------------------------------------------------------------------
-- load moodel
paths.dofile('DeepMask.lua')
paths.dofile('SharpMask.lua')
print('| loading model file... ' .. config.model)
local m = torch.load(config.model..'/model.t7')
local model = m.model
model:inference(config.np)
model:cuda()
--------------------------------------------------------------------------------
-- create inference module
local scales = {}
for i = config.si,config.sf,config.ss do table.insert(scales,2^i) end
if torch.type(model)=='nn.DeepMask' then
paths.dofile('InferDeepMask.lua')
elseif torch.type(model)=='nn.SharpMask' then
paths.dofile('InferSharpMask.lua')
end
local infer = Infer{
np = config.np,
scales = scales,
meanstd = meanstd,
model = model,
dm = config.dm,
}
--------------------------------------------------------------------------------
-- do it
print('| start')
-- load image
local img = image.load(config.img)
local h,w = img:size(2),img:size(3)
-- forward all scales
infer:forward(img)
-- get top propsals
local masks,_ = infer:getTopProps(.2,h,w)
-- save result
local res = img:clone()
maskApi.drawMasks(res, masks, 10)
image.save(string.format('./res.jpg',config.model),res)
print('| done')
collectgarbage()