尝试理解 TensorFlow 序列模型的摘要。

huangapple go评论42阅读模式
英文:

Trying understand tensorflow sequential summary

问题

以下是翻译好的部分:

层 (类型) 输出形状 参数数目
zero_padding2d (ZeroPadding2D) (None, 70, 70, 3) 0
conv2d (Conv2D) (None, 64, 64, 32) 4736

我不明白为什么有 4736 个参数?64 * 64 * 32 != 4736

我的模型:

tf.keras.Sequential([
        tf.keras.Input(shape=(64, 64, 3)),
        ## 零填充层,填充为3,输入形状为64 x 64 x 3
        tf.keras.layers.ZeroPadding2D(padding=3),
        ## Conv2D 层,有32个7x7的过滤器和步幅为1
        tf.keras.layers.Conv2D(
            filters=32,
            kernel_size=7,
            strides=(1, 1)
        ),
        ## 沿轴3的批量标准化
        tf.keras.layers.BatchNormalization(
            axis=3
        ),
        ## ReLU激活函数
        tf.keras.layers.ReLU(),
        ## 2D最大池化层,默认参数
        tf.keras.layers.MaxPooling2D(),
        ## 展平层
        tf.keras.layers.Flatten(),
        ## 具有1个单元的全连接层,使用'sigmoid'激活函数
        tf.keras.layers.Dense(1, activation='sigmoid')
    ])

希望这有助于理解模型的概要以及参数数量的来源。

英文:

I can't figure out a summary of my model. For example first 2 rows of the summary(tf.keras.Sequential.summary()):

Layer (type) Output Shape Param #
zero_padding2d (ZeroPadding2D) (None, 70, 70, 3) 0
conv2d (Conv2D) (None, 64, 64, 32) 4736

I don't understand why 4736 params? 64 * 64 * 32 != 4736

my model:

tf.keras.Sequential([
        tf.keras.Input(shape=(64 , 64 ,3)),
        ## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
        tf.keras.layers.ZeroPadding2D(padding=3),
        ## Conv2D with 32 7x7 filters and stride of 1
        tf.keras.layers.Conv2D(
            filters = 32,
            kernel_size = 7,
            strides = (1,1)
        ),
        ## BatchNormalization for axis 3
        tf.keras.layers.BatchNormalization(
            axis=3
        ),
        ## ReLU
        tf.keras.layers.ReLU(),
        ## Max Pooling 2D with default parameters
        tf.keras.layers.MaxPooling2D(),
        ## Flatten layer
        tf.keras.layers.Flatten(),
        ## Dense layer with 1 unit for output & 'sigmoid' activation
        tf.keras.layers.Dense(1, activation='sigmoid')
    ])

答案1

得分: 1

参数的数量等于Tensorflow在训练特定层时可以调整的变量数量。它与输入大小有关,但不直接等于输入的数量。

这也解释了零填充层的“param #”。零填充不可训练,因此参数数量为零。

英文:

The number of parameters equals the number of variables Tensorflow can tune when training that particular layer. It is related to the input size but does not equal the number of inputs directly.

That also explains the param # of the zero padding layer. Zero padding is not trainable, so the number of parameters is zero.

huangapple
  • 本文由 发表于 2023年2月27日 08:03:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75575777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定