以下のような全結合ネットワークに正則化を導入する場合、どのように書く事が正しいのでしょうか?
regularizer = tf.contrib.layers.l2_regularizer(scale=0.1)
init = tf.constant_initializer(value= 1 )
nn1 = tf.layers.dense(inputs=x, units=unit_size, activation=tf.nn.relu , kernel_initializer=init,kernel_regularizer=regularizer )
などや、lossに tf.losses.get_regularization_loss()を加えるなどしても、学習が全く進まなくなります。(stepを進めてもネットワークの出力が全く変わらなくなりました)
このコードのままだと一応学習は進みます。
python3
1 x = tf.placeholder(shape=[None, 10], dtype=tf.float32, name='x') 2 unit_size = 100 3 classes= 5 4 5 nn1 = tf.layers.dense(inputs=x, units=unit_size , activation=tf.nn.relu) 6 nn2 = tf.layers.dense(inputs=nn1, units=unit_size , activation=tf.nn.relu) 7 nn3 = tf.layers.dense(inputs=nn2, units=classes, activation=tf.nn.relu) 8 9 y = tf.nn.softmax(nn3 ) 10 11 y_ = tf.placeholder(tf.float32, [None, classes ], name='y_') 12 cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y)) 13 train_step = tf.train.AdamOptimizer(learning_rate= 0.001 ).minimize(cross_entropy) 14 15 with tf.Session() as sess: 16 epoch = 1000 17 sess.run(tf.initialize_all_variables()) 18 for c in range(epoch): 19 sess.run( train_step , feed_dict={x: np.array( training.data ) , y_: np.array( training.label ).astype( np.int ) }) 20 21
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/26 01:38
2018/11/26 01:52
2018/11/26 02:29
2018/11/27 01:07