为了能理解conv2d函数,最好的学习就是自己再制造它,那就用代码模拟conv2d里体是怎么计算的。
import math
def conv2d(input, filter, **kwargs):
strides= 'strides' in kwargs and kwargs['strides'] or [1,1,1,1]
padding = 'padding' in kwargs and kwargs['padding'] or 'SAME'
assert(padding =='SAME' or padding =='VALID')
assert(strides[0]==1 and strides[3]==1)
in_batch =len(input)
in_height =len(input[0])
in_width =len(input[0][0])
in_channel=len(input[0][0][0])
fi_height = len(filter)
fi_width = len(filter[0])
assert(in_channel==len(filter[0][0]))
out_channel = len(filter[0][0][0])
if padding == "VALID":
assert(in_height >= fi_height)
assert(in_width >= fi_width)
def take_sample(T, i, j):
M = []
for y in range(f