TyranitarX Connect.

针对Cifar-10数据集建立的卷积神经网络

Word count: 183Reading time: 1 min
2019/07/06 Share
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
45
46
47
48
49
50
51
52
53
54
55
56
x = tf.placeholder(tf.float32, [None, 3072])
y = tf.placeholder(tf.int64, [None])

x_image = tf.reshape(x, [-1, 3, 32, 32])
x_image = tf.transpose(x_image, perm=[0, 2, 3, 1])

# conv1 :神经元图, feature_map 输出图像
conv1 = tf.layers.conv2d(
x_image, # input image,
32, # output channel number
(3, 3), # kernel size
padding='same', # padding type
activation=tf.nn.relu,
name='conv1'
)
# polling1 16 * 16
polling1 = tf.layers.max_pooling2d(
conv1, # input image,
(2, 2), # kernel size,
(2, 2), # stride
name='pool1'
)
conv2 = tf.layers.conv2d(
polling1,
32, # output channel number
(3, 3), # kernel size
padding='same', # padding type
activation=tf.nn.relu,
name='conv2'
)
# 8 * 8
polling2 = tf.layers.max_pooling2d(
conv2, # input image,
(2, 2), # kernel size,
(2, 2), # stride
name='pool2'
)
conv3 = tf.layers.conv2d(
polling2,
32, # output channel number
(3, 3), # kernel size
padding='same', # padding type
activation=tf.nn.relu,
name='conv3'
)
# 4 * 4
polling3 = tf.layers.max_pooling2d(
conv3, # input image,
(2, 2), # kernel size,
(2, 2), # stride
name='pool3'
)

# flatten [None , 4 * 4 * 32] 全连接层
flatten = tf.layers.flatten(polling3)
y_ = tf.layers.dense(flatten, 10)
CATALOG