0

我正在尝试确定我的 Keras 网络中的“神经元/节点”的数量,而不是参数。我正在使用一个已经实现的变体,所以我没有自己开发任何东西。

我知道,我可以通过摘要获得网络的概述和参数数量。这里的问题是,我不想知道我有多少参数,而是知道有多少“神经元”。背景是,对于 8 到 8 个全连接层,我得到 64 个参数。但我想达到 16。我也知道,使用 Conv2D 层的整个故事并不是那么容易制作的。

我的第一种方法是将 output_shape 变量的所有值相乘,然后将它们相加。我可以这样做还是错了?

这就是列表形式模型摘要:

Layer (type)                            Output Shape            
================================================================
input_image (InputLayer)                (None, None, None, 1)   
zero_padding2d_1 (ZeroPadding2D)        (None, None, None, 1)   
conv1 (Conv2D)                          (None, None, None, 64)  
bn_conv1 (BatchNorm)                    (None, None, None, 64)  
activation_1 (Activation)               (None, None, None, 64)  
max_pooling2d_1 (MaxPooling2D)          (None, None, None, 64)  
res2a_branch2a (Conv2D)                 (None, None, None, 64)  
bn2a_branch2a (BatchNorm)               (None, None, None, 64)  
activation_2 (Activation)               (None, None, None, 64)  
res2a_branch2b (Conv2D)                 (None, None, None, 64)  
bn2a_branch2b (BatchNorm)               (None, None, None, 64)  
activation_3 (Activation)               (None, None, None, 64)  
res2a_branch2c (Conv2D)                 (None, None, None, 256) 
res2a_branch1 (Conv2D)                  (None, None, None, 256) 
bn2a_branch2c (BatchNorm)               (None, None, None, 256) 
bn2a_branch1 (BatchNorm)                (None, None, None, 256) 
add_1 (Add)                             (None, None, None, 256) 
res2a_out (Activation)                  (None, None, None, 256) 
res2b_branch2a (Conv2D)                 (None, None, None, 64)  
bn2b_branch2a (BatchNorm)               (None, None, None, 64)  
activation_4 (Activation)               (None, None, None, 64)  
res2b_branch2b (Conv2D)                 (None, None, None, 64)  
bn2b_branch2b (BatchNorm)               (None, None, None, 64)  
activation_5 (Activation)               (None, None, None, 64)  
res2b_branch2c (Conv2D)                 (None, None, None, 256) 
bn2b_branch2c (BatchNorm)               (None, None, None, 256) 
add_2 (Add)                             (None, None, None, 256) 
res2b_out (Activation)                  (None, None, None, 256) 
res2c_branch2a (Conv2D)                 (None, None, None, 64)  
bn2c_branch2a (BatchNorm)               (None, None, None, 64)  
activation_6 (Activation)               (None, None, None, 64)  
res2c_branch2b (Conv2D)                 (None, None, None, 64)  
bn2c_branch2b (BatchNorm)               (None, None, None, 64)  
activation_7 (Activation)               (None, None, None, 64)  
res2c_branch2c (Conv2D)                 (None, None, None, 256) 
bn2c_branch2c (BatchNorm)               (None, None, None, 256) 
add_3 (Add)                             (None, None, None, 256) 
res2c_out (Activation)                  (None, None, None, 256) 
res3a_branch2a (Conv2D)                 (None, None, None, 128) 
bn3a_branch2a (BatchNorm)               (None, None, None, 128) 
activation_8 (Activation)               (None, None, None, 128) 
res3a_branch2b (Conv2D)                 (None, None, None, 128) 
bn3a_branch2b (BatchNorm)               (None, None, None, 128) 
activation_9 (Activation)               (None, None, None, 128) 
res3a_branch2c (Conv2D)                 (None, None, None, 512) 
res3a_branch1 (Conv2D)                  (None, None, None, 512) 
bn3a_branch2c (BatchNorm)               (None, None, None, 512) 
bn3a_branch1 (BatchNorm)                (None, None, None, 512) 
add_4 (Add)                             (None, None, None, 512) 
res3a_out (Activation)                  (None, None, None, 512) 
res3b_branch2a (Conv2D)                 (None, None, None, 128) 
bn3b_branch2a (BatchNorm)               (None, None, None, 128) 
activation_10 (Activation)              (None, None, None, 128) 
res3b_branch2b (Conv2D)                 (None, None, None, 128) 
bn3b_branch2b (BatchNorm)               (None, None, None, 128) 
activation_11 (Activation)              (None, None, None, 128) 
res3b_branch2c (Conv2D)                 (None, None, None, 512) 
bn3b_branch2c (BatchNorm)               (None, None, None, 512) 
add_5 (Add)                             (None, None, None, 512) 
res3b_out (Activation)                  (None, None, None, 512) 
res3c_branch2a (Conv2D)                 (None, None, None, 128) 
bn3c_branch2a (BatchNorm)               (None, None, None, 128) 
activation_12 (Activation)              (None, None, None, 128) 
res3c_branch2b (Conv2D)                 (None, None, None, 128) 
bn3c_branch2b (BatchNorm)               (None, None, None, 128) 
activation_13 (Activation)              (None, None, None, 128) 
res3c_branch2c (Conv2D)                 (None, None, None, 512) 
bn3c_branch2c (BatchNorm)               (None, None, None, 512) 
add_6 (Add)                             (None, None, None, 512) 
res3c_out (Activation)                  (None, None, None, 512) 
res3d_branch2a (Conv2D)                 (None, None, None, 128) 
bn3d_branch2a (BatchNorm)               (None, None, None, 128) 
activation_14 (Activation)              (None, None, None, 128) 
res3d_branch2b (Conv2D)                 (None, None, None, 128) 
bn3d_branch2b (BatchNorm)               (None, None, None, 128) 
activation_15 (Activation)              (None, None, None, 128) 
res3d_branch2c (Conv2D)                 (None, None, None, 512) 
bn3d_branch2c (BatchNorm)               (None, None, None, 512) 
add_7 (Add)                             (None, None, None, 512) 
res3d_out (Activation)                  (None, None, None, 512) 
res4a_branch2a (Conv2D)                 (None, None, None, 256) 
bn4a_branch2a (BatchNorm)               (None, None, None, 256) 
activation_16 (Activation)              (None, None, None, 256) 
res4a_branch2b (Conv2D)                 (None, None, None, 256) 
bn4a_branch2b (BatchNorm)               (None, None, None, 256) 
activation_17 (Activation)              (None, None, None, 256) 
res4a_branch2c (Conv2D)                 (None, None, None, 1024)
res4a_branch1 (Conv2D)                  (None, None, None, 1024)
bn4a_branch2c (BatchNorm)               (None, None, None, 1024)
bn4a_branch1 (BatchNorm)                (None, None, None, 1024)
add_8 (Add)                             (None, None, None, 1024)
res4a_out (Activation)                  (None, None, None, 1024)
res4b_branch2a (Conv2D)                 (None, None, None, 256) 
bn4b_branch2a (BatchNorm)               (None, None, None, 256) 
activation_18 (Activation)              (None, None, None, 256) 
res4b_branch2b (Conv2D)                 (None, None, None, 256) 
bn4b_branch2b (BatchNorm)               (None, None, None, 256) 
activation_19 (Activation)              (None, None, None, 256) 
res4b_branch2c (Conv2D)                 (None, None, None, 1024)
bn4b_branch2c (BatchNorm)               (None, None, None, 1024)
add_9 (Add)                             (None, None, None, 1024)
res4b_out (Activation)                  (None, None, None, 1024)
res4c_branch2a (Conv2D)                 (None, None, None, 256) 
bn4c_branch2a (BatchNorm)               (None, None, None, 256) 
activation_20 (Activation)              (None, None, None, 256) 
res4c_branch2b (Conv2D)                 (None, None, None, 256) 
bn4c_branch2b (BatchNorm)               (None, None, None, 256) 
activation_21 (Activation)              (None, None, None, 256) 
res4c_branch2c (Conv2D)                 (None, None, None, 1024)
bn4c_branch2c (BatchNorm)               (None, None, None, 1024)
add_10 (Add)                            (None, None, None, 1024)
res4c_out (Activation)                  (None, None, None, 1024)
res4d_branch2a (Conv2D)                 (None, None, None, 256) 
bn4d_branch2a (BatchNorm)               (None, None, None, 256) 
activation_22 (Activation)              (None, None, None, 256) 
res4d_branch2b (Conv2D)                 (None, None, None, 256) 
bn4d_branch2b (BatchNorm)               (None, None, None, 256) 
activation_23 (Activation)              (None, None, None, 256) 
res4d_branch2c (Conv2D)                 (None, None, None, 1024)
bn4d_branch2c (BatchNorm)               (None, None, None, 1024)
add_11 (Add)                            (None, None, None, 1024)
res4d_out (Activation)                  (None, None, None, 1024)
res4e_branch2a (Conv2D)                 (None, None, None, 256) 
bn4e_branch2a (BatchNorm)               (None, None, None, 256) 
activation_24 (Activation)              (None, None, None, 256) 
res4e_branch2b (Conv2D)                 (None, None, None, 256) 
bn4e_branch2b (BatchNorm)               (None, None, None, 256) 
activation_25 (Activation)              (None, None, None, 256) 
res4e_branch2c (Conv2D)                 (None, None, None, 1024)
bn4e_branch2c (BatchNorm)               (None, None, None, 1024)
add_12 (Add)                            (None, None, None, 1024)
res4e_out (Activation)                  (None, None, None, 1024)
res4f_branch2a (Conv2D)                 (None, None, None, 256) 
bn4f_branch2a (BatchNorm)               (None, None, None, 256) 
activation_26 (Activation)              (None, None, None, 256) 
res4f_branch2b (Conv2D)                 (None, None, None, 256) 
bn4f_branch2b (BatchNorm)               (None, None, None, 256) 
activation_27 (Activation)              (None, None, None, 256) 
res4f_branch2c (Conv2D)                 (None, None, None, 1024)
bn4f_branch2c (BatchNorm)               (None, None, None, 1024)
add_13 (Add)                            (None, None, None, 1024)
res4f_out (Activation)                  (None, None, None, 1024)
res5a_branch2a (Conv2D)                 (None, None, None, 512) 
bn5a_branch2a (BatchNorm)               (None, None, None, 512) 
activation_28 (Activation)              (None, None, None, 512) 
res5a_branch2b (Conv2D)                 (None, None, None, 512) 
bn5a_branch2b (BatchNorm)               (None, None, None, 512) 
activation_29 (Activation)              (None, None, None, 512) 
res5a_branch2c (Conv2D)                 (None, None, None, 2048)
res5a_branch1 (Conv2D)                  (None, None, None, 2048)
bn5a_branch2c (BatchNorm)               (None, None, None, 2048)
bn5a_branch1 (BatchNorm)                (None, None, None, 2048)
add_14 (Add)                            (None, None, None, 2048)
res5a_out (Activation)                  (None, None, None, 2048)
res5b_branch2a (Conv2D)                 (None, None, None, 512) 
bn5b_branch2a (BatchNorm)               (None, None, None, 512) 
activation_30 (Activation)              (None, None, None, 512) 
res5b_branch2b (Conv2D)                 (None, None, None, 512) 
bn5b_branch2b (BatchNorm)               (None, None, None, 512) 
activation_31 (Activation)              (None, None, None, 512) 
res5b_branch2c (Conv2D)                 (None, None, None, 2048)
bn5b_branch2c (BatchNorm)               (None, None, None, 2048)
add_15 (Add)                            (None, None, None, 2048)
res5b_out (Activation)                  (None, None, None, 2048)
res5c_branch2a (Conv2D)                 (None, None, None, 512) 
bn5c_branch2a (BatchNorm)               (None, None, None, 512) 
activation_32 (Activation)              (None, None, None, 512) 
res5c_branch2b (Conv2D)                 (None, None, None, 512) 
bn5c_branch2b (BatchNorm)               (None, None, None, 512) 
activation_33 (Activation)              (None, None, None, 512) 
res5c_branch2c (Conv2D)                 (None, None, None, 2048)
bn5c_branch2c (BatchNorm)               (None, None, None, 2048)
add_16 (Add)                            (None, None, None, 2048)
res5c_out (Activation)                  (None, None, None, 2048)
fpn_c5p5 (Conv2D)                       (None, None, None, 256) 
fpn_p5upsampled (UpSampling2D)          (None, None, None, 256) 
fpn_c4p4 (Conv2D)                       (None, None, None, 256) 
fpn_p4add (Add)                         (None, None, None, 256) 
fpn_p4upsampled (UpSampling2D)          (None, None, None, 256) 
fpn_c3p3 (Conv2D)                       (None, None, None, 256) 
fpn_p3add (Add)                         (None, None, None, 256) 
fpn_p3upsampled (UpSampling2D)          (None, None, None, 256) 
fpn_c2p2 (Conv2D)                       (None, None, None, 256) 
fpn_p2add (Add)                         (None, None, None, 256) 
fpn_p5 (Conv2D)                         (None, None, None, 256) 
fpn_p2 (Conv2D)                         (None, None, None, 256) 
fpn_p3 (Conv2D)                         (None, None, None, 256) 
fpn_p4 (Conv2D)                         (None, None, None, 256) 
fpn_p6 (MaxPooling2D)                   (None, None, None, 256) 
rpn_model (Model)                       [(None, None, 2), 
                                             (None, None, 2), 
                                             (None, None, 4)]       
rpn_class (Concatenate)                 (None, None, 2)         
rpn_bbox (Concatenate)                  (None, None, 4)         
input_anchors (InputLayer)              (None, None, 4)         
ROI (ProposalLayer)                     (None, 1000, 4)         
input_image_meta (InputLayer)           (None, 18)              
roi_align_classifier (PyramidROIAlign)  (None, 1000, 7, 7, 256) 
mrcnn_class_conv1 (TimeDistributed)     (None, 1000, 1, 1, 1024)
mrcnn_class_bn1 (TimeDistributed)       (None, 1000, 1, 1, 1024)
activation_34 (Activation)              (None, 1000, 1, 1, 1024)
mrcnn_class_conv2 (TimeDistributed)     (None, 1000, 1, 1, 1024)
mrcnn_class_bn2 (TimeDistributed)       (None, 1000, 1, 1, 1024)
activation_35 (Activation)              (None, 1000, 1, 1, 1024)
pool_squeeze (Lambda)                   (None, 1000, 1024)      
mrcnn_class_logits (TimeDistributed)    (None, 1000, 6)         
mrcnn_bbox_fc (TimeDistributed)         (None, 1000, 24)        
mrcnn_class (TimeDistributed)           (None, 1000, 6)         
mrcnn_bbox (Reshape)                    (None, 1000, 6, 4)      
mrcnn_detection (DetectionLayer)        (None, 100, 6)          
lambda_3 (Lambda)                       (None, 100, 4)          
roi_align_mask (PyramidROIAlign)        (None, 100, 14, 14, 256)
mrcnn_mask_conv1 (TimeDistributed)      (None, 100, 14, 14, 256)
mrcnn_mask_bn1 (TimeDistributed)        (None, 100, 14, 14, 256)
activation_37 (Activation)              (None, 100, 14, 14, 256)
mrcnn_mask_conv2 (TimeDistributed)      (None, 100, 14, 14, 256)
mrcnn_mask_bn2 (TimeDistributed)        (None, 100, 14, 14, 256)
activation_38 (Activation)              (None, 100, 14, 14, 256)
mrcnn_mask_conv3 (TimeDistributed)      (None, 100, 14, 14, 256)
mrcnn_mask_bn3 (TimeDistributed)        (None, 100, 14, 14, 256)
activation_39 (Activation)              (None, 100, 14, 14, 256)
mrcnn_mask_conv4 (TimeDistributed)      (None, 100, 14, 14, 256)
mrcnn_mask_bn4 (TimeDistributed)        (None, 100, 14, 14, 256)
activation_40 (Activation)              (None, 100, 14, 14, 256)
mrcnn_mask_deconv (TimeDistributed)     (None, 100, 28, 28, 256)
mrcnn_mask (TimeDistributed)            (None, 100, 28, 28, 6)  
================================================================
Total params: 44,678,198
Trainable params: 44,618,934
Non-trainable params: 59,264

我数了一下神经元 105,641,486。这看起来是错误的,因为除了权重(参数)之外还有很多。我不确定我是否真的可以添加所有图层?

如果有人想知道我为什么要这样做。我想将它与生物神经网络进行比较,我只有大脑的神经元数量,而不是那里的所有连接。我知道它们没有可比性,但对于我想做的事情来说已经足够了。

感谢您的提示和帮助

4

1 回答 1

1

一些东西:

  • 在卷积层中,neurons == filters
  • 如果您计算其他层,例如激活、填充和池化/采样,您将计算其他不存在的神经元(这些层没有神经元)
  • BatchNormalization图层确实有参数,但我不确定您是否要将它们视为具有神经元。然而,除了不可训练的均值和方差参数外,它们还具有可学习的缩放和偏差参数。use_bias=False(总是在批规范之前的任何层中 使用的一个很好的理由)

因此,只需计算每个 Conv 层中的过滤器数量。如果需要,请添加 BatchNorm 通道。

于 2019-01-30T16:38:59.240 回答