尝试使用tensorflow创建展开的RNN模型,并看到我不理解的错误消息。最后,尝试使用多步前瞻进行简单的时间序列预测,其中输入向量是一组回望窗口样本(每个10步长,每个特征1个),响应集样本是每个10步回望窗口序列的下一(5)个步骤。
在这里,您可以看到数据集的尺寸和预期的RNN细胞神经元
n_samples = int( data_x.get_shape()[0] )
n_input_steps = int( data__x.get_shape()[1] )
n_inputs = int( tx.get_shape()[2] )
n_neurons = 7 # small for demo purposes
n_output_steps = int( data_y.get_shape()[1] )
n_outputs = int( data_y.get_shape()[2] )
print (n_samples, n_input_steps, n_inputs, n_neurons, n_output_steps, n_outputs)
#output
(97, 10, 1, 7, 5, 1)
以及展开的模型代码
# params section
X = tf.placeholder(tf.float64, [None, n_input_steps, n_inputs])
print X.get_shape()
y = tf.placeholder(tf.float64, [None, n_output_steps, n_outputs])
print y.get_shape()
cell = tf.nn.rnn_cell.LSTMCell(name='basic_lstm_cell', num_units=n_neurons, activation=tf.nn.relu, use_peepholes=True)
# wrap in fully connect single output projection
fc_cell = tf.contrib.rnn.OutputProjectionWrapper(cell, output_size=n_outputs, reuse=tf.AUTO_REUSE)
outputs, states = tf.nn.dynamic_rnn(cell=fc_cell, inputs=X, dtype=tf.float64)
"""
expecting unrolled RNN:
y[0] .... y[n_input_steps]
| |
* -> ... -> *
| .... |
x[0] x[n_input_steps]
where each * is an RNN cell with a single output
"""
尝试设置此RNN时引发的完整错误消息如下所示
(?, 10, 1)
(?, 5, 1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-204-d52a40d9a302> in <module>()
10 fc_cell = tf.contrib.rnn.OutputProjectionWrapper(cell, output_size=n_outputs, reuse=tf.AUTO_REUSE)
11
---> 12 outputs, states = tf.nn.dynamic_rnn(cell=fc_cell, inputs=X, dtype=tf.float64)
13
....
....
....
/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.pyc in _get_single_variable(self, name, shape, dtype, initializer, regularizer, partition_info, reuse, trainable, collections, caching_device, validate_shape, use_resource, constraint, synchronization, aggregation)
864 raise ValueError("Trying to share variable %s, but specified shape %s"
865 " and found shape %s." % (name, shape,
--> 866 found_var.get_shape()))
867 if not dtype.is_compatible_with(found_var.dtype):
868 dtype_str = dtype.name
ValueError: Trying to share variable rnn/output_projection_wrapper/basic_lstm_cell/kernel, but specified shape (8, 28) and found shape (4, 12).
如有任何调试建议或修复,将不胜感激。