gpt4 book ai didi

tensorflow - 值错误: The two structures don't have the same number of elements

转载 作者:行者123 更新时间:2023-12-02 22:27:34 26 4
gpt4 key购买 nike

with tf.variable_scope('forward'):
cell_img_fwd = tf.nn.rnn_cell.GRUCell(hidden_state_size, hidden_state_size)
img_init_state_fwd = rnn_img_mapped[:, 0, :]
img_init_state_fwd = tf.multiply(
img_init_state_fwd,
tf.zeros([batch_size, hidden_state_size]))
rnn_outputs2, final_state2 = tf.nn.dynamic_rnn(
cell_img_fwd,
rnn_img_mapped,
initial_state=img_init_state_fwd,
dtype=tf.float32)

这是我的 GRU 代码,用于输入维度 100x196x50,它应该沿着第二个维度(即 196)解包。 hidden_​​state_size 是 50,batch_size 是 100。但是我收到以下错误:

ValueError: The two structures don't have the same number of elements.
First structure: Tensor("backward/Tile:0", shape=(100, 50), dtype=float32),
second structure:
(<tf.Tensor 'backward/bwd_states/while/GRUCell/add:0' shape=(100, 50) dtype=float32>,
<tf.Tensor 'backward/bwd_states/while/GRUCell/add:0' shape=(100, 50) dtype=float32>).

知道如何解决这个问题吗?

最佳答案

您好,我遇到了同样的问题,我尝试这样做:

highest = tf.map_fn(lambda x : (-x, x), indices)

这给了我类似的错误消息:

ValueError: The two structures don't have the same number of elements.

First structure (1 elements): <dtype: 'int32'>

Second structure (2 elements): (<tf.Tensor 'map/while/Neg:0' shape=() dtype=int32>, <tf.Tensor 'map/while/TensorArrayReadV3:0' shape=() dtype=int32>)

我通过明确数据类型解决了这个问题:

highest = tf.map_fn(lambda x : (-x, x), indices, dtype=(tf.int32, tf.int32))

关于tensorflow - 值错误: The two structures don't have the same number of elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42776980/

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