0
我有這個簡單的兩層前饋網絡將分類MNIST數字。有了這個網絡,我可以得到滿意的精度,但我想稍微修改它。在Shrivastava et al.之後,我希望在沒有橫向模塊的情況下采用自上而下的調製(請參閱第3頁)。另外,我想將它限制在這兩層,所以不要創建更深的網絡。基本上,在新網絡中,與下面的簡單前饋網絡相反,第二層再次連接到第一層以實現這種自頂向下的反饋鏈路。自頂向下調製雙層網絡
我不知道該如何去做,經過大量的在線挖掘之後,我還沒有發現任何其他關於如何在TensorFlow(或任何其他庫)中執行此操作的源代碼/示例。任何幫助或正確的方向推動非常感謝!
# PREVENTS VANISHING GRADIENT PROBLEM
stddev1=np.sqrt(2/float(784))
# second = 10 units
stddev2=np.sqrt(2/float(10))
w1 = tf.get_variable('w1',[784,10],
initializer=tf.random_normal_initializer(mean=0, stddev=stddev1))
b1 = tf.get_variable('b1',[10,],
initializer=tf.constant_initializer(0.0))
# relu has vanishing gradient problem
z1 = tf.matmul(x, w1) + b1
y1 = tf.nn.relu(z1) #
# layer 2
w2 = tf.get_variable('w2',[10,10],
initializer= tf.random_normal_initializer(mean=0,stddev=stddev2))
b2 = tf.get_variable('b2',[10,],
initializer=tf.constant_initializer(0.0))
y = tf.nn.softmax(tf.matmul(y1, w2) + b2, name="output")
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
好的,這是有道理的。這可能是在稍後階段。我想要完成的是將z2添加到x(輸入圖像),並且z1是從x和z2的和中計算出來的。我應該使用RNN細胞/ LSTM細胞嗎?然後會像這樣的工作(這是單層的權利?):[鏈接](https://pythonprogramming.net/rnn-tensorflow-python-machine-learning-tutorial/) – coderjoe
如果你想這樣做:(layer1 = x + z1,layer2 = x + layer1),因此不需要RNN,並且您共享的鏈接使用多個圖層。 –