teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コメント追記。

2019/09/01 09:54

投稿

open_your_eyes
open_your_eyes

スコア4

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

#つきのコメントを削除

2019/09/01 09:54

投稿

open_your_eyes
open_your_eyes

スコア4

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
- # residualのチャンネル数を取得
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) # 32x32x32 -> 16x16x32
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) # 16x16x64 -> 8x8x64
42
+ h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
48
- h = _resblock(n_filters=128)(h) # 8x8x64 -> 8x8x128
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) # 8x8x128 -> 4x4x128
47
+ h = tf.layers.MaxPooling2D(pool_size=[2, 2], strides=2)(h)
48
+
52
- h = _resblock(n_filters=256)(h) # 4x4x128 -> 4x4x256
49
+ h = _resblock(n_filters=256)(h)
53
50
  h = _resblock(n_filters=256)(h)
54
51
  h = _resblock(n_filters=256)(h)
55
- # Global Average Pooling
52
+
56
- h = tf.keras.layers.GlobalAveragePooling2D()(h) # 4x4x256 -> 256
53
+ h = tf.keras.layers.GlobalAveragePooling2D()(h)
57
- # FCN(全結合ネットワーク)
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
- # optimizer = tf.train.AdamOptimizer(0.01).minimize(cost)
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
  どうぞよろしくお願いいたします。