-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPool.lua
More file actions
59 lines (49 loc) · 1.44 KB
/
Pool.lua
File metadata and controls
59 lines (49 loc) · 1.44 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
48
49
50
51
52
53
54
55
56
57
58
59
local synchronize = require(script.Parent.Synchronize)
local pool = {
pool_size = 5,
pool_stride = 2
}
function pool.transform(input)
local data = {}
local pool_stride = pool.pool_stride
local pool_size = pool.pool_size
local pool_offset = math.floor(pool_size/2)
local width = input.shape.width
local height = input.shape.height
local depth = input.shape.depth
local shape = {
depth = depth,
height = math.floor((input.shape.height - 2 * pool_offset) / pool_stride),
width = math.floor((input.shape.width - 2 * pool_offset) / pool_stride)
}
local output = { shape = shape, data = data }
local threads = {}
for k = 1, depth do
local thread = coroutine.create(function()
for i = 1 + pool_offset, width - pool_offset, pool_stride do
for j = 1 + pool_offset, height - pool_offset, pool_stride do
local max = nil
for p = i - pool_offset, i + pool_offset do
for q = j - pool_offset, j + pool_offset do
local key = p..','..q..','..k
local value = input.data[key]
if max == nil then
max = value
else
max = math.max(max, value)
end
end
end
local r = 1 + (i - pool_offset - 1)/pool_stride
local s = 1 + (j - pool_offset - 1)/pool_stride
output.data[r..','..s..','..k] = max
end
end
end)
coroutine.resume(thread)
table.insert(threads, thread)
end
synchronize.all(threads, 'dead', 0.1)
return output
end
return pool