- ジュリア0.6.0
- TensorFlow.jl 0.7.5
- tensorflow(パイソン)1.4.1
- OS:Ubuntuの16.04
私は時系列予測のためのLSTMを設定する。私は最後のタイムステップだけでなく、損失を計算したいので、すべてのタイムステップの出力が必要です。 documentation of tensorflow (Python API)によれば、dynamic_rnn
の出力は、形状[batch_size, max_time, cell.output_size]
(time_major == False
の場合)でなければなりません。 PythonでTensorFlow.jl出力形状
、これは正常に動作します:
import tensorflow as tf
import numpy as np
batch_size = 3
series_length = 10
hidden_size = 7
number_of_features = 2
session = tf.Session()
x = tf.placeholder(tf.float32, [None, series_length, number_of_features])
cell = tf.contrib.rnn.BasicLSTMCell(hidden_size)
outputs, state = tf.nn.dynamic_rnn(cell, x, dtype=tf.float32)
session.run(tf.global_variables_initializer())
o = session.run(outputs, feed_dict={x: np.random.randn(batch_size, series_length, number_of_features)})
outputs
は[batch_size, series_length, hidden_size]
と一致する形状[3, 10, 7]
を、持っています。
ここで、密なレイヤーを使用して、各タイムステップで単一の値yを出力できます。
outputs
はに対応する形状[3, 7]
を持っています。これは最後のタイムステップにすぎないようです。
using TensorFlow
tf = TensorFlow
batch_size = 3
series_length = 10
number_of_features = 2
hidden_size = 7
session = tf.Session()
x = tf.placeholder(Float32, shape=[-1, series_length, number_of_features])
cell = tf.nn.rnn_cell.LSTMCell(hidden_size)
outputs, state = tf.nn.dynamic_rnn(cell, x)
run(session, global_variables_initializer())
o = run(session, [outputs], Dict(x=>rand(Float32, batch_size, series_length, number_of_features)))
これは意図的に、バグなのか、ポイントがないのか誰かが理解していますか?