Dzung Nguyen
Dzung Nguyen

Reputation: 3944

Tensorflow reshape with variable length

I'm using the following reshape in my model:

data = tf.placeholder(tf.float32, shape = (BATCH_SIZE, N_CHUNK, WIN * N_SENSOR))

data_flattened = tf.reshape(data, [BATCH_SIZE*N_CHUNK, WIN*N_SENSOR])

Now I want N_CHUNK to be variable (i.e. NONE in the dimension). How do I implement the reshape? Does the None dimension must be the first dimension?

Upvotes: 0

Views: 1844

Answers (1)

Allen Lavoie
Allen Lavoie

Reputation: 5808

You can use tf.shape to get a shape as an integer Tensor.

So in your example:

data = tf.placeholder(tf.float32, shape = (BATCH_SIZE, None, WIN * N_SENSOR))

data_flattened = tf.reshape(data, [BATCH_SIZE*tf.shape(data)[1], WIN*N_SENSOR])

Upvotes: 2

Related Questions