[英]How to reshape a tensor with None dimension tensorflow
I have a tensor of shape (3, None, 80, 10)
and I want to reshape it to (3*None, 80, 10)
.我有一个形状
(3, None, 80, 10)
的张量,我想将它重塑为(3*None, 80, 10)
。 I tried with the following lines of code but didn't get the desired shape (3*None, 80, 10)
, I got a tensor of shape (None, None, None)
:我尝试了以下代码行,但没有得到所需的形状
(3*None, 80, 10)
,我得到了形状张量(None, None, None)
:
shape = [tf.shape(node_embed_tmp)[k] for k in range(4)]
Y = tf.reshape(node_embed_tmp, [shape[0]*shape[1], shape[2], shape[3]])
Any suggestions, Please!任何建议,请!
EDIT:编辑:
I also tried the following code:我还尝试了以下代码:
shape = [tf.shape(node_embed_tmp)[k] for k in range(4)]
Y=tf.reshape(node_embed_tmp, [-1, shape[2], shape[3]])
But I got the shape (None, None, None)
and the following error: ValueError: Input size (depth of inputs) must be accessible via shape inference, but saw value None.
但是我得到了形状
(None, None, None)
和以下错误: ValueError: Input size (depth of inputs) must be accessible via shape inference, but saw value None.
It is challenging to reshape the Variable dimension tensor, you can use keras.Input library重塑可变维张量具有挑战性,您可以使用 keras.Input 库
from tensorflow import keras
tensor_shape = (3, None, 80, 10)
input = keras.Input(shape=((None,) + tensor_shape[1:]), dtype = 'int32')
input.shape
Output输出
TensorShape([None, None, None, 80, 10])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.