ValueError:两个结构没有相同数量的元素

编程入门 行业动态 更新时间:2024-10-09 07:18:16
本文介绍了ValueError:两个结构没有相同数量的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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)

这是我输入100x196x50尺寸的GRU的代码,应沿第二个尺寸(即196)解压缩. hidden_state_size是50,batch_size是100.但是我得到以下错误:

This is my code for a GRU for input of dimension 100x196x50, it should be unpacked along the second dimension (that is 196). hidden_state_size is 50, batch_size is 100. However I get the following error:

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>).

有什么线索可以解决这个问题吗?

Any clue how to resolve this?

推荐答案

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

Hello I had the same problem, I tried to do this:

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

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

This gave me a similar error message:

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>)

我通过使dtypes显式解决了这个问题:

I resolved this by making the dtypes explicit:

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

更多推荐

ValueError:两个结构没有相同数量的元素

本文发布于:2023-11-29 04:21:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   数量   两个   结构   ValueError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!