-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathprocess.lua
More file actions
47 lines (40 loc) · 1.18 KB
/
process.lua
File metadata and controls
47 lines (40 loc) · 1.18 KB
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
local process = {} -- process object
local function multiscale(img, network)
assert(require('image'))
local eye = opt.is
local scaled = nil
if img:dim() == 4 and img:size(1) == 1 then
img = img:squeeze(1)
end
if img:dim() == 3 then
-- no batch case
scaled = image.scale(img,'^' .. eye)
-- normalize the input:
for c = 1,3 do
scaled[c]:add(-network.stat.mean[c])
scaled[c]:div( network.stat.std [c])
end
end
return scaled
end
local function prep_spatial_0_cpu(opt, source, network)
assert(require('image'))
local eye = opt.is
local side = math.min(source.h, source.w)
local x1 = source.w / 2 - side / 2
local y1 = source.h / 2 - side / 2
local x2 = source.w / 2 + side / 2
local y2 = source.h / 2 + side / 2
local cropped = nil
process.forward = function(img)
cropped = image.crop(img, x1, y1, x2, y2)
local scaled = multiscale(cropped, network)
-- computing network output
local results = network.model:forward(scaled)
return results, cropped
end
end
function process:init(opt, source, network)
prep_spatial_0_cpu(opt, source, network)
end
return process