使用keras实现Inception结构

Inception结构

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import keras
from keras.layers import Input, Conv2D, MaxPooling2D
from keras.models import Model

# 定义输入图像尺寸
inputs = Input(shape=(256, 256, 3))

# 定义第一个分支
tower_1 = Conv2D(64, (1, 1), padding='same', activation='relu')(inputs)

# 定义第二个分支
tower_2 = Conv2D(64, (1, 1), padding='same', activation='relu')(inputs)
tower_2 = Conv2D(64, (3, 3), padding='same', activation='relu')(tower_2)

# 定义第三个分支
tower_3 = Conv2D(64, (1, 1), padding='same', activation='relu')(inputs)
tower_3 = Conv2D(64, (5, 5), padding='same', activation='relu')(tower_3)

# 定义第四个分支
tower_4 = MaxPooling2D((3, 3), strides=(1, 1), padding='same')(inputs)
tower_4 = Conv2D(64, (1, 1), padding='same', activation='relu')(tower_4)

output = keras.layers.concatenate([tower_1, tower_2, tower_3, tower_4], axis=1)

model = Model(inputs=inputs, outputs=output)

model.compile(...)
model.fit(...)