def bilinear_interpolation_kernel(in_channels, out_channels, ksize):
"""calculate a bilinear interpolation kernel
Args:
in_channels (int): Number of channels of input arrays. If ``None``,
parameter initialization will be deferred until the first forward
data pass at which time the size will be determined.
out_channels (int): Number of channels of output arrays.
ksize (int): Size of filters (a.k.a. kernels).
"""
factor = (ksize + 1) / 2
if ksize % 2 == 1:
center = factor - 1
else:
center = factor - 0.5
og = np.ogrid[:ksize, :ksize]
k = (1 - abs(og[0] - center) / factor) * (1 - abs(og[1] - center) / factor)
W = np.zeros((in_channels, out_channels, ksize, ksize)).astype(np.float32)
W[range(in_channels), range(out_channels), :, :] = k
return W
functions.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录