我有一个在 Keras 和 PyTorch 中实现的示例微型 CNN。当我打印两个网络的摘要时,可训练参数的总数相同,但参数总数和批量标准化的参数数不匹配。
这是 Keras 中的 CNN 实现:
inputs = Input(shape = (64, 64, 1)). # Channel Last: (NHWC)
model = Conv2D(filters=32, kernel_size=(3, 3), padding='SAME', activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1))(inputs)
model = BatchNormalization(momentum=0.15, axis=-1)(model)
model = Flatten()(model)
dense = Dense(100, activation = "relu")(model)
head_root = Dense(10, activation = 'softmax')(dense)
以上模型打印的摘要是:
Model: "model_8"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_9 (InputLayer) (None, 64, 64, 1) 0
_________________________________________________________________
conv2d_10 (Conv2D) (None, 64, 64, 32) 320
_________________________________________________________________
batch_normalization_2 (Batch (None, 64, 64, 32) 128
_________________________________________________________________
flatten_3 (Flatten) (None, 131072) 0
_________________________________________________________________
dense_11 (Dense) (None, 100) 13107300
_________________________________________________________________
dense_12 (Dense) (None, 10) 1010
=================================================================
Total params: 13,108,758
Trainable params: 13,108,694
Non-trainable params: 64
_________________________________________________________________
正如您在上面的结果中看到的,Keras 中的批量标准化比 PyTorch 具有更多的参数(准确地说是 2 倍)。那么上述 CNN 架构有什么区别呢?如果它们是等效的,那么我在这里缺少什么?
心有法竹
慕斯王
随时随地看视频慕课网APP
相关分类