論文のモデルを自分で実装する ResNet編

## はじめに
機械学習のために理論を理解しておくのは十分必要なわけですが、やはり手を動かさないと何も進まなそう、ということで、自分でいろんなネットワークを実装してみる修行を始めようと思います。
そこで、まず初めにResNetから行こう、ということで、書かせていただきます。

前まで書いてた記事とはえらく楽した記事になっていて、読みにくいかもしれません。そこはごめんなさい。

## 論文
[Deep Residual Learning for Image Recognition](https://arxiv.org/abs/1512.03385)

## 1回目
とりあえず、ざっと書いてみます
<details><summary>初めに書いたコード</summary><div>

```python
from typing import Union

import tensorflow as tf
from tensorflow.keras.applications import ResNet50 as _ResNet50
from tensorflow.keras.layers import (Activation, Add, BatchNormalization,
                                     Conv2D, Input, MaxPooling2D, GlobalAveragePooling2D, Dense)
from tensorflow.keras.models import Model


class ResNet():
    """ResNet Architecture"""
    __LAYER_LOOPS = {
        '18' : [2,2,2,2],
        '34' : [3,4,6,3],
        '50' : [3,4,6,3],
        '101' : [3,4,23,3],
        '152' : [3,8,36,3]
    }

    def __init__(self, input_ch:tuple, output_ch:int, layers:str):
        try:
            self._range = self.__LAYER_LOOPS[layers]
        except KeyError:
            raise ValueError('ResNet layers must be [18, 34, 50, 101, 152].')

        self.input_ch = input_ch
        self.output_ch = output_ch
        self.layers = layers
        self.index = 0

    def conv_bn_act(self,
        x,
        filters:Union[int, tuple, list],
        kernel_size:Union[int, tuple, list],
        strides=(1,1)):
        """
        Conv2D + BatchNormalization + Relu
        """

        x = Conv2D(filters=filters, kernel_size=kernel_size, strides=strides)(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        return x

    def conv_x(self, x, times):
        """conv2_x"""
        y = x
        for _ in range(self._range[self.index]):
            if self.layers == 18:
                x = self.conv_bn_act(x, 3, 64*(2**times))
                x = self.conv_bn_act(x, 3, 64*(2**times))
            elif self.layers == 34:
                x = self.conv_bn_act(x, 3, 64*(2**times))
                x = self.conv_bn_act(x, 3, 64*(2**times))
            else:
                x = self.conv_bn_act(x, 1, 64*(2**times))
                x = self.conv_bn_act(x, 3, 64*(2**times))
                x = self.conv_bn_act(x, 1, 256*(2**times))
        x = Add()[y, x]
        x = Activation('relu')(x)

        self.index += 1
        return x

    def build_resnet(self):
        input = Input(shape=self.input_ch)

        # 7x7 conv, 64, /2
        x = self.conv_bn_act(input, filters=64, kernel_size=7, strides=(2,2))

        # pool, /2
        x = MaxPooling2D(pool_size=(3,3), strides=2)(x)

        # conv2_x
        x = self.conv_x(x, 0)

        # conv3_x
        x = self.conv_x(x, 1)

        # conv4_x
        x = self.conv_x(x, 2)

        # conv5_x
        x = self.conv_x(x, 3)

        # average pool, softmax
        x = GlobalAveragePooling2D()(x)
        x = Dense(units = self.output_ch, activation='softmax')(x)

        model = Model(inputs = input, outputs = x)
        return model

        

resnet_50  = ResNet(input_ch = (512, 512, 3), output_ch=100, layers='50')
model = resnet_50.build_resnet()

model.summary()
```

</div></details>

### 結果

```bash
ValueError: Negative dimension size caused by subtracting 64 from 63 for '{{node conv2d_2/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](Placeholder, conv2d_2/Conv2D/ReadVariableOp)' with input shapes: [?,63,63,1], [64,64,1,3].
```

oof

## 2回目
50行目辺りが原因でした。ふつうに引数間違いです。
あと、layers.Addで重大ミス犯してました。リストは指定できないわな…

### 結果

```bash
ValueError: Operands could not be broadcast together with shapes (126, 126, 64) (120, 120, 256)
```

oof…

## 3回目
解決ができたのでざっと書きます。

- Addの場所が違ってたり、結合前の畳み込みのActivationはしないという所が辺でした。
- shapeが違うということは、3x3の畳み込みでpadding='same'してない所が原因そうです(理由は「[CNNと画像認識による構造の違いについて](https://qiita.com/ppza53893/items/fa662a799b76be07baaf)」の記事で説明しています)。また50層以上の場合、結合前の畳み込みでフィルターが4倍になっているので、畳んでない方(論文中の、いわゆる$\bf x$)についても同じフィルタサイズで畳み込みしておく必要がありそうです。
- 関数conv_xの初めのstrideを2にするのを忘れてました。stride=1だとずっとhとwのサイズが減りません…

### 結果

<details><summary>出力</summary><div>

```bash
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            [(None, 512, 512, 3) 0
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 253, 253, 64) 9472        input_1[0][0]
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, 253, 253, 64) 256         conv2d[0][0]
__________________________________________________________________________________________________
activation (Activation)         (None, 253, 253, 64) 0           batch_normalization[0][0]
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 126, 126, 64) 0           activation[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 63, 63, 64)   4160        max_pooling2d[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 63, 63, 64)   256         conv2d_2[0][0]
__________________________________________________________________________________________________
activation_1 (Activation)       (None, 63, 63, 64)   0           batch_normalization_2[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 63, 63, 64)   36928       activation_1[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 63, 63, 64)   256         conv2d_3[0][0]
__________________________________________________________________________________________________
activation_2 (Activation)       (None, 63, 63, 64)   0           batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 63, 63, 256)  16640       max_pooling2d[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 63, 63, 256)  16640       activation_2[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 63, 63, 256)  1024        conv2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 63, 63, 256)  1024        conv2d_4[0][0]
__________________________________________________________________________________________________
add (Add)                       (None, 63, 63, 256)  0           batch_normalization_1[0][0]
                                                                 batch_normalization_4[0][0]
__________________________________________________________________________________________________
activation_3 (Activation)       (None, 63, 63, 256)  0           add[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D)               (None, 63, 63, 64)   16448       activation_3[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 63, 63, 64)   256         conv2d_6[0][0]
__________________________________________________________________________________________________
activation_4 (Activation)       (None, 63, 63, 64)   0           batch_normalization_6[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D)               (None, 63, 63, 64)   36928       activation_4[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 63, 63, 64)   256         conv2d_7[0][0]
__________________________________________________________________________________________________
activation_5 (Activation)       (None, 63, 63, 64)   0           batch_normalization_7[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 63, 63, 256)  65792       activation_3[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D)               (None, 63, 63, 256)  16640       activation_5[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 63, 63, 256)  1024        conv2d_5[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 63, 63, 256)  1024        conv2d_8[0][0]
__________________________________________________________________________________________________
add_1 (Add)                     (None, 63, 63, 256)  0           batch_normalization_5[0][0]
                                                                 batch_normalization_8[0][0]
__________________________________________________________________________________________________
activation_6 (Activation)       (None, 63, 63, 256)  0           add_1[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D)              (None, 63, 63, 64)   16448       activation_6[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 63, 63, 64)   256         conv2d_10[0][0]
__________________________________________________________________________________________________
activation_7 (Activation)       (None, 63, 63, 64)   0           batch_normalization_10[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D)              (None, 63, 63, 64)   36928       activation_7[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 63, 63, 64)   256         conv2d_11[0][0]
__________________________________________________________________________________________________
activation_8 (Activation)       (None, 63, 63, 64)   0           batch_normalization_11[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D)               (None, 63, 63, 256)  65792       activation_6[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D)              (None, 63, 63, 256)  16640       activation_8[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 63, 63, 256)  1024        conv2d_9[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 63, 63, 256)  1024        conv2d_12[0][0]
__________________________________________________________________________________________________
add_2 (Add)                     (None, 63, 63, 256)  0           batch_normalization_9[0][0]
                                                                 batch_normalization_12[0][0]
__________________________________________________________________________________________________
activation_9 (Activation)       (None, 63, 63, 256)  0           add_2[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D)              (None, 32, 32, 128)  32896       activation_9[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 32, 32, 128)  512         conv2d_14[0][0]
__________________________________________________________________________________________________
activation_10 (Activation)      (None, 32, 32, 128)  0           batch_normalization_14[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D)              (None, 32, 32, 128)  147584      activation_10[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 32, 32, 128)  512         conv2d_15[0][0]
__________________________________________________________________________________________________
activation_11 (Activation)      (None, 32, 32, 128)  0           batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D)              (None, 32, 32, 512)  131584      activation_9[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D)              (None, 32, 32, 512)  66048       activation_11[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 32, 32, 512)  2048        conv2d_13[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 32, 32, 512)  2048        conv2d_16[0][0]
__________________________________________________________________________________________________
add_3 (Add)                     (None, 32, 32, 512)  0           batch_normalization_13[0][0]
                                                                 batch_normalization_16[0][0]
__________________________________________________________________________________________________
activation_12 (Activation)      (None, 32, 32, 512)  0           add_3[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D)              (None, 32, 32, 128)  65664       activation_12[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 32, 32, 128)  512         conv2d_18[0][0]
__________________________________________________________________________________________________
activation_13 (Activation)      (None, 32, 32, 128)  0           batch_normalization_18[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 32, 32, 128)  147584      activation_13[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 32, 32, 128)  512         conv2d_19[0][0]
__________________________________________________________________________________________________
activation_14 (Activation)      (None, 32, 32, 128)  0           batch_normalization_19[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D)              (None, 32, 32, 512)  262656      activation_12[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D)              (None, 32, 32, 512)  66048       activation_14[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 32, 32, 512)  2048        conv2d_17[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 32, 32, 512)  2048        conv2d_20[0][0]
__________________________________________________________________________________________________
add_4 (Add)                     (None, 32, 32, 512)  0           batch_normalization_17[0][0]
                                                                 batch_normalization_20[0][0]
__________________________________________________________________________________________________
activation_15 (Activation)      (None, 32, 32, 512)  0           add_4[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D)              (None, 32, 32, 128)  65664       activation_15[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 32, 32, 128)  512         conv2d_22[0][0]
__________________________________________________________________________________________________
activation_16 (Activation)      (None, 32, 32, 128)  0           batch_normalization_22[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D)              (None, 32, 32, 128)  147584      activation_16[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 32, 32, 128)  512         conv2d_23[0][0]
__________________________________________________________________________________________________
activation_17 (Activation)      (None, 32, 32, 128)  0           batch_normalization_23[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D)              (None, 32, 32, 512)  262656      activation_15[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D)              (None, 32, 32, 512)  66048       activation_17[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 32, 32, 512)  2048        conv2d_21[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 32, 32, 512)  2048        conv2d_24[0][0]
__________________________________________________________________________________________________
add_5 (Add)                     (None, 32, 32, 512)  0           batch_normalization_21[0][0]
                                                                 batch_normalization_24[0][0]
__________________________________________________________________________________________________
activation_18 (Activation)      (None, 32, 32, 512)  0           add_5[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D)              (None, 32, 32, 128)  65664       activation_18[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 32, 32, 128)  512         conv2d_26[0][0]
__________________________________________________________________________________________________
activation_19 (Activation)      (None, 32, 32, 128)  0           batch_normalization_26[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D)              (None, 32, 32, 128)  147584      activation_19[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 32, 32, 128)  512         conv2d_27[0][0]
__________________________________________________________________________________________________
activation_20 (Activation)      (None, 32, 32, 128)  0           batch_normalization_27[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D)              (None, 32, 32, 512)  262656      activation_18[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D)              (None, 32, 32, 512)  66048       activation_20[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 32, 32, 512)  2048        conv2d_25[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 32, 32, 512)  2048        conv2d_28[0][0]
__________________________________________________________________________________________________
add_6 (Add)                     (None, 32, 32, 512)  0           batch_normalization_25[0][0]
                                                                 batch_normalization_28[0][0]
__________________________________________________________________________________________________
activation_21 (Activation)      (None, 32, 32, 512)  0           add_6[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D)              (None, 16, 16, 256)  131328      activation_21[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 16, 16, 256)  1024        conv2d_30[0][0]
__________________________________________________________________________________________________
activation_22 (Activation)      (None, 16, 16, 256)  0           batch_normalization_30[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D)              (None, 16, 16, 256)  590080      activation_22[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 16, 16, 256)  1024        conv2d_31[0][0]
__________________________________________________________________________________________________
activation_23 (Activation)      (None, 16, 16, 256)  0           batch_normalization_31[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D)              (None, 16, 16, 1024) 525312      activation_21[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D)              (None, 16, 16, 1024) 263168      activation_23[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 16, 16, 1024) 4096        conv2d_29[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 16, 16, 1024) 4096        conv2d_32[0][0]
__________________________________________________________________________________________________
add_7 (Add)                     (None, 16, 16, 1024) 0           batch_normalization_29[0][0]
                                                                 batch_normalization_32[0][0]
__________________________________________________________________________________________________
activation_24 (Activation)      (None, 16, 16, 1024) 0           add_7[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D)              (None, 16, 16, 256)  262400      activation_24[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 16, 16, 256)  1024        conv2d_34[0][0]
__________________________________________________________________________________________________
activation_25 (Activation)      (None, 16, 16, 256)  0           batch_normalization_34[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D)              (None, 16, 16, 256)  590080      activation_25[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 16, 16, 256)  1024        conv2d_35[0][0]
__________________________________________________________________________________________________
activation_26 (Activation)      (None, 16, 16, 256)  0           batch_normalization_35[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D)              (None, 16, 16, 1024) 1049600     activation_24[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D)              (None, 16, 16, 1024) 263168      activation_26[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 16, 16, 1024) 4096        conv2d_33[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 16, 16, 1024) 4096        conv2d_36[0][0]
__________________________________________________________________________________________________
add_8 (Add)                     (None, 16, 16, 1024) 0           batch_normalization_33[0][0]
                                                                 batch_normalization_36[0][0]
__________________________________________________________________________________________________
activation_27 (Activation)      (None, 16, 16, 1024) 0           add_8[0][0]
__________________________________________________________________________________________________
conv2d_38 (Conv2D)              (None, 16, 16, 256)  262400      activation_27[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 16, 16, 256)  1024        conv2d_38[0][0]
__________________________________________________________________________________________________
activation_28 (Activation)      (None, 16, 16, 256)  0           batch_normalization_38[0][0]
__________________________________________________________________________________________________
conv2d_39 (Conv2D)              (None, 16, 16, 256)  590080      activation_28[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 16, 16, 256)  1024        conv2d_39[0][0]
__________________________________________________________________________________________________
activation_29 (Activation)      (None, 16, 16, 256)  0           batch_normalization_39[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D)              (None, 16, 16, 1024) 1049600     activation_27[0][0]
__________________________________________________________________________________________________
conv2d_40 (Conv2D)              (None, 16, 16, 1024) 263168      activation_29[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 16, 16, 1024) 4096        conv2d_37[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 16, 16, 1024) 4096        conv2d_40[0][0]
__________________________________________________________________________________________________
add_9 (Add)                     (None, 16, 16, 1024) 0           batch_normalization_37[0][0]
                                                                 batch_normalization_40[0][0]
__________________________________________________________________________________________________
activation_30 (Activation)      (None, 16, 16, 1024) 0           add_9[0][0]
__________________________________________________________________________________________________
conv2d_42 (Conv2D)              (None, 16, 16, 256)  262400      activation_30[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 16, 16, 256)  1024        conv2d_42[0][0]
__________________________________________________________________________________________________
activation_31 (Activation)      (None, 16, 16, 256)  0           batch_normalization_42[0][0]
__________________________________________________________________________________________________
conv2d_43 (Conv2D)              (None, 16, 16, 256)  590080      activation_31[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 16, 16, 256)  1024        conv2d_43[0][0]
__________________________________________________________________________________________________
activation_32 (Activation)      (None, 16, 16, 256)  0           batch_normalization_43[0][0]
__________________________________________________________________________________________________
conv2d_41 (Conv2D)              (None, 16, 16, 1024) 1049600     activation_30[0][0]
__________________________________________________________________________________________________
conv2d_44 (Conv2D)              (None, 16, 16, 1024) 263168      activation_32[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 16, 16, 1024) 4096        conv2d_41[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 16, 16, 1024) 4096        conv2d_44[0][0]
__________________________________________________________________________________________________
add_10 (Add)                    (None, 16, 16, 1024) 0           batch_normalization_41[0][0]
                                                                 batch_normalization_44[0][0]
__________________________________________________________________________________________________
activation_33 (Activation)      (None, 16, 16, 1024) 0           add_10[0][0]
__________________________________________________________________________________________________
conv2d_46 (Conv2D)              (None, 16, 16, 256)  262400      activation_33[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 16, 16, 256)  1024        conv2d_46[0][0]
__________________________________________________________________________________________________
activation_34 (Activation)      (None, 16, 16, 256)  0           batch_normalization_46[0][0]
__________________________________________________________________________________________________
conv2d_47 (Conv2D)              (None, 16, 16, 256)  590080      activation_34[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 16, 16, 256)  1024        conv2d_47[0][0]
__________________________________________________________________________________________________
activation_35 (Activation)      (None, 16, 16, 256)  0           batch_normalization_47[0][0]
__________________________________________________________________________________________________
conv2d_45 (Conv2D)              (None, 16, 16, 1024) 1049600     activation_33[0][0]
__________________________________________________________________________________________________
conv2d_48 (Conv2D)              (None, 16, 16, 1024) 263168      activation_35[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 16, 16, 1024) 4096        conv2d_45[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 16, 16, 1024) 4096        conv2d_48[0][0]
__________________________________________________________________________________________________
add_11 (Add)                    (None, 16, 16, 1024) 0           batch_normalization_45[0][0]
                                                                 batch_normalization_48[0][0]
__________________________________________________________________________________________________
activation_36 (Activation)      (None, 16, 16, 1024) 0           add_11[0][0]
__________________________________________________________________________________________________
conv2d_50 (Conv2D)              (None, 16, 16, 256)  262400      activation_36[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 16, 16, 256)  1024        conv2d_50[0][0]
__________________________________________________________________________________________________
activation_37 (Activation)      (None, 16, 16, 256)  0           batch_normalization_50[0][0]
__________________________________________________________________________________________________
conv2d_51 (Conv2D)              (None, 16, 16, 256)  590080      activation_37[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 16, 16, 256)  1024        conv2d_51[0][0]
__________________________________________________________________________________________________
activation_38 (Activation)      (None, 16, 16, 256)  0           batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_49 (Conv2D)              (None, 16, 16, 1024) 1049600     activation_36[0][0]
__________________________________________________________________________________________________
conv2d_52 (Conv2D)              (None, 16, 16, 1024) 263168      activation_38[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 16, 16, 1024) 4096        conv2d_49[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 16, 16, 1024) 4096        conv2d_52[0][0]
__________________________________________________________________________________________________
add_12 (Add)                    (None, 16, 16, 1024) 0           batch_normalization_49[0][0]
                                                                 batch_normalization_52[0][0]
__________________________________________________________________________________________________
activation_39 (Activation)      (None, 16, 16, 1024) 0           add_12[0][0]
__________________________________________________________________________________________________
conv2d_54 (Conv2D)              (None, 8, 8, 512)    524800      activation_39[0][0]
__________________________________________________________________________________________________
batch_normalization_54 (BatchNo (None, 8, 8, 512)    2048        conv2d_54[0][0]
__________________________________________________________________________________________________
activation_40 (Activation)      (None, 8, 8, 512)    0           batch_normalization_54[0][0]
__________________________________________________________________________________________________
conv2d_55 (Conv2D)              (None, 8, 8, 512)    2359808     activation_40[0][0]
__________________________________________________________________________________________________
batch_normalization_55 (BatchNo (None, 8, 8, 512)    2048        conv2d_55[0][0]
__________________________________________________________________________________________________
activation_41 (Activation)      (None, 8, 8, 512)    0           batch_normalization_55[0][0]
__________________________________________________________________________________________________
conv2d_53 (Conv2D)              (None, 8, 8, 2048)   2099200     activation_39[0][0]
__________________________________________________________________________________________________
conv2d_56 (Conv2D)              (None, 8, 8, 2048)   1050624     activation_41[0][0]
__________________________________________________________________________________________________
batch_normalization_53 (BatchNo (None, 8, 8, 2048)   8192        conv2d_53[0][0]
__________________________________________________________________________________________________
batch_normalization_56 (BatchNo (None, 8, 8, 2048)   8192        conv2d_56[0][0]
__________________________________________________________________________________________________
add_13 (Add)                    (None, 8, 8, 2048)   0           batch_normalization_53[0][0]
                                                                 batch_normalization_56[0][0]
__________________________________________________________________________________________________
activation_42 (Activation)      (None, 8, 8, 2048)   0           add_13[0][0]
__________________________________________________________________________________________________
conv2d_58 (Conv2D)              (None, 8, 8, 512)    1049088     activation_42[0][0]
__________________________________________________________________________________________________
batch_normalization_58 (BatchNo (None, 8, 8, 512)    2048        conv2d_58[0][0]
__________________________________________________________________________________________________
activation_43 (Activation)      (None, 8, 8, 512)    0           batch_normalization_58[0][0]
__________________________________________________________________________________________________
conv2d_59 (Conv2D)              (None, 8, 8, 512)    2359808     activation_43[0][0]
__________________________________________________________________________________________________
batch_normalization_59 (BatchNo (None, 8, 8, 512)    2048        conv2d_59[0][0]
__________________________________________________________________________________________________
activation_44 (Activation)      (None, 8, 8, 512)    0           batch_normalization_59[0][0]
__________________________________________________________________________________________________
conv2d_57 (Conv2D)              (None, 8, 8, 2048)   4196352     activation_42[0][0]
__________________________________________________________________________________________________
conv2d_60 (Conv2D)              (None, 8, 8, 2048)   1050624     activation_44[0][0]
__________________________________________________________________________________________________
batch_normalization_57 (BatchNo (None, 8, 8, 2048)   8192        conv2d_57[0][0]
__________________________________________________________________________________________________
batch_normalization_60 (BatchNo (None, 8, 8, 2048)   8192        conv2d_60[0][0]
__________________________________________________________________________________________________
add_14 (Add)                    (None, 8, 8, 2048)   0           batch_normalization_57[0][0]
                                                                 batch_normalization_60[0][0]
__________________________________________________________________________________________________
activation_45 (Activation)      (None, 8, 8, 2048)   0           add_14[0][0]
__________________________________________________________________________________________________
conv2d_62 (Conv2D)              (None, 8, 8, 512)    1049088     activation_45[0][0]
__________________________________________________________________________________________________
batch_normalization_62 (BatchNo (None, 8, 8, 512)    2048        conv2d_62[0][0]
__________________________________________________________________________________________________
activation_46 (Activation)      (None, 8, 8, 512)    0           batch_normalization_62[0][0]
__________________________________________________________________________________________________
conv2d_63 (Conv2D)              (None, 8, 8, 512)    2359808     activation_46[0][0]
__________________________________________________________________________________________________
batch_normalization_63 (BatchNo (None, 8, 8, 512)    2048        conv2d_63[0][0]
__________________________________________________________________________________________________
activation_47 (Activation)      (None, 8, 8, 512)    0           batch_normalization_63[0][0]
__________________________________________________________________________________________________
conv2d_61 (Conv2D)              (None, 8, 8, 2048)   4196352     activation_45[0][0]
__________________________________________________________________________________________________
conv2d_64 (Conv2D)              (None, 8, 8, 2048)   1050624     activation_47[0][0]
__________________________________________________________________________________________________
batch_normalization_61 (BatchNo (None, 8, 8, 2048)   8192        conv2d_61[0][0]
__________________________________________________________________________________________________
batch_normalization_64 (BatchNo (None, 8, 8, 2048)   8192        conv2d_64[0][0]
__________________________________________________________________________________________________
add_15 (Add)                    (None, 8, 8, 2048)   0           batch_normalization_61[0][0]
                                                                 batch_normalization_64[0][0]
__________________________________________________________________________________________________
activation_48 (Activation)      (None, 8, 8, 2048)   0           add_15[0][0]
__________________________________________________________________________________________________
global_average_pooling2d (Globa (None, 2048)         0           activation_48[0][0]
__________________________________________________________________________________________________
dense (Dense)                   (None, 100)          204900      global_average_pooling2d[0][0]
==================================================================================================
Total params: 38,397,924
Trainable params: 38,322,276
Non-trainable params: 75,648
__________________________________________________________________________________________________

```

</div></details>

サマリー出してくれました。うれしい
ただ答え合わせしてみたところ、Gobalaveratepoolingする前のhとwが1まわり小さくなっているのが気になります。またはじめのところも253x253になってたりと、もう少し直す必要がありそうです。

## 4回目
はじめの253になっている部分については、畳み込んだら256になってもらいたいのではZeroPadding2Dで対処します。
hとwが1周り小さくなっているのははじめのMaxPoolingしたときにstrideを2にしてしまっているのが原因っぽそうです。

#### 結果
<details><summary>出力</summary><div>

```bash
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0
__________________________________________________________________________________________________
zero_padding2d (ZeroPadding2D)  (None, 230, 230, 3)  0           input_1[0][0]
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 112, 112, 64) 9472        zero_padding2d[0][0]
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, 112, 112, 64) 256         conv2d[0][0]
__________________________________________________________________________________________________
activation (Activation)         (None, 112, 112, 64) 0           batch_normalization[0][0]
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 55, 55, 64)   0           activation[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 55, 55, 64)   4160        max_pooling2d[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 55, 55, 64)   256         conv2d_2[0][0]
__________________________________________________________________________________________________
activation_1 (Activation)       (None, 55, 55, 64)   0           batch_normalization_2[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 55, 55, 64)   36928       activation_1[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 55, 55, 64)   256         conv2d_3[0][0]
__________________________________________________________________________________________________
activation_2 (Activation)       (None, 55, 55, 64)   0           batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 55, 55, 256)  16640       max_pooling2d[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 55, 55, 256)  16640       activation_2[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 55, 55, 256)  1024        conv2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 55, 55, 256)  1024        conv2d_4[0][0]
__________________________________________________________________________________________________
add (Add)                       (None, 55, 55, 256)  0           batch_normalization_1[0][0]
                                                                 batch_normalization_4[0][0]
__________________________________________________________________________________________________
activation_3 (Activation)       (None, 55, 55, 256)  0           add[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D)               (None, 55, 55, 64)   16448       activation_3[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 55, 55, 64)   256         conv2d_6[0][0]
__________________________________________________________________________________________________
activation_4 (Activation)       (None, 55, 55, 64)   0           batch_normalization_6[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D)               (None, 55, 55, 64)   36928       activation_4[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 55, 55, 64)   256         conv2d_7[0][0]
__________________________________________________________________________________________________
activation_5 (Activation)       (None, 55, 55, 64)   0           batch_normalization_7[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 55, 55, 256)  65792       activation_3[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D)               (None, 55, 55, 256)  16640       activation_5[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 55, 55, 256)  1024        conv2d_5[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 55, 55, 256)  1024        conv2d_8[0][0]
__________________________________________________________________________________________________
add_1 (Add)                     (None, 55, 55, 256)  0           batch_normalization_5[0][0]
                                                                 batch_normalization_8[0][0]
__________________________________________________________________________________________________
activation_6 (Activation)       (None, 55, 55, 256)  0           add_1[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D)              (None, 55, 55, 64)   16448       activation_6[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 55, 55, 64)   256         conv2d_10[0][0]
__________________________________________________________________________________________________
activation_7 (Activation)       (None, 55, 55, 64)   0           batch_normalization_10[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D)              (None, 55, 55, 64)   36928       activation_7[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 55, 55, 64)   256         conv2d_11[0][0]
__________________________________________________________________________________________________
activation_8 (Activation)       (None, 55, 55, 64)   0           batch_normalization_11[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D)               (None, 55, 55, 256)  65792       activation_6[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D)              (None, 55, 55, 256)  16640       activation_8[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 55, 55, 256)  1024        conv2d_9[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 55, 55, 256)  1024        conv2d_12[0][0]
__________________________________________________________________________________________________
add_2 (Add)                     (None, 55, 55, 256)  0           batch_normalization_9[0][0]
                                                                 batch_normalization_12[0][0]
__________________________________________________________________________________________________
activation_9 (Activation)       (None, 55, 55, 256)  0           add_2[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D)              (None, 28, 28, 128)  32896       activation_9[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 28, 28, 128)  512         conv2d_14[0][0]
__________________________________________________________________________________________________
activation_10 (Activation)      (None, 28, 28, 128)  0           batch_normalization_14[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D)              (None, 28, 28, 128)  147584      activation_10[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 28, 28, 128)  512         conv2d_15[0][0]
__________________________________________________________________________________________________
activation_11 (Activation)      (None, 28, 28, 128)  0           batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D)              (None, 28, 28, 512)  131584      activation_9[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D)              (None, 28, 28, 512)  66048       activation_11[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 28, 28, 512)  2048        conv2d_13[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 28, 28, 512)  2048        conv2d_16[0][0]
__________________________________________________________________________________________________
add_3 (Add)                     (None, 28, 28, 512)  0           batch_normalization_13[0][0]
                                                                 batch_normalization_16[0][0]
__________________________________________________________________________________________________
activation_12 (Activation)      (None, 28, 28, 512)  0           add_3[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D)              (None, 28, 28, 128)  65664       activation_12[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 28, 28, 128)  512         conv2d_18[0][0]
__________________________________________________________________________________________________
activation_13 (Activation)      (None, 28, 28, 128)  0           batch_normalization_18[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 28, 28, 128)  147584      activation_13[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 28, 28, 128)  512         conv2d_19[0][0]
__________________________________________________________________________________________________
activation_14 (Activation)      (None, 28, 28, 128)  0           batch_normalization_19[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D)              (None, 28, 28, 512)  262656      activation_12[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D)              (None, 28, 28, 512)  66048       activation_14[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 28, 28, 512)  2048        conv2d_17[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 28, 28, 512)  2048        conv2d_20[0][0]
__________________________________________________________________________________________________
add_4 (Add)                     (None, 28, 28, 512)  0           batch_normalization_17[0][0]
                                                                 batch_normalization_20[0][0]
__________________________________________________________________________________________________
activation_15 (Activation)      (None, 28, 28, 512)  0           add_4[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D)              (None, 28, 28, 128)  65664       activation_15[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 28, 28, 128)  512         conv2d_22[0][0]
__________________________________________________________________________________________________
activation_16 (Activation)      (None, 28, 28, 128)  0           batch_normalization_22[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D)              (None, 28, 28, 128)  147584      activation_16[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 28, 28, 128)  512         conv2d_23[0][0]
__________________________________________________________________________________________________
activation_17 (Activation)      (None, 28, 28, 128)  0           batch_normalization_23[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D)              (None, 28, 28, 512)  262656      activation_15[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D)              (None, 28, 28, 512)  66048       activation_17[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 28, 28, 512)  2048        conv2d_21[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 28, 28, 512)  2048        conv2d_24[0][0]
__________________________________________________________________________________________________
add_5 (Add)                     (None, 28, 28, 512)  0           batch_normalization_21[0][0]
                                                                 batch_normalization_24[0][0]
__________________________________________________________________________________________________
activation_18 (Activation)      (None, 28, 28, 512)  0           add_5[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D)              (None, 28, 28, 128)  65664       activation_18[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 28, 28, 128)  512         conv2d_26[0][0]
__________________________________________________________________________________________________
activation_19 (Activation)      (None, 28, 28, 128)  0           batch_normalization_26[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D)              (None, 28, 28, 128)  147584      activation_19[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 28, 28, 128)  512         conv2d_27[0][0]
__________________________________________________________________________________________________
activation_20 (Activation)      (None, 28, 28, 128)  0           batch_normalization_27[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D)              (None, 28, 28, 512)  262656      activation_18[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D)              (None, 28, 28, 512)  66048       activation_20[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 28, 28, 512)  2048        conv2d_25[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 28, 28, 512)  2048        conv2d_28[0][0]
__________________________________________________________________________________________________
add_6 (Add)                     (None, 28, 28, 512)  0           batch_normalization_25[0][0]
                                                                 batch_normalization_28[0][0]
__________________________________________________________________________________________________
activation_21 (Activation)      (None, 28, 28, 512)  0           add_6[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D)              (None, 14, 14, 256)  131328      activation_21[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 14, 14, 256)  1024        conv2d_30[0][0]
__________________________________________________________________________________________________
activation_22 (Activation)      (None, 14, 14, 256)  0           batch_normalization_30[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D)              (None, 14, 14, 256)  590080      activation_22[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 14, 14, 256)  1024        conv2d_31[0][0]
__________________________________________________________________________________________________
activation_23 (Activation)      (None, 14, 14, 256)  0           batch_normalization_31[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D)              (None, 14, 14, 1024) 525312      activation_21[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D)              (None, 14, 14, 1024) 263168      activation_23[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 14, 14, 1024) 4096        conv2d_29[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 14, 14, 1024) 4096        conv2d_32[0][0]
__________________________________________________________________________________________________
add_7 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_29[0][0]
                                                                 batch_normalization_32[0][0]
__________________________________________________________________________________________________
activation_24 (Activation)      (None, 14, 14, 1024) 0           add_7[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D)              (None, 14, 14, 256)  262400      activation_24[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 14, 14, 256)  1024        conv2d_34[0][0]
__________________________________________________________________________________________________
activation_25 (Activation)      (None, 14, 14, 256)  0           batch_normalization_34[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D)              (None, 14, 14, 256)  590080      activation_25[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 14, 14, 256)  1024        conv2d_35[0][0]
__________________________________________________________________________________________________
activation_26 (Activation)      (None, 14, 14, 256)  0           batch_normalization_35[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_24[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D)              (None, 14, 14, 1024) 263168      activation_26[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 14, 14, 1024) 4096        conv2d_33[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 14, 14, 1024) 4096        conv2d_36[0][0]
__________________________________________________________________________________________________
add_8 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_33[0][0]
                                                                 batch_normalization_36[0][0]
__________________________________________________________________________________________________
activation_27 (Activation)      (None, 14, 14, 1024) 0           add_8[0][0]
__________________________________________________________________________________________________
conv2d_38 (Conv2D)              (None, 14, 14, 256)  262400      activation_27[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 14, 14, 256)  1024        conv2d_38[0][0]
__________________________________________________________________________________________________
activation_28 (Activation)      (None, 14, 14, 256)  0           batch_normalization_38[0][0]
__________________________________________________________________________________________________
conv2d_39 (Conv2D)              (None, 14, 14, 256)  590080      activation_28[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 14, 14, 256)  1024        conv2d_39[0][0]
__________________________________________________________________________________________________
activation_29 (Activation)      (None, 14, 14, 256)  0           batch_normalization_39[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_27[0][0]
__________________________________________________________________________________________________
conv2d_40 (Conv2D)              (None, 14, 14, 1024) 263168      activation_29[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 14, 14, 1024) 4096        conv2d_37[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 14, 14, 1024) 4096        conv2d_40[0][0]
__________________________________________________________________________________________________
add_9 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_37[0][0]
                                                                 batch_normalization_40[0][0]
__________________________________________________________________________________________________
activation_30 (Activation)      (None, 14, 14, 1024) 0           add_9[0][0]
__________________________________________________________________________________________________
conv2d_42 (Conv2D)              (None, 14, 14, 256)  262400      activation_30[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 14, 14, 256)  1024        conv2d_42[0][0]
__________________________________________________________________________________________________
activation_31 (Activation)      (None, 14, 14, 256)  0           batch_normalization_42[0][0]
__________________________________________________________________________________________________
conv2d_43 (Conv2D)              (None, 14, 14, 256)  590080      activation_31[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 14, 14, 256)  1024        conv2d_43[0][0]
__________________________________________________________________________________________________
activation_32 (Activation)      (None, 14, 14, 256)  0           batch_normalization_43[0][0]
__________________________________________________________________________________________________
conv2d_41 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_30[0][0]
__________________________________________________________________________________________________
conv2d_44 (Conv2D)              (None, 14, 14, 1024) 263168      activation_32[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 14, 14, 1024) 4096        conv2d_41[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 14, 14, 1024) 4096        conv2d_44[0][0]
__________________________________________________________________________________________________
add_10 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_41[0][0]
                                                                 batch_normalization_44[0][0]
__________________________________________________________________________________________________
activation_33 (Activation)      (None, 14, 14, 1024) 0           add_10[0][0]
__________________________________________________________________________________________________
conv2d_46 (Conv2D)              (None, 14, 14, 256)  262400      activation_33[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 14, 14, 256)  1024        conv2d_46[0][0]
__________________________________________________________________________________________________
activation_34 (Activation)      (None, 14, 14, 256)  0           batch_normalization_46[0][0]
__________________________________________________________________________________________________
conv2d_47 (Conv2D)              (None, 14, 14, 256)  590080      activation_34[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 14, 14, 256)  1024        conv2d_47[0][0]
__________________________________________________________________________________________________
activation_35 (Activation)      (None, 14, 14, 256)  0           batch_normalization_47[0][0]
__________________________________________________________________________________________________
conv2d_45 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_33[0][0]
__________________________________________________________________________________________________
conv2d_48 (Conv2D)              (None, 14, 14, 1024) 263168      activation_35[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 14, 14, 1024) 4096        conv2d_45[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 14, 14, 1024) 4096        conv2d_48[0][0]
__________________________________________________________________________________________________
add_11 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_45[0][0]
                                                                 batch_normalization_48[0][0]
__________________________________________________________________________________________________
activation_36 (Activation)      (None, 14, 14, 1024) 0           add_11[0][0]
__________________________________________________________________________________________________
conv2d_50 (Conv2D)              (None, 14, 14, 256)  262400      activation_36[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 14, 14, 256)  1024        conv2d_50[0][0]
__________________________________________________________________________________________________
activation_37 (Activation)      (None, 14, 14, 256)  0           batch_normalization_50[0][0]
__________________________________________________________________________________________________
conv2d_51 (Conv2D)              (None, 14, 14, 256)  590080      activation_37[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 14, 14, 256)  1024        conv2d_51[0][0]
__________________________________________________________________________________________________
activation_38 (Activation)      (None, 14, 14, 256)  0           batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_49 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_36[0][0]
__________________________________________________________________________________________________
conv2d_52 (Conv2D)              (None, 14, 14, 1024) 263168      activation_38[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 14, 14, 1024) 4096        conv2d_49[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 14, 14, 1024) 4096        conv2d_52[0][0]
__________________________________________________________________________________________________
add_12 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_49[0][0]
                                                                 batch_normalization_52[0][0]
__________________________________________________________________________________________________
activation_39 (Activation)      (None, 14, 14, 1024) 0           add_12[0][0]
__________________________________________________________________________________________________
conv2d_54 (Conv2D)              (None, 7, 7, 512)    524800      activation_39[0][0]
__________________________________________________________________________________________________
batch_normalization_54 (BatchNo (None, 7, 7, 512)    2048        conv2d_54[0][0]
__________________________________________________________________________________________________
activation_40 (Activation)      (None, 7, 7, 512)    0           batch_normalization_54[0][0]
__________________________________________________________________________________________________
conv2d_55 (Conv2D)              (None, 7, 7, 512)    2359808     activation_40[0][0]
__________________________________________________________________________________________________
batch_normalization_55 (BatchNo (None, 7, 7, 512)    2048        conv2d_55[0][0]
__________________________________________________________________________________________________
activation_41 (Activation)      (None, 7, 7, 512)    0           batch_normalization_55[0][0]
__________________________________________________________________________________________________
conv2d_53 (Conv2D)              (None, 7, 7, 2048)   2099200     activation_39[0][0]
__________________________________________________________________________________________________
conv2d_56 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_41[0][0]
__________________________________________________________________________________________________
batch_normalization_53 (BatchNo (None, 7, 7, 2048)   8192        conv2d_53[0][0]
__________________________________________________________________________________________________
batch_normalization_56 (BatchNo (None, 7, 7, 2048)   8192        conv2d_56[0][0]
__________________________________________________________________________________________________
add_13 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_53[0][0]
                                                                 batch_normalization_56[0][0]
__________________________________________________________________________________________________
activation_42 (Activation)      (None, 7, 7, 2048)   0           add_13[0][0]
__________________________________________________________________________________________________
conv2d_58 (Conv2D)              (None, 7, 7, 512)    1049088     activation_42[0][0]
__________________________________________________________________________________________________
batch_normalization_58 (BatchNo (None, 7, 7, 512)    2048        conv2d_58[0][0]
__________________________________________________________________________________________________
activation_43 (Activation)      (None, 7, 7, 512)    0           batch_normalization_58[0][0]
__________________________________________________________________________________________________
conv2d_59 (Conv2D)              (None, 7, 7, 512)    2359808     activation_43[0][0]
__________________________________________________________________________________________________
batch_normalization_59 (BatchNo (None, 7, 7, 512)    2048        conv2d_59[0][0]
__________________________________________________________________________________________________
activation_44 (Activation)      (None, 7, 7, 512)    0           batch_normalization_59[0][0]
__________________________________________________________________________________________________
conv2d_57 (Conv2D)              (None, 7, 7, 2048)   4196352     activation_42[0][0]
__________________________________________________________________________________________________
conv2d_60 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_44[0][0]
__________________________________________________________________________________________________
batch_normalization_57 (BatchNo (None, 7, 7, 2048)   8192        conv2d_57[0][0]
__________________________________________________________________________________________________
batch_normalization_60 (BatchNo (None, 7, 7, 2048)   8192        conv2d_60[0][0]
__________________________________________________________________________________________________
add_14 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_57[0][0]
                                                                 batch_normalization_60[0][0]
__________________________________________________________________________________________________
activation_45 (Activation)      (None, 7, 7, 2048)   0           add_14[0][0]
__________________________________________________________________________________________________
conv2d_62 (Conv2D)              (None, 7, 7, 512)    1049088     activation_45[0][0]
__________________________________________________________________________________________________
batch_normalization_62 (BatchNo (None, 7, 7, 512)    2048        conv2d_62[0][0]
__________________________________________________________________________________________________
activation_46 (Activation)      (None, 7, 7, 512)    0           batch_normalization_62[0][0]
__________________________________________________________________________________________________
conv2d_63 (Conv2D)              (None, 7, 7, 512)    2359808     activation_46[0][0]
__________________________________________________________________________________________________
batch_normalization_63 (BatchNo (None, 7, 7, 512)    2048        conv2d_63[0][0]
__________________________________________________________________________________________________
activation_47 (Activation)      (None, 7, 7, 512)    0           batch_normalization_63[0][0]
__________________________________________________________________________________________________
conv2d_61 (Conv2D)              (None, 7, 7, 2048)   4196352     activation_45[0][0]
__________________________________________________________________________________________________
conv2d_64 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_47[0][0]
__________________________________________________________________________________________________
batch_normalization_61 (BatchNo (None, 7, 7, 2048)   8192        conv2d_61[0][0]
__________________________________________________________________________________________________
batch_normalization_64 (BatchNo (None, 7, 7, 2048)   8192        conv2d_64[0][0]
__________________________________________________________________________________________________
add_15 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_61[0][0]
                                                                 batch_normalization_64[0][0]
__________________________________________________________________________________________________
activation_48 (Activation)      (None, 7, 7, 2048)   0           add_15[0][0]
__________________________________________________________________________________________________
global_average_pooling2d (Globa (None, 2048)         0           activation_48[0][0]
__________________________________________________________________________________________________
dense (Dense)                   (None, 100)          204900      global_average_pooling2d[0][0]
==================================================================================================
Total params: 38,397,924
Trainable params: 38,322,276
Non-trainable params: 75,648
__________________________________________________________________________________________________
```

</div></details>

MaxPoolingした後のサイズが127になってます。こいつもZeroPaddingで対処してしまいます。

## 5回目
入力サイズは改めて224x224x3、出力は1000にします。

<details><summary>出力</summary><div>

```bash
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0
__________________________________________________________________________________________________
zero_padding2d (ZeroPadding2D)  (None, 230, 230, 3)  0           input_1[0][0]
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 112, 112, 64) 9472        zero_padding2d[0][0]
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, 112, 112, 64) 256         conv2d[0][0]
__________________________________________________________________________________________________
activation (Activation)         (None, 112, 112, 64) 0           batch_normalization[0][0]
__________________________________________________________________________________________________
zero_padding2d_1 (ZeroPadding2D (None, 114, 114, 64) 0           activation[0][0]
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 56, 56, 64)   0           zero_padding2d_1[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 56, 56, 64)   4160        max_pooling2d[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 56, 56, 64)   256         conv2d_2[0][0]
__________________________________________________________________________________________________
activation_1 (Activation)       (None, 56, 56, 64)   0           batch_normalization_2[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 56, 56, 64)   36928       activation_1[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 56, 56, 64)   256         conv2d_3[0][0]
__________________________________________________________________________________________________
activation_2 (Activation)       (None, 56, 56, 64)   0           batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 56, 56, 256)  16640       max_pooling2d[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 56, 56, 256)  16640       activation_2[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 56, 56, 256)  1024        conv2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 56, 56, 256)  1024        conv2d_4[0][0]
__________________________________________________________________________________________________
add (Add)                       (None, 56, 56, 256)  0           batch_normalization_1[0][0]
                                                                 batch_normalization_4[0][0]
__________________________________________________________________________________________________
activation_3 (Activation)       (None, 56, 56, 256)  0           add[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D)               (None, 56, 56, 64)   16448       activation_3[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 56, 56, 64)   256         conv2d_6[0][0]
__________________________________________________________________________________________________
activation_4 (Activation)       (None, 56, 56, 64)   0           batch_normalization_6[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D)               (None, 56, 56, 64)   36928       activation_4[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 56, 56, 64)   256         conv2d_7[0][0]
__________________________________________________________________________________________________
activation_5 (Activation)       (None, 56, 56, 64)   0           batch_normalization_7[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 56, 56, 256)  65792       activation_3[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D)               (None, 56, 56, 256)  16640       activation_5[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 56, 56, 256)  1024        conv2d_5[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 56, 56, 256)  1024        conv2d_8[0][0]
__________________________________________________________________________________________________
add_1 (Add)                     (None, 56, 56, 256)  0           batch_normalization_5[0][0]
                                                                 batch_normalization_8[0][0]
__________________________________________________________________________________________________
activation_6 (Activation)       (None, 56, 56, 256)  0           add_1[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D)              (None, 56, 56, 64)   16448       activation_6[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 56, 56, 64)   256         conv2d_10[0][0]
__________________________________________________________________________________________________
activation_7 (Activation)       (None, 56, 56, 64)   0           batch_normalization_10[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D)              (None, 56, 56, 64)   36928       activation_7[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 56, 56, 64)   256         conv2d_11[0][0]
__________________________________________________________________________________________________
activation_8 (Activation)       (None, 56, 56, 64)   0           batch_normalization_11[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D)               (None, 56, 56, 256)  65792       activation_6[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D)              (None, 56, 56, 256)  16640       activation_8[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 56, 56, 256)  1024        conv2d_9[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 56, 56, 256)  1024        conv2d_12[0][0]
__________________________________________________________________________________________________
add_2 (Add)                     (None, 56, 56, 256)  0           batch_normalization_9[0][0]
                                                                 batch_normalization_12[0][0]
__________________________________________________________________________________________________
activation_9 (Activation)       (None, 56, 56, 256)  0           add_2[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D)              (None, 28, 28, 128)  32896       activation_9[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 28, 28, 128)  512         conv2d_14[0][0]
__________________________________________________________________________________________________
activation_10 (Activation)      (None, 28, 28, 128)  0           batch_normalization_14[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D)              (None, 28, 28, 128)  147584      activation_10[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 28, 28, 128)  512         conv2d_15[0][0]
__________________________________________________________________________________________________
activation_11 (Activation)      (None, 28, 28, 128)  0           batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D)              (None, 28, 28, 512)  131584      activation_9[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D)              (None, 28, 28, 512)  66048       activation_11[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 28, 28, 512)  2048        conv2d_13[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 28, 28, 512)  2048        conv2d_16[0][0]
__________________________________________________________________________________________________
add_3 (Add)                     (None, 28, 28, 512)  0           batch_normalization_13[0][0]
                                                                 batch_normalization_16[0][0]
__________________________________________________________________________________________________
activation_12 (Activation)      (None, 28, 28, 512)  0           add_3[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D)              (None, 28, 28, 128)  65664       activation_12[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 28, 28, 128)  512         conv2d_18[0][0]
__________________________________________________________________________________________________
activation_13 (Activation)      (None, 28, 28, 128)  0           batch_normalization_18[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 28, 28, 128)  147584      activation_13[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 28, 28, 128)  512         conv2d_19[0][0]
__________________________________________________________________________________________________
activation_14 (Activation)      (None, 28, 28, 128)  0           batch_normalization_19[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D)              (None, 28, 28, 512)  262656      activation_12[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D)              (None, 28, 28, 512)  66048       activation_14[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 28, 28, 512)  2048        conv2d_17[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 28, 28, 512)  2048        conv2d_20[0][0]
__________________________________________________________________________________________________
add_4 (Add)                     (None, 28, 28, 512)  0           batch_normalization_17[0][0]
                                                                 batch_normalization_20[0][0]
__________________________________________________________________________________________________
activation_15 (Activation)      (None, 28, 28, 512)  0           add_4[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D)              (None, 28, 28, 128)  65664       activation_15[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 28, 28, 128)  512         conv2d_22[0][0]
__________________________________________________________________________________________________
activation_16 (Activation)      (None, 28, 28, 128)  0           batch_normalization_22[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D)              (None, 28, 28, 128)  147584      activation_16[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 28, 28, 128)  512         conv2d_23[0][0]
__________________________________________________________________________________________________
activation_17 (Activation)      (None, 28, 28, 128)  0           batch_normalization_23[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D)              (None, 28, 28, 512)  262656      activation_15[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D)              (None, 28, 28, 512)  66048       activation_17[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 28, 28, 512)  2048        conv2d_21[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 28, 28, 512)  2048        conv2d_24[0][0]
__________________________________________________________________________________________________
add_5 (Add)                     (None, 28, 28, 512)  0           batch_normalization_21[0][0]
                                                                 batch_normalization_24[0][0]
__________________________________________________________________________________________________
activation_18 (Activation)      (None, 28, 28, 512)  0           add_5[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D)              (None, 28, 28, 128)  65664       activation_18[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 28, 28, 128)  512         conv2d_26[0][0]
__________________________________________________________________________________________________
activation_19 (Activation)      (None, 28, 28, 128)  0           batch_normalization_26[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D)              (None, 28, 28, 128)  147584      activation_19[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 28, 28, 128)  512         conv2d_27[0][0]
__________________________________________________________________________________________________
activation_20 (Activation)      (None, 28, 28, 128)  0           batch_normalization_27[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D)              (None, 28, 28, 512)  262656      activation_18[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D)              (None, 28, 28, 512)  66048       activation_20[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 28, 28, 512)  2048        conv2d_25[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 28, 28, 512)  2048        conv2d_28[0][0]
__________________________________________________________________________________________________
add_6 (Add)                     (None, 28, 28, 512)  0           batch_normalization_25[0][0]
                                                                 batch_normalization_28[0][0]
__________________________________________________________________________________________________
activation_21 (Activation)      (None, 28, 28, 512)  0           add_6[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D)              (None, 14, 14, 256)  131328      activation_21[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 14, 14, 256)  1024        conv2d_30[0][0]
__________________________________________________________________________________________________
activation_22 (Activation)      (None, 14, 14, 256)  0           batch_normalization_30[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D)              (None, 14, 14, 256)  590080      activation_22[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 14, 14, 256)  1024        conv2d_31[0][0]
__________________________________________________________________________________________________
activation_23 (Activation)      (None, 14, 14, 256)  0           batch_normalization_31[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D)              (None, 14, 14, 1024) 525312      activation_21[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D)              (None, 14, 14, 1024) 263168      activation_23[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 14, 14, 1024) 4096        conv2d_29[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 14, 14, 1024) 4096        conv2d_32[0][0]
__________________________________________________________________________________________________
add_7 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_29[0][0]
                                                                 batch_normalization_32[0][0]
__________________________________________________________________________________________________
activation_24 (Activation)      (None, 14, 14, 1024) 0           add_7[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D)              (None, 14, 14, 256)  262400      activation_24[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 14, 14, 256)  1024        conv2d_34[0][0]
__________________________________________________________________________________________________
activation_25 (Activation)      (None, 14, 14, 256)  0           batch_normalization_34[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D)              (None, 14, 14, 256)  590080      activation_25[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 14, 14, 256)  1024        conv2d_35[0][0]
__________________________________________________________________________________________________
activation_26 (Activation)      (None, 14, 14, 256)  0           batch_normalization_35[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_24[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D)              (None, 14, 14, 1024) 263168      activation_26[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 14, 14, 1024) 4096        conv2d_33[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 14, 14, 1024) 4096        conv2d_36[0][0]
__________________________________________________________________________________________________
add_8 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_33[0][0]
                                                                 batch_normalization_36[0][0]
__________________________________________________________________________________________________
activation_27 (Activation)      (None, 14, 14, 1024) 0           add_8[0][0]
__________________________________________________________________________________________________
conv2d_38 (Conv2D)              (None, 14, 14, 256)  262400      activation_27[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 14, 14, 256)  1024        conv2d_38[0][0]
__________________________________________________________________________________________________
activation_28 (Activation)      (None, 14, 14, 256)  0           batch_normalization_38[0][0]
__________________________________________________________________________________________________
conv2d_39 (Conv2D)              (None, 14, 14, 256)  590080      activation_28[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 14, 14, 256)  1024        conv2d_39[0][0]
__________________________________________________________________________________________________
activation_29 (Activation)      (None, 14, 14, 256)  0           batch_normalization_39[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_27[0][0]
__________________________________________________________________________________________________
conv2d_40 (Conv2D)              (None, 14, 14, 1024) 263168      activation_29[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 14, 14, 1024) 4096        conv2d_37[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 14, 14, 1024) 4096        conv2d_40[0][0]
__________________________________________________________________________________________________
add_9 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_37[0][0]
                                                                 batch_normalization_40[0][0]
__________________________________________________________________________________________________
activation_30 (Activation)      (None, 14, 14, 1024) 0           add_9[0][0]
__________________________________________________________________________________________________
conv2d_42 (Conv2D)              (None, 14, 14, 256)  262400      activation_30[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 14, 14, 256)  1024        conv2d_42[0][0]
__________________________________________________________________________________________________
activation_31 (Activation)      (None, 14, 14, 256)  0           batch_normalization_42[0][0]
__________________________________________________________________________________________________
conv2d_43 (Conv2D)              (None, 14, 14, 256)  590080      activation_31[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 14, 14, 256)  1024        conv2d_43[0][0]
__________________________________________________________________________________________________
activation_32 (Activation)      (None, 14, 14, 256)  0           batch_normalization_43[0][0]
__________________________________________________________________________________________________
conv2d_41 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_30[0][0]
__________________________________________________________________________________________________
conv2d_44 (Conv2D)              (None, 14, 14, 1024) 263168      activation_32[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 14, 14, 1024) 4096        conv2d_41[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 14, 14, 1024) 4096        conv2d_44[0][0]
__________________________________________________________________________________________________
add_10 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_41[0][0]
                                                                 batch_normalization_44[0][0]
__________________________________________________________________________________________________
activation_33 (Activation)      (None, 14, 14, 1024) 0           add_10[0][0]
__________________________________________________________________________________________________
conv2d_46 (Conv2D)              (None, 14, 14, 256)  262400      activation_33[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 14, 14, 256)  1024        conv2d_46[0][0]
__________________________________________________________________________________________________
activation_34 (Activation)      (None, 14, 14, 256)  0           batch_normalization_46[0][0]
__________________________________________________________________________________________________
conv2d_47 (Conv2D)              (None, 14, 14, 256)  590080      activation_34[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 14, 14, 256)  1024        conv2d_47[0][0]
__________________________________________________________________________________________________
activation_35 (Activation)      (None, 14, 14, 256)  0           batch_normalization_47[0][0]
__________________________________________________________________________________________________
conv2d_45 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_33[0][0]
__________________________________________________________________________________________________
conv2d_48 (Conv2D)              (None, 14, 14, 1024) 263168      activation_35[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 14, 14, 1024) 4096        conv2d_45[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 14, 14, 1024) 4096        conv2d_48[0][0]
__________________________________________________________________________________________________
add_11 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_45[0][0]
                                                                 batch_normalization_48[0][0]
__________________________________________________________________________________________________
activation_36 (Activation)      (None, 14, 14, 1024) 0           add_11[0][0]
__________________________________________________________________________________________________
conv2d_50 (Conv2D)              (None, 14, 14, 256)  262400      activation_36[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 14, 14, 256)  1024        conv2d_50[0][0]
__________________________________________________________________________________________________
activation_37 (Activation)      (None, 14, 14, 256)  0           batch_normalization_50[0][0]
__________________________________________________________________________________________________
conv2d_51 (Conv2D)              (None, 14, 14, 256)  590080      activation_37[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 14, 14, 256)  1024        conv2d_51[0][0]
__________________________________________________________________________________________________
activation_38 (Activation)      (None, 14, 14, 256)  0           batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_49 (Conv2D)              (None, 14, 14, 1024) 1049600     activation_36[0][0]
__________________________________________________________________________________________________
conv2d_52 (Conv2D)              (None, 14, 14, 1024) 263168      activation_38[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 14, 14, 1024) 4096        conv2d_49[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 14, 14, 1024) 4096        conv2d_52[0][0]
__________________________________________________________________________________________________
add_12 (Add)                    (None, 14, 14, 1024) 0           batch_normalization_49[0][0]
                                                                 batch_normalization_52[0][0]
__________________________________________________________________________________________________
activation_39 (Activation)      (None, 14, 14, 1024) 0           add_12[0][0]
__________________________________________________________________________________________________
conv2d_54 (Conv2D)              (None, 7, 7, 512)    524800      activation_39[0][0]
__________________________________________________________________________________________________
batch_normalization_54 (BatchNo (None, 7, 7, 512)    2048        conv2d_54[0][0]
__________________________________________________________________________________________________
activation_40 (Activation)      (None, 7, 7, 512)    0           batch_normalization_54[0][0]
__________________________________________________________________________________________________
conv2d_55 (Conv2D)              (None, 7, 7, 512)    2359808     activation_40[0][0]
__________________________________________________________________________________________________
batch_normalization_55 (BatchNo (None, 7, 7, 512)    2048        conv2d_55[0][0]
__________________________________________________________________________________________________
activation_41 (Activation)      (None, 7, 7, 512)    0           batch_normalization_55[0][0]
__________________________________________________________________________________________________
conv2d_53 (Conv2D)              (None, 7, 7, 2048)   2099200     activation_39[0][0]
__________________________________________________________________________________________________
conv2d_56 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_41[0][0]
__________________________________________________________________________________________________
batch_normalization_53 (BatchNo (None, 7, 7, 2048)   8192        conv2d_53[0][0]
__________________________________________________________________________________________________
batch_normalization_56 (BatchNo (None, 7, 7, 2048)   8192        conv2d_56[0][0]
__________________________________________________________________________________________________
add_13 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_53[0][0]
                                                                 batch_normalization_56[0][0]
__________________________________________________________________________________________________
activation_42 (Activation)      (None, 7, 7, 2048)   0           add_13[0][0]
__________________________________________________________________________________________________
conv2d_58 (Conv2D)              (None, 7, 7, 512)    1049088     activation_42[0][0]
__________________________________________________________________________________________________
batch_normalization_58 (BatchNo (None, 7, 7, 512)    2048        conv2d_58[0][0]
__________________________________________________________________________________________________
activation_43 (Activation)      (None, 7, 7, 512)    0           batch_normalization_58[0][0]
__________________________________________________________________________________________________
conv2d_59 (Conv2D)              (None, 7, 7, 512)    2359808     activation_43[0][0]
__________________________________________________________________________________________________
batch_normalization_59 (BatchNo (None, 7, 7, 512)    2048        conv2d_59[0][0]
__________________________________________________________________________________________________
activation_44 (Activation)      (None, 7, 7, 512)    0           batch_normalization_59[0][0]
__________________________________________________________________________________________________
conv2d_57 (Conv2D)              (None, 7, 7, 2048)   4196352     activation_42[0][0]
__________________________________________________________________________________________________
conv2d_60 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_44[0][0]
__________________________________________________________________________________________________
batch_normalization_57 (BatchNo (None, 7, 7, 2048)   8192        conv2d_57[0][0]
__________________________________________________________________________________________________
batch_normalization_60 (BatchNo (None, 7, 7, 2048)   8192        conv2d_60[0][0]
__________________________________________________________________________________________________
add_14 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_57[0][0]
                                                                 batch_normalization_60[0][0]
__________________________________________________________________________________________________
activation_45 (Activation)      (None, 7, 7, 2048)   0           add_14[0][0]
__________________________________________________________________________________________________
conv2d_62 (Conv2D)              (None, 7, 7, 512)    1049088     activation_45[0][0]
__________________________________________________________________________________________________
batch_normalization_62 (BatchNo (None, 7, 7, 512)    2048        conv2d_62[0][0]
__________________________________________________________________________________________________
activation_46 (Activation)      (None, 7, 7, 512)    0           batch_normalization_62[0][0]
__________________________________________________________________________________________________
conv2d_63 (Conv2D)              (None, 7, 7, 512)    2359808     activation_46[0][0]
__________________________________________________________________________________________________
batch_normalization_63 (BatchNo (None, 7, 7, 512)    2048        conv2d_63[0][0]
__________________________________________________________________________________________________
activation_47 (Activation)      (None, 7, 7, 512)    0           batch_normalization_63[0][0]
__________________________________________________________________________________________________
conv2d_61 (Conv2D)              (None, 7, 7, 2048)   4196352     activation_45[0][0]
__________________________________________________________________________________________________
conv2d_64 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_47[0][0]
__________________________________________________________________________________________________
batch_normalization_61 (BatchNo (None, 7, 7, 2048)   8192        conv2d_61[0][0]
__________________________________________________________________________________________________
batch_normalization_64 (BatchNo (None, 7, 7, 2048)   8192        conv2d_64[0][0]
__________________________________________________________________________________________________
add_15 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_61[0][0]
                                                                 batch_normalization_64[0][0]
__________________________________________________________________________________________________
activation_48 (Activation)      (None, 7, 7, 2048)   0           add_15[0][0]
__________________________________________________________________________________________________
global_average_pooling2d (Globa (None, 2048)         0           activation_48[0][0]
__________________________________________________________________________________________________
dense (Dense)                   (None, 1000)         2049000     global_average_pooling2d[0][0]
==================================================================================================
Total params: 40,242,024
Trainable params: 40,166,376
Non-trainable params: 75,648
__________________________________________________________________________________________________
```

</div></details>

再び答え合わせしてみましたが、パラメータが異様に多い気がします(tf.keras公式だとだいたい2500万ほど)。

## 6回目
にらめっこしてましたが、$\bf x$のフィルターを毎度4倍にしてるのが原因っぽそうです。そういえば結合してしまえばフィルターは4倍してやる必要ないですよね。

#### 結果

<details><summary>出力</summary><div>

```bash
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0
__________________________________________________________________________________________________
zero_padding2d (ZeroPadding2D)  (None, 230, 230, 3)  0           input_1[0][0]
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 112, 112, 64) 9472        zero_padding2d[0][0]
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, 112, 112, 64) 256         conv2d[0][0]
__________________________________________________________________________________________________
activation (Activation)         (None, 112, 112, 64) 0           batch_normalization[0][0]
__________________________________________________________________________________________________
zero_padding2d_1 (ZeroPadding2D (None, 114, 114, 64) 0           activation[0][0]
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 56, 56, 64)   0           zero_padding2d_1[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 56, 56, 64)   4160        max_pooling2d[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 56, 56, 64)   256         conv2d_2[0][0]
__________________________________________________________________________________________________
activation_1 (Activation)       (None, 56, 56, 64)   0           batch_normalization_2[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 56, 56, 64)   36928       activation_1[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 56, 56, 64)   256         conv2d_3[0][0]
__________________________________________________________________________________________________
activation_2 (Activation)       (None, 56, 56, 64)   0           batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 56, 56, 256)  16640       max_pooling2d[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 56, 56, 256)  16640       activation_2[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 56, 56, 256)  1024        conv2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 56, 56, 256)  1024        conv2d_4[0][0]
__________________________________________________________________________________________________
add (Add)                       (None, 56, 56, 256)  0           batch_normalization_1[0][0]
                                                                 batch_normalization_4[0][0]
__________________________________________________________________________________________________
activation_3 (Activation)       (None, 56, 56, 256)  0           add[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 56, 56, 64)   16448       activation_3[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 56, 56, 64)   256         conv2d_5[0][0]
__________________________________________________________________________________________________
activation_4 (Activation)       (None, 56, 56, 64)   0           batch_normalization_5[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D)               (None, 56, 56, 64)   36928       activation_4[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 56, 56, 64)   256         conv2d_6[0][0]
__________________________________________________________________________________________________
activation_5 (Activation)       (None, 56, 56, 64)   0           batch_normalization_6[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D)               (None, 56, 56, 256)  16640       activation_5[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 56, 56, 256)  1024        conv2d_7[0][0]
__________________________________________________________________________________________________
add_1 (Add)                     (None, 56, 56, 256)  0           activation_3[0][0]
                                                                 batch_normalization_7[0][0]
__________________________________________________________________________________________________
activation_6 (Activation)       (None, 56, 56, 256)  0           add_1[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D)               (None, 56, 56, 64)   16448       activation_6[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 56, 56, 64)   256         conv2d_8[0][0]
__________________________________________________________________________________________________
activation_7 (Activation)       (None, 56, 56, 64)   0           batch_normalization_8[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D)               (None, 56, 56, 64)   36928       activation_7[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 56, 56, 64)   256         conv2d_9[0][0]
__________________________________________________________________________________________________
activation_8 (Activation)       (None, 56, 56, 64)   0           batch_normalization_9[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D)              (None, 56, 56, 256)  16640       activation_8[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 56, 56, 256)  1024        conv2d_10[0][0]
__________________________________________________________________________________________________
add_2 (Add)                     (None, 56, 56, 256)  0           activation_6[0][0]
                                                                 batch_normalization_10[0][0]
__________________________________________________________________________________________________
activation_9 (Activation)       (None, 56, 56, 256)  0           add_2[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D)              (None, 28, 28, 128)  32896       activation_9[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 28, 28, 128)  512         conv2d_12[0][0]
__________________________________________________________________________________________________
activation_10 (Activation)      (None, 28, 28, 128)  0           batch_normalization_12[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D)              (None, 28, 28, 128)  147584      activation_10[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 28, 28, 128)  512         conv2d_13[0][0]
__________________________________________________________________________________________________
activation_11 (Activation)      (None, 28, 28, 128)  0           batch_normalization_13[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D)              (None, 28, 28, 512)  131584      activation_9[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D)              (None, 28, 28, 512)  66048       activation_11[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 28, 28, 512)  2048        conv2d_11[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 28, 28, 512)  2048        conv2d_14[0][0]
__________________________________________________________________________________________________
add_3 (Add)                     (None, 28, 28, 512)  0           batch_normalization_11[0][0]
                                                                 batch_normalization_14[0][0]
__________________________________________________________________________________________________
activation_12 (Activation)      (None, 28, 28, 512)  0           add_3[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D)              (None, 28, 28, 128)  65664       activation_12[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 28, 28, 128)  512         conv2d_15[0][0]
__________________________________________________________________________________________________
activation_13 (Activation)      (None, 28, 28, 128)  0           batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D)              (None, 28, 28, 128)  147584      activation_13[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 28, 28, 128)  512         conv2d_16[0][0]
__________________________________________________________________________________________________
activation_14 (Activation)      (None, 28, 28, 128)  0           batch_normalization_16[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D)              (None, 28, 28, 512)  66048       activation_14[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 28, 28, 512)  2048        conv2d_17[0][0]
__________________________________________________________________________________________________
add_4 (Add)                     (None, 28, 28, 512)  0           activation_12[0][0]
                                                                 batch_normalization_17[0][0]
__________________________________________________________________________________________________
activation_15 (Activation)      (None, 28, 28, 512)  0           add_4[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D)              (None, 28, 28, 128)  65664       activation_15[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 28, 28, 128)  512         conv2d_18[0][0]
__________________________________________________________________________________________________
activation_16 (Activation)      (None, 28, 28, 128)  0           batch_normalization_18[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 28, 28, 128)  147584      activation_16[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 28, 28, 128)  512         conv2d_19[0][0]
__________________________________________________________________________________________________
activation_17 (Activation)      (None, 28, 28, 128)  0           batch_normalization_19[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D)              (None, 28, 28, 512)  66048       activation_17[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 28, 28, 512)  2048        conv2d_20[0][0]
__________________________________________________________________________________________________
add_5 (Add)                     (None, 28, 28, 512)  0           activation_15[0][0]
                                                                 batch_normalization_20[0][0]
__________________________________________________________________________________________________
activation_18 (Activation)      (None, 28, 28, 512)  0           add_5[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D)              (None, 28, 28, 128)  65664       activation_18[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 28, 28, 128)  512         conv2d_21[0][0]
__________________________________________________________________________________________________
activation_19 (Activation)      (None, 28, 28, 128)  0           batch_normalization_21[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D)              (None, 28, 28, 128)  147584      activation_19[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 28, 28, 128)  512         conv2d_22[0][0]
__________________________________________________________________________________________________
activation_20 (Activation)      (None, 28, 28, 128)  0           batch_normalization_22[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D)              (None, 28, 28, 512)  66048       activation_20[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 28, 28, 512)  2048        conv2d_23[0][0]
__________________________________________________________________________________________________
add_6 (Add)                     (None, 28, 28, 512)  0           activation_18[0][0]
                                                                 batch_normalization_23[0][0]
__________________________________________________________________________________________________
activation_21 (Activation)      (None, 28, 28, 512)  0           add_6[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D)              (None, 14, 14, 256)  131328      activation_21[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 14, 14, 256)  1024        conv2d_25[0][0]
__________________________________________________________________________________________________
activation_22 (Activation)      (None, 14, 14, 256)  0           batch_normalization_25[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D)              (None, 14, 14, 256)  590080      activation_22[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 14, 14, 256)  1024        conv2d_26[0][0]
__________________________________________________________________________________________________
activation_23 (Activation)      (None, 14, 14, 256)  0           batch_normalization_26[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D)              (None, 14, 14, 1024) 525312      activation_21[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D)              (None, 14, 14, 1024) 263168      activation_23[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 14, 14, 1024) 4096        conv2d_24[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 14, 14, 1024) 4096        conv2d_27[0][0]
__________________________________________________________________________________________________
add_7 (Add)                     (None, 14, 14, 1024) 0           batch_normalization_24[0][0]
                                                                 batch_normalization_27[0][0]
__________________________________________________________________________________________________
activation_24 (Activation)      (None, 14, 14, 1024) 0           add_7[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D)              (None, 14, 14, 256)  262400      activation_24[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 14, 14, 256)  1024        conv2d_28[0][0]
__________________________________________________________________________________________________
activation_25 (Activation)      (None, 14, 14, 256)  0           batch_normalization_28[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D)              (None, 14, 14, 256)  590080      activation_25[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 14, 14, 256)  1024        conv2d_29[0][0]
__________________________________________________________________________________________________
activation_26 (Activation)      (None, 14, 14, 256)  0           batch_normalization_29[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D)              (None, 14, 14, 1024) 263168      activation_26[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 14, 14, 1024) 4096        conv2d_30[0][0]
__________________________________________________________________________________________________
add_8 (Add)                     (None, 14, 14, 1024) 0           activation_24[0][0]
                                                                 batch_normalization_30[0][0]
__________________________________________________________________________________________________
activation_27 (Activation)      (None, 14, 14, 1024) 0           add_8[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D)              (None, 14, 14, 256)  262400      activation_27[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 14, 14, 256)  1024        conv2d_31[0][0]
__________________________________________________________________________________________________
activation_28 (Activation)      (None, 14, 14, 256)  0           batch_normalization_31[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D)              (None, 14, 14, 256)  590080      activation_28[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 14, 14, 256)  1024        conv2d_32[0][0]
__________________________________________________________________________________________________
activation_29 (Activation)      (None, 14, 14, 256)  0           batch_normalization_32[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D)              (None, 14, 14, 1024) 263168      activation_29[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 14, 14, 1024) 4096        conv2d_33[0][0]
__________________________________________________________________________________________________
add_9 (Add)                     (None, 14, 14, 1024) 0           activation_27[0][0]
                                                                 batch_normalization_33[0][0]
__________________________________________________________________________________________________
activation_30 (Activation)      (None, 14, 14, 1024) 0           add_9[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D)              (None, 14, 14, 256)  262400      activation_30[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 14, 14, 256)  1024        conv2d_34[0][0]
__________________________________________________________________________________________________
activation_31 (Activation)      (None, 14, 14, 256)  0           batch_normalization_34[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D)              (None, 14, 14, 256)  590080      activation_31[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 14, 14, 256)  1024        conv2d_35[0][0]
__________________________________________________________________________________________________
activation_32 (Activation)      (None, 14, 14, 256)  0           batch_normalization_35[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D)              (None, 14, 14, 1024) 263168      activation_32[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 14, 14, 1024) 4096        conv2d_36[0][0]
__________________________________________________________________________________________________
add_10 (Add)                    (None, 14, 14, 1024) 0           activation_30[0][0]
                                                                 batch_normalization_36[0][0]
__________________________________________________________________________________________________
activation_33 (Activation)      (None, 14, 14, 1024) 0           add_10[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D)              (None, 14, 14, 256)  262400      activation_33[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 14, 14, 256)  1024        conv2d_37[0][0]
__________________________________________________________________________________________________
activation_34 (Activation)      (None, 14, 14, 256)  0           batch_normalization_37[0][0]
__________________________________________________________________________________________________
conv2d_38 (Conv2D)              (None, 14, 14, 256)  590080      activation_34[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 14, 14, 256)  1024        conv2d_38[0][0]
__________________________________________________________________________________________________
activation_35 (Activation)      (None, 14, 14, 256)  0           batch_normalization_38[0][0]
__________________________________________________________________________________________________
conv2d_39 (Conv2D)              (None, 14, 14, 1024) 263168      activation_35[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 14, 14, 1024) 4096        conv2d_39[0][0]
__________________________________________________________________________________________________
add_11 (Add)                    (None, 14, 14, 1024) 0           activation_33[0][0]
                                                                 batch_normalization_39[0][0]
__________________________________________________________________________________________________
activation_36 (Activation)      (None, 14, 14, 1024) 0           add_11[0][0]
__________________________________________________________________________________________________
conv2d_40 (Conv2D)              (None, 14, 14, 256)  262400      activation_36[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 14, 14, 256)  1024        conv2d_40[0][0]
__________________________________________________________________________________________________
activation_37 (Activation)      (None, 14, 14, 256)  0           batch_normalization_40[0][0]
__________________________________________________________________________________________________
conv2d_41 (Conv2D)              (None, 14, 14, 256)  590080      activation_37[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 14, 14, 256)  1024        conv2d_41[0][0]
__________________________________________________________________________________________________
activation_38 (Activation)      (None, 14, 14, 256)  0           batch_normalization_41[0][0]
__________________________________________________________________________________________________
conv2d_42 (Conv2D)              (None, 14, 14, 1024) 263168      activation_38[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 14, 14, 1024) 4096        conv2d_42[0][0]
__________________________________________________________________________________________________
add_12 (Add)                    (None, 14, 14, 1024) 0           activation_36[0][0]
                                                                 batch_normalization_42[0][0]
__________________________________________________________________________________________________
activation_39 (Activation)      (None, 14, 14, 1024) 0           add_12[0][0]
__________________________________________________________________________________________________
conv2d_44 (Conv2D)              (None, 7, 7, 512)    524800      activation_39[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 7, 7, 512)    2048        conv2d_44[0][0]
__________________________________________________________________________________________________
activation_40 (Activation)      (None, 7, 7, 512)    0           batch_normalization_44[0][0]
__________________________________________________________________________________________________
conv2d_45 (Conv2D)              (None, 7, 7, 512)    2359808     activation_40[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 7, 7, 512)    2048        conv2d_45[0][0]
__________________________________________________________________________________________________
activation_41 (Activation)      (None, 7, 7, 512)    0           batch_normalization_45[0][0]
__________________________________________________________________________________________________
conv2d_43 (Conv2D)              (None, 7, 7, 2048)   2099200     activation_39[0][0]
__________________________________________________________________________________________________
conv2d_46 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_41[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 7, 7, 2048)   8192        conv2d_43[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 7, 7, 2048)   8192        conv2d_46[0][0]
__________________________________________________________________________________________________
add_13 (Add)                    (None, 7, 7, 2048)   0           batch_normalization_43[0][0]
                                                                 batch_normalization_46[0][0]
__________________________________________________________________________________________________
activation_42 (Activation)      (None, 7, 7, 2048)   0           add_13[0][0]
__________________________________________________________________________________________________
conv2d_47 (Conv2D)              (None, 7, 7, 512)    1049088     activation_42[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 7, 7, 512)    2048        conv2d_47[0][0]
__________________________________________________________________________________________________
activation_43 (Activation)      (None, 7, 7, 512)    0           batch_normalization_47[0][0]
__________________________________________________________________________________________________
conv2d_48 (Conv2D)              (None, 7, 7, 512)    2359808     activation_43[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 7, 7, 512)    2048        conv2d_48[0][0]
__________________________________________________________________________________________________
activation_44 (Activation)      (None, 7, 7, 512)    0           batch_normalization_48[0][0]
__________________________________________________________________________________________________
conv2d_49 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_44[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 7, 7, 2048)   8192        conv2d_49[0][0]
__________________________________________________________________________________________________
add_14 (Add)                    (None, 7, 7, 2048)   0           activation_42[0][0]
                                                                 batch_normalization_49[0][0]
__________________________________________________________________________________________________
activation_45 (Activation)      (None, 7, 7, 2048)   0           add_14[0][0]
__________________________________________________________________________________________________
conv2d_50 (Conv2D)              (None, 7, 7, 512)    1049088     activation_45[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 7, 7, 512)    2048        conv2d_50[0][0]
__________________________________________________________________________________________________
activation_46 (Activation)      (None, 7, 7, 512)    0           batch_normalization_50[0][0]
__________________________________________________________________________________________________
conv2d_51 (Conv2D)              (None, 7, 7, 512)    2359808     activation_46[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 7, 7, 512)    2048        conv2d_51[0][0]
__________________________________________________________________________________________________
activation_47 (Activation)      (None, 7, 7, 512)    0           batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_52 (Conv2D)              (None, 7, 7, 2048)   1050624     activation_47[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 7, 7, 2048)   8192        conv2d_52[0][0]
__________________________________________________________________________________________________
add_15 (Add)                    (None, 7, 7, 2048)   0           activation_45[0][0]
                                                                 batch_normalization_52[0][0]
__________________________________________________________________________________________________
activation_48 (Activation)      (None, 7, 7, 2048)   0           add_15[0][0]
__________________________________________________________________________________________________
global_average_pooling2d (Globa (None, 2048)         0           activation_48[0][0]
__________________________________________________________________________________________________
dense (Dense)                   (None, 1000)         2049000     global_average_pooling2d[0][0]
==================================================================================================
Total params: 25,636,712
Trainable params: 25,583,592
Non-trainable params: 53,120
__________________________________________________________________________________________________

```

</div></details>

オッケーです! パラメータが公式実装のものと一致してくれました!

## 最後に
モデル構築面白いです。次はUNetかDenseNet辺りでしょうか。
近いうちに記事にできればと思います。

## 書いたコード(最終結果)

```python
import os
import warnings

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
warnings.simplefilter('ignore')

from typing import Union

import tensorflow as tf
from tensorflow.keras.layers import (Activation, Add, BatchNormalization,
                                     Conv2D, Dense, GlobalAveragePooling2D,
                                     Input, MaxPooling2D, ZeroPadding2D)
from tensorflow.keras.models import Model


class ResNet():
    """ResNet Architecture"""
    __LAYER_LOOPS = {
        '18' : [2,2,2,2],
        '34' : [3,4,6,3],
        '50' : [3,4,6,3],
        '101' : [3,4,23,3],
        '152' : [3,8,36,3]
    }

    def __init__(self, input_ch:tuple, output_ch:int, layers:str):
        try:
            self._range = self.__LAYER_LOOPS[layers]
        except KeyError:
            raise ValueError('ResNet layers must be [18, 34, 50, 101, 152].')

        self.input_ch = input_ch
        self.output_ch = output_ch
        self.layers = layers
        self.index = 0

    def conv_bn_act(self,
        x,
        filters:Union[int, tuple, list],
        kernel_size:Union[int, tuple, list],
        strides:Union[int, tuple, list],
        skip_activation=False,
        **kwargs):
        """
        Conv2D + BatchNormalization + Relu
        """

        x = Conv2D(filters=filters, kernel_size=kernel_size, strides=strides, **kwargs)(x)
        x = BatchNormalization()(x)
        if not skip_activation:
            x = Activation('relu')(x)
        return x

    def conv_x(self, x, times, initial_strides=2):
        """conv{n}_x"""
        filters = 64*(2**times)
        for i in range(self._range[self.index]):
            if i==0:
                strides = initial_strides
                y = self.conv_bn_act(x, 4*filters, 1, strides=strides, skip_activation=True)
            else:
                strides = 1
                y = x
            if self.layers == 18 or self.layers == 34:
                x = self.conv_bn_act(x, filters, 3, 2, padding='same')
                x = self.conv_bn_act(x, filters, 3, 1, skip_activation=True, padding='same')
            else:
                x = self.conv_bn_act(x, filters, 1, strides=strides)
                x = self.conv_bn_act(x, filters, 3, 1, padding='same')
                x = self.conv_bn_act(x, 4*filters, 1, 1, skip_activation=True)
            x = Add()([y, x])
            x = Activation('relu')(x)

        self.index += 1
        return x

    def build_resnet(self):
        input = Input(shape=self.input_ch)

        # 7x7 conv, 64, /2
        x = ZeroPadding2D(padding=3)(input)
        x = self.conv_bn_act(x, filters=64, kernel_size=7, strides=(2,2))

        # pool, /2
        x = ZeroPadding2D()(x)
        x = MaxPooling2D(pool_size=(3,3), strides=2)(x)

        # conv2_x
        x = self.conv_x(x, 0, initial_strides=1)

        # conv3_x
        x = self.conv_x(x, 1)

        # conv4_x
        x = self.conv_x(x, 2)

        # conv5_x
        x = self.conv_x(x, 3)

        # average pool, softmax
        x = GlobalAveragePooling2D()(x)
        x = Dense(units = self.output_ch, activation='softmax')(x)

        model = Model(inputs = input, outputs = x)
        return model

        

resnet_50  = ResNet(input_ch = (224, 224, 3), output_ch=1000, layers='50')
model = resnet_50.build_resnet()

model.summary()


```