-
Notifications
You must be signed in to change notification settings - Fork 0
/
avg_pool.py
34 lines (21 loc) · 1001 Bytes
/
avg_pool.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
import numpy as np
import utils as ut
import math
class AveragePool:
def __init__(self, patch_size):
self.feature_maps = None
self.patch_size = patch_size
self.patches = None
def forward(self, feature_maps):
patches = []
self.feature_maps = feature_maps
for i in range(len(self.feature_maps)):
subarray = ut.extract_subarrays(self.feature_maps[i], self.patch_size)
patched_average = []
for j in range(len(subarray)):
patched_average.append(np.mean(subarray[j]))
patched_average = np.array(patched_average)
flatten_patch_length = len(patched_average)
patches.append(patched_average.reshape(int(math.sqrt(flatten_patch_length)), int(math.sqrt(flatten_patch_length))))
self.patches = np.array(patches)
return self.patches