Подсчитать нейроны в керасе (с разными слоями), мой подход правильный?
Я пытаюсь определить количество "нейронов / узлов" в моей сети 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. Это выглядит неправильно, потому что их гораздо больше, чем весов (параметров). Я не уверен, могу ли я действительно добавить все слои?
И если кому-то интересно, почему я хочу это сделать. Я хочу сравнить его с биологической нейронной сетью, и у меня есть только количество нейронов мозга, а не все связи между ними. Я знаю, что они несопоставимы, но достаточно хороши для того, что я хочу сделать.
спасибо за подсказки и помощь
1 ответ
Несколько вещей:
- В сверточных слоях
neurons == filters
- Если вы посчитаете другие слои, такие как активация, заполнение и объединение / выборка, вы будете считать дополнительные нейроны, которые не существуют (эти слои не имеют нейронов)
BatchNormalization
слои имеют параметры, но я не уверен, что вы хотите считать их имеющими нейроны. Тем не менее, они имеют обучаемые параметры для масштабирования и смещения, помимо необучаемых параметров для среднего и дисперсии. (Хорошая причина всегда использоватьuse_bias=False
в любом слое непосредственно до нормы партии)
Итак, просто посчитайте количество фильтров в каждом слое Conv. Добавьте каналы BatchNorm, если хотите.