1
votes

I have a tensor of shape (3, None, 80, 10) and I want to reshape it to (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):

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.

1
Are you looking on the model.summary() ? Try to call model with actual data - Andrey
3*None doesn't mean anything. Why would you want that? Do you mean (3,80,10)? - Lawhatre
I am newbie to Tensorflow and I am looking for using LSTM on the above tensor through the following lines of code lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(embedding_u_size) # init_state = cell.zero_state(None, dtype=tf.float32) node_type_embed, _ = tf.nn.dynamic_rnn(lstm_cell, Y, time_major= True, dtype=tf.float32) and I think that I cannot use model.summary() in this case It is not a keras layers. - Amina Amara
@Ragnar The 3 dimension means a some category of data and None dimension means the batch_size of each category - Amina Amara
I think what you want is (None, 80, 10, 3) - Lawhatre

1 Answers

0
votes

It is challenging to reshape the Variable dimension tensor, you can use keras.Input library

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