我有定義了這些四層:Tensorflow:轉變手動構建層tf.contrib.layers
layer_1 = tf.add(
tf.matmul(input, tf.Variable(tf.random_normal([n_input, n_hidden_1])),
tf.Variable(tf.random_normal([n_hidden_1]))))
layer_2 = tf.nn.sigmoid(tf.add(
tf.matmul(layer_1, tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),
tf.Variable(tf.random_normal([n_hidden_2]))))
layer_3 = tf.nn.sigmoid(tf.add(
tf.matmul(layer_2, tf.Variable(tf.random_normal([n_hidden_2, n_hidden_1])))),
tf.Variable(tf.random_normal([n_hidden_1]))))
layer_4 = tf.add(
tf.matmul(layer_3, tf.Variable(tf.random_normal([n_hidden_1, n_input]))),
tf.Variable(tf.random_normal([n_input])))
我想這個代碼轉換成基於tf.contrib.layers
代碼。到目前爲止,我通過https://www.tensorflow.org/versions/master/tutorials/layers/和https://www.tensorflow.org/api_docs/python/tf/contrib/layers/fully_connected讀了有
layer_1 = tf.contrib.layers.fully_connected(
inputs=input,
num_outputs=n_hidden_1,
activation_fn=None)
layer_2 = tf.contrib.layers.fully_connected(
inputs=layer_1,
num_outputs=n_hidden_2,
activation_fn=tf.nn.sigmoid)
layer_3 = tf.contrib.layers.fully_connected(
inputs=layer_2,
num_outputs=n_hidden_1,
activation_fn=tf.nn.sigmoid)
layer_4 = tf.contrib.layers.linear(
inputs=layer_3,
num_outputs=n_input)
。我在https://www.tensorflow.org/api_guides/python/contrib.layers#Higher_level_ops_for_building_neural_network_layers中看到tf.contrib.layers.linear
是線性層的替代品。
但是我的輸出與我之前所獲得的輸出相比更加不同,那麼這可能是偶然的。我在配置圖層時做了什麼錯誤?你的代碼和tf.contrib.layers
版本之間