class Pooling:
def __init__(self,pool_h,pool_w,stride=1,pad=0):
self.pool_h=pool_h
self.pool_w=pool_w
self.stride=stride
self.pad=pad
def forward(self,x):
N,C,H,W = x.shape
out_h = int(1+ (H - self.pool_h)/self.stride)
out_w = int(1+ (W- self.pool_w)/self.stride)
#전개(1)
col= im2col(x,self.pool_h, self.pool_w,self.stride,self.pad)
col= col.reshape(-1,self.pool_h * self.pool_w)
# 최댓값(2)
out = np.max(col,axis=1)
# 성형 (3)
out = out.reshape(N, out_h,out_w,C).transpose(0,3,1,2)
return out
x = np.array([[[21,8,8,12],[12,19,9,7],[8,10,4,3],[18,12,9,10]],
[[19,8,7,12],[1,19,9,7],[4,2,4,3],[4,12,9,10]],
[[2,8,8,12],[10,19,9,7],[5,6,4,3],[1,12,9,12]]])
a = x.reshape(1, 3, 4, 4)
pool = Pooling(2, 2, stride = 2, pad = 0)
print(pool.forward(a))