池化与采样

Outline

  • Pooling

  • upsample

  • ReLU

Reduce Dim

36-池化与采样-降维.jpg

subsample

Max/Avg pooling

  • stride = 2

36-池化与采样-池化.jpg

Strides

  • stride = 1

36-池化与采样-池化步长1.jpg

For instance

36-池化与采样-池化all.jpg

import tensorflow as tf
from tensorflow.keras import layers
x = tf.random.normal([1, 14, 14, 4])
x.shape
TensorShape([1, 14, 14, 4])
pool = layers.MaxPool2D(2, strides=2)
out = pool(x)
out.shape
TensorShape([1, 7, 7, 4])
pool = layers.MaxPool2D(3, strides=2)
out = pool(x)
out.shape
TensorShape([1, 6, 6, 4])
out = tf.nn.max_pool2d(x, 2, strides=2, padding='VALID')
out.shape
TensorShape([1, 7, 7, 4])

upsample

  • nearest

  • bilinear

36-池化与采样-上采样.jpg

UpSampling2D

x = tf.random.normal([1, 7, 7, 4])
x.shape
TensorShape([1, 7, 7, 4])
layer = layers.UpSampling2D(size=3)
out = layer(x)
out.shape
TensorShape([1, 21, 21, 4])
layer = layers.UpSampling2D(size=2)
out = layer(x)
out.shape
TensorShape([1, 14, 14, 4])

ReLu

36-池化与采样-relu.jpg

x = tf.random.normal([2,3])
x
<tf.Tensor: id=76, shape=(2, 3), dtype=float32, numpy=
array([[-0.30181265,  0.39785287, -0.78380096],
       [ 0.6593401 , -0.40962896, -0.3656048 ]], dtype=float32)>
tf.nn.relu(x)
x
<tf.Tensor: id=76, shape=(2, 3), dtype=float32, numpy=
array([[-0.30181265,  0.39785287, -0.78380096],
       [ 0.6593401 , -0.40962896, -0.3656048 ]], dtype=float32)>
layers.ReLU()(x)
<tf.Tensor: id=80, shape=(2, 3), dtype=float32, numpy=
array([[0.        , 0.39785287, 0.        ],
       [0.6593401 , 0.        , 0.        ]], dtype=float32)>

转载于:https://www.cnblogs.com/nickchen121/p/10930571.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值