TensorFlow10.2 卷积神经网络-卷积神经网络池化层与采样

发布时间 2023-06-23 22:44:07作者: 哎呦哎(iui)

▪ Pooling
▪ upsample
▪ ReLU

我们看一下这个Subsampling层就是这个:这一层起到Reduce Dim的作用。
image

1 Max/Avg pooling(下采样)

keras.layers.MaxPooling2D(pool_size=,
strides=,
padding='valid',
data_format=None)
pool_size: 池化窗口大小
strides: 池化步长,默认值等于 pool_size
padding: 'VALID' 或 'SAME','VALID'表示无填充,'SAME'表示用0填充
data_format: 表示输入张量的维度顺序,默认为 [batch, height, width, channel]

1.1 Max/Avg pooling讲解

image
上面那个是stride=2的时候
image
当stride=1的时候
举个例子:
image
max pooling的话就是这个最大值。
image

1.2 Max/Avg pooling实现

Max/Avg pooling
image

2 upsample(上采样)

tf.keras.layers.UpSampling2D(
    size=(2, 2), data_format=None, interpolation='nearest', **kwargs
)

参数:
	size: int或者tuple,行与列的采样数,一个int表示两个值都相同。
    data_format: 数据格式。str, 默认"channels_last",还有"channels_first", 表示输入图片格式的通道是在前还是在后。
        一般我们输入的图片格式是[B,H,W,C]通道C是最后面的,因为比如openCV或者plt都是识别通道最后的。
        如果你输入的图片格式是[B,C,H,W]则需要选择"channels_first"
        
    interpolation: 差值方式,str,"nearest"最近采样方式 或者"bilinear" 双直线采样方式,默认"nearest"
        

image
image
UpSampling2D就是对图片数据在高与宽的方向进行数据插值倍增

ReLU层

image
它可以将一个黑的变成一个灰的。也就是将一个负的像素点,变成0.
image