Xception 実装

#構造
<b>Entry flow 　→ 　Middle flow　×8　→　Exit flow

#Entry flow

![image.png](https://qiita-image-store.s3.amazonaws.com/0/315063/ce3afcf1-c2cc-3b1e-53ec-ad4b426ff2cd.png)



```python
def Xception():
        inputs = Input(shape=(32, 32, 3))
    
        # entry flow
       
        x = Convolution2D(32, (3,3), strides=2)(inputs)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = Convolution2D(64, (3,3))(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
       
        residual = Convolution2D(128, (1,1), strides=2, padding='same')(x)
        residual = BatchNormalization()(residual)
        
        x = SeparableConv2D(128, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = SeparableConv2D(128, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = MaxPooling2D((3, 3), strides=2, padding='same')(x)
        x = add([x, residual])
        
        residual = Convolution2D(256, (1,1), strides=2, padding='same')(x)
        residual = BatchNormalization()(residual)
        
        x = Activation('relu')(x)
        x = SeparableConv2D(256, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = SeparableConv2D(256, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = MaxPooling2D((3, 3), strides=2, padding='same')(x)
        x = add([x, residual])
        
        residual = Convolution2D(728, (1,1), strides=2, padding='same')(x)
        residual = BatchNormalization()(residual)
        
        x = Activation('relu')(x)
        x = SeparableConv2D(728, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = SeparableConv2D(728, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = MaxPooling2D((3, 3), strides=2, padding='same')(x)
        x = add([x, residual])
    
```

# Middle flow

![image.png](https://qiita-image-store.s3.amazonaws.com/0/315063/ad822233-68f2-3c47-5dfc-9a9886fe6c46.png)

```python
# middle flow
        
        for i in range(8):
            residual = x
        
            x = Activation('relu')(x)
            x = SeparableConv2D(728, (3,3), padding='same')(x)
            x = BatchNormalization()(x)
            x = Activation('relu')(x)
            x = SeparableConv2D(728, (3,3), padding='same')(x)
            x = BatchNormalization()(x)
            x = Activation('relu')(x)
            x = SeparableConv2D(728, (3,3), padding='same')(x)
            x = BatchNormalization()(x)
            x = add([x, residual])
          
```

# Exit flow

![image.png](https://qiita-image-store.s3.amazonaws.com/0/315063/4e415ef1-b3af-3cad-7209-0683b5267322.png)

```python
  # exit flow
        
        residual = Convolution2D(1024, (1,1), strides=2, padding='same')(x)
        residual = BatchNormalization()(residual)
        
        x = Activation('relu')(x)
        x = SeparableConv2D(728, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = SeparableConv2D(1024, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = MaxPooling2D((3, 3), strides=2, padding='same')(x)
        
        x = add([x, residual])
        
        x = SeparableConv2D(1536, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        x = SeparableConv2D(2048, (3,3), padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)
        
        x = GlobalAveragePooling2D()(x)
        x = Dense(10, kernel_initializer='he_normal', activation='softmax')(x)
  
        model = Model(inputs=inputs, outputs=x)
        return model

```

#学習まで
```python
model = Xception()
adam = Adam()
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['accuracy'])
model.summary() 
```

```python
batch_size = 50
epochs = 10

h = model.fit(X_train, Y_train,
              batch_size=batch_size,
              epochs=epochs,
              validation_split=0.2,)
```