gpt4 book ai didi

tensorflow - tf.nn.dynamic_rnn 中的排名错误

转载 作者:行者123 更新时间:2023-12-03 00:39:38 25 4
gpt4 key购买 nike

我正在尝试构建 CNN + RNN 模型,但收到以下错误。任何帮助将不胜感激。

fc2 has shape (?,4096)

cell = tf.contrib.rnn.BasicLSTMCell(self.rnn_hidden_units)
stack = tf.contrib.rnn.MultiRNNCell([cell]*self.rnn_layers)
initial_state = cell.zero_state(self.batch_size, tf.float32)
initial_state = tf.identity(initial_state, name='initial_state')
outputs, _ = tf.nn.dynamic_rnn(stack, fc2,dtype=tf.float32)

File "rcnn.py", line 182, in model outputs, _ = tf.nn.dynamic_rnn(stack, [fc2],dtype=tf.float32)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 574, in dynamic_rnn dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 637, in _dynamic_rnn_loop for input_ in flat_input)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 637, in for input_ in flat_input)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 649, in with_rank_at_least raise ValueError("Shape %s must have rank at least %d" % (self, rank)) ValueError: Shape (4096, ?) must have rank at least 3

最佳答案

从@jdehesa的评论中复制他的答案以获得更好的可见性:

错误似乎相当清楚,tf.nn.dynamic_rnn期望 3 维张量作为输入(即等级 3),但 fc2 只有二维。形状fc2应该是类似 (<batch_size>, <max_time>, <num_features>) (或 (<max_time>, <batch_size>, <num_features>) 如果您通过 time_major=True )

关于tensorflow - tf.nn.dynamic_rnn 中的排名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44673865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com