-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxPoolingLayer.py
61 lines (58 loc) · 1.83 KB
/
MaxPoolingLayer.py
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
class MaxPoolingLayer(PoolingLayer):
def __init__(self, index, inputCoordinates, kernelDimension, padding, stride):
pass
def Instrument(self, instrumentation, input, output):
instrumentation[Index] = Instrumentation.MaxPoolingInstrumentation([None] * OutputDimension)
self.ApplyKernels(instrumentation, ApplyKernelConcrete, input)
def ApplyKernelConcrete(self, instr, input, outIndex, channel, row, column):
argMax = InputCoordinates.GetIndex(channel, row, column)
max = input[argMax]
i = 0
while i < KernelDimension:
j = 0
while j < KernelDimension:
if i == 0 and j == 0:
continue
x = row - Padding + i
y = column - Padding + j
if x >= InputCoordinates.RowCount or y >= InputCoordinates.ColumnCount:
continue
index = InputCoordinates.GetIndex(channel, x, y)
if index < 0 or index >= input.Count:
continue
if max < input[index]:
argMax = index
max = input[index]
j += 1
i += 1
if instr != None:
instr[Index].Selections[outIndex] = argMax
return max
def ApplyKernelSymbolic(self, state, input, outIndex, channel, row, column):
selections = state.Instrumentation[Index].Selections
maxIndex = selections[outIndex]
maxInput = input[maxIndex]
i = 0
while i < KernelDimension:
j = 0
while j < KernelDimension:
x = row - Padding + i
y = column - Padding + j
if x >= InputCoordinates.RowCount or y >= InputCoordinates.ColumnCount:
continue
curIndex = InputCoordinates.GetIndex(channel, x, y)
if curIndex == maxIndex:
continue
if curIndex < 0 or curIndex >= input.Length:
continue
# maxInput - input[curIndex] >= 0
t = LPSTerm.Const(0.0)
t.append(maxInput)
t.AddMul(input[curIndex], -1.0)
state.DeferredCts.And(t, InequalityType.GE)
j += 1
i += 1
return maxInput
def IsAffine(self):
return False