【问题标题】:Dense layer does not give expected Output shape密集层没有给出预期的输出形状
【发布时间】:2022-01-12 20:35:33
【问题描述】:

我正在尝试复制模型架构。在原始模型架构中,应用最后一个 Dense 层后,输出形状为 (None, 3),参数为 300。如图

 _________________________________________________________________
 Layer (type)                Output Shape              Param #   
 =================================================================

 dense_Dense1 (Dense)        (None, 100)               128100    
                                                             
 dense_Dense2 (Dense)        (None, 3)                 300       

但是当我应用密集输出形状时,我得到的是 (None, 3) 和 303 个参数。如下图

 _________________________________________________________________
 Layer (type)                Output Shape              Param #   
 =================================================================

 dense_35 (Dense)                (None, 100)          128100  

 dense_36 (Dense)                (None, 3)            303  

这是我为此部分编写的代码:

x = GlobalAveragePooling2D()(x)
x = Dense(100, activation="relu")(x)
prediction = Dense(3, activation='softmax')(x)

【问题讨论】:

    标签: machine-learning keras deep-learning computer-vision conv-neural-network


    【解决方案1】:

    您尝试复制的架构是否可能不使用偏见?试试not using bias

    Dense(3, activation='softmax', use_bias=False)
    
    Model: "sequential_5"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    global_average_pooling2d_3 ( (None, 8)                 0         
    _________________________________________________________________
    dense_9 (Dense)              (None, 100)               900       
    _________________________________________________________________
    dense_10 (Dense)             (None, 3)                 300       
    =================================================================
    Total params: 1,200
    Trainable params: 1,200
    Non-trainable params: 0
    _________________________________________________________________
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 2018-09-18
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多