<https://blog.csdn.net/briblue/article/details/79654482>

tf.nn.conv2d( input, filter, strides, padding, use_cudnn_on_gpu=True,
data_format='NHWC', dilations=[1, 1, 1, 1], name=None )

input: [batch, in_height, in_width, in_channels] filter [filter_height,
filter_width, in_channels, out_channels]
input 的 4 个参数很好理解，分别是批数量、高、宽、通道数。

y(n)=∑i=−∞∞x(i)∗h(n−i) y(n) = \sum_{i=-\infty}^{\infty} x(i)*h(n-i) y(n)=i=−∞∑∞
​x(i)∗h(n−i)

feature 组成了卷积后的 featuremap，而 N 就是 featuremap 的通道数。
input: [batch, in_height, in_width, in_channels] filter [filter_height,
filter_width, in_channels, out_channels]

<>代码实现

def _con_each(src_block,kernel): pixel_count = kernel.size; pixel_sum = 0; _src
= src_block.flatten(); _kernel = kernel.flatten(); for i in range(pixel_count):
pixel_sum+= _src[i]*_kernel[i]; return pixel_sum

import numpy as np def _conv_epoch(src_block,filter): input = src_block.flatten
() filter = filter.flatten().T return np.dot(input,filter)

""" input_size:(h,w,c) filter_size:(h,w,ic,oc) """ def conv(img,input_size,
filter_size,stride=1): ih = input_size[0] iw = input_size[1] ic = input_size[2]
filter_oc= filter_size[3] filter_h = filter_size[0] filter_w = filter_size[1]
filter_ic= filter_size[2] l = int((ih - filter_h) / stride + 1) m = int((iw -
filter_w) / stride + 1) result = np.zeros(shape=(l,m,filter_oc),dtype=np.uint8)
for i in range(l): for j in range(m): for k in range(filter_oc): f = np.random.
uniform(0,1,filter_w*filter_h*filter_ic).T input = img[i:i+filter_h,j:j+filter_w
,:] result[i,j,k] = _conv_epoch(input,f) return result

def test(): img = plt.imread("../datas/cat.jpg") print("img shape ",img.shape)
result= conv(img,img.shape,(3,3,img.shape[2],3)) plt.figure() plt.subplot(121)
plt.imshow(img) plt.subplot(122) plt.imshow(result) plt.show() test()

filter，它们通过一反复学习，最终形成了可靠的特征表达能力。