質問編集履歴
2
コメント追記。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
(少数点4桁くらい表示していますが、まったく変化せず)。
|
8
8
|
計算グラフがうまくできておらず、誤差逆伝播ができていないのかと推察しています。
|
9
9
|
|
10
|
+
以下、インデントが上手くされておらず、読みにくいコードになっておりすみません。
|
11
|
+
|
10
12
|
def _shortcut(inputs, residual)
|
11
13
|
n_filters = residual.shape[3]
|
12
14
|
print('n_filters=',n_filters)
|
1
#つきのコメントを削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,12 +7,9 @@
|
|
7
7
|
(少数点4桁くらい表示していますが、まったく変化せず)。
|
8
8
|
計算グラフがうまくできておらず、誤差逆伝播ができていないのかと推察しています。
|
9
9
|
|
10
|
-
# ResNet
|
11
|
-
def _shortcut(inputs, residual): #inputs: ResBlockへの入力そのもの(ショートカットしたデータ), residual: ResBlockの中で処理されたデータ
|
12
|
-
|
10
|
+
def _shortcut(inputs, residual)
|
13
11
|
n_filters = residual.shape[3]
|
14
12
|
print('n_filters=',n_filters)
|
15
|
-
# inputsのチャンネル数をresidualのチャンネル数に合わせる(1x1畳み込み)
|
16
13
|
shortcut = tf.layers.Conv2D(n_filters, kernel_size=[1, 1], strides=[1, 1], padding='VALID')(inputs)
|
17
14
|
return tf.keras.layers.add([shortcut, residual])
|
18
15
|
|
@@ -28,42 +25,41 @@
|
|
28
25
|
return _shortcut(input, x)
|
29
26
|
return f
|
30
27
|
|
31
|
-
### ネットワーク ###
|
32
28
|
tf.reset_default_graph()
|
33
29
|
is_training = tf.placeholder(tf.bool, shape=())
|
34
30
|
|
35
31
|
x = tf.placeholder(tf.float32, [None, 32, 32, 3]) #入力データ
|
36
32
|
t = tf.placeholder(tf.float32, [None, 10]) #正解ラベル
|
37
33
|
|
38
|
-
### ネットワーク本体 ###
|
39
34
|
h = tf.layers.Conv2D(filters=32, kernel_size=[7, 7], strides=[1, 1], kernel_initializer=initializer, padding='SAME')(x)
|
40
35
|
h = tf.layers.BatchNormalization()(h, training=is_training)
|
41
36
|
h = tf.nn.relu(h)
|
42
|
-
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
37
|
+
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
43
38
|
|
44
|
-
h = _resblock(n_filters=64)(h) # 16x16x32 -> 16x16x64
|
45
39
|
h = _resblock(n_filters=64)(h)
|
46
40
|
h = _resblock(n_filters=64)(h)
|
41
|
+
h = _resblock(n_filters=64)(h)
|
47
|
-
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
42
|
+
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
48
|
-
|
43
|
+
|
49
44
|
h = _resblock(n_filters=128)(h)
|
50
45
|
h = _resblock(n_filters=128)(h)
|
46
|
+
h = _resblock(n_filters=128)(h)
|
51
|
-
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
47
|
+
h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
|
48
|
+
|
52
|
-
h = _resblock(n_filters=256)(h)
|
49
|
+
h = _resblock(n_filters=256)(h)
|
53
50
|
h = _resblock(n_filters=256)(h)
|
54
51
|
h = _resblock(n_filters=256)(h)
|
55
|
-
|
52
|
+
|
56
|
-
h = tf.keras.layers.GlobalAveragePooling2D()(h)
|
53
|
+
h = tf.keras.layers.GlobalAveragePooling2D()(h)
|
57
|
-
|
54
|
+
|
58
55
|
h = tf.layers.Dense(units=128, activation=tf.nn.relu)(h)
|
59
|
-
y = tf.layers.Dense(units=10, activation=tf.nn.softmax)(h)
|
56
|
+
y = tf.layers.Dense(units=10, activation=tf.nn.softmax)(h)
|
60
57
|
|
61
58
|
cost = - tf.reduce_mean(tf.reduce_sum(t * tf_log(y), axis=1))
|
62
59
|
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
|
63
60
|
|
64
61
|
with tf.control_dependencies(update_ops):
|
65
|
-
|
62
|
+
optimizer = tf.train.AdamOptimizer(0.01).minimize(cost)
|
66
|
-
optimizer = tf.train.GradientDecentOptimizer(0.01).minimize(cost)
|
67
63
|
|
68
64
|
Tensorflow自体に不慣れであり、基本的なミスなのかもしれませんが、
|
69
65
|
どうぞよろしくお願いいたします。
|