import numpy as np
def pooling(feature_map, size=2, stride=2):
channel=feature_map.shape[0]
height=feature_map.shape[1]
width=feature_map.shape[2]
padding_height=np.uint16(round((height-size+1)/stride))
padding_width=np.uint16(round((width-size+1)/stride))
print(padding_height,padding_width)
pool_out = np.zeros((channel,padding_height,padding_width),dtype=np.uint8)
for map_num in range(channel):
out_height = 0
for r in np.arange(0,height, stride):
out_width = 0
for c in np.arange(0, width, stride):
pool_out[map_num,out_height, out_width] = np.max(feature_map[map_num,r:r+size,c:c+size])
out_width=out_width+1
out_height=out_height+1
return pool_out
if __name__ == "__main__":
input=np.fromfile('./file.bin',dtype=np.uint8)
input=input.reshape((16,608,608))
output=pooling(input,2,2)
print(output.dtype)
print(output.shape)
output.tofile('./out.bin')
用numpy实现MaxPooling
最新推荐文章于 2025-03-25 13:38:05 发布