池化与采样

目录

  • Outline
  • Reduce Dim
  • subsample
    • Max/Avg pooling
    • Strides
    • For instance
  • upsample
    • UpSampling2D
  • ReLu

Outline

  • Pooling

  • upsample

  • ReLU

Reduce Dim

subsample

Max/Avg pooling

  • stride = 2

Strides

  • stride = 1

For instance

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

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

x = tf.random.normal([2,3])
x
tf.nn.relu(x)
x
layers.ReLU()(x)

你可能感兴趣的:(池化与采样)