动手深度学习note-4(GoogLeNet)

GoogLeNet

模型结构

Inception块

可能有作用的东西并行训练——大力出奇迹

整体架构

代码实现

1
import tensorflow as tf
PYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Inception
class Inception(tf.keras.Model):
def _init_(self, c1, c2, c3, c4):
super()._init_()
self.p1_1 = tf.keras.layers.Conv2D(c1, kernel_size=1, activation='relu')

self.p2_1 = tf.keras.layers.Conv2D(c2[0], kernel_size=1, activation='relu')
self.p2_2 = tf.keras.layers.Conv2D(c2[1], kernel_size=3, padding='same', activation='relu')

self.p3_1 = tf.keras.layers.Conv2D(c3[0], kernel_size=1, activation='relu')
self.p3_2 = tf.keras.layers.Conv2D(c3[1], kernel_size=5, padding='same', activation='relu')

self.p4_1 = tf.keras.layers.MaxPool2D(3, 1, padding='same')
self.p4_2 = tf.keras.layers.Conv2D(c4, 1, activation='relu')

def call(self, x):
p1 = self.p1_1(x)
p2 = self.p2_2(self.p2_1(x))
p3 = self.p3_2(self.p3_1(x))
p4 = self.p4_2(self.p4_1(x))
return tf.keras.layers.Concatenate()([p1, p2, p3, p4])
PYTHON
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# GoogLeNet
def b1():
return tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, 7, strides=2, padding='same', activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')
])

def b2():
return tf.keras.Sequential([
tf.keras.layers.Conv2D(64, kernel_size=1, activation='relu'),
tf.keras.layers.Conv2D(192, kernel_size=3, padding='same', activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')
])

def b3():
return tf.keras.models.Sequential([
Inception(64, (96, 128), (16, 32), 32),
Inception(128, (128, 192), (32, 96), 64),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')
])

def b4():
return tf.keras.Sequential([
Inception(192, (96, 208), (16, 48), 64),
Inception(160, (112, 224), (24, 64), 64),
Inception(128, (128, 256), (24, 64), 64),
Inception(112, (144, 288), (32, 64), 64),
Inception(256, (160, 320), (32, 128), 128),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')])

def b5():
return tf.keras.layers.Sequential([
Inception(256, (160, 320), (32, 128), 128),
Inception(384, (192, 384), (48, 128), 128),
tf.keras.layers.GlobalAvgPool2D(),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(10)
])

def model():
model = tf.keras.layers.Sequential([
b1(), b2(), b3(), b4(), b5()
])
return model
PYTHON

LeNet && AlexNet

VGG块

NiN

不使用全连接层


动手深度学习note-4(GoogLeNet)
https://blog.potential.icu/2024/02/03/2024-2-3-动手深度学习note-4(GoogLeNet)/
Author
Xt-Zhu
Posted on
February 3, 2024
Licensed under