TensorFlow - Separation and Compression

I am new to TensorFlow and I am formatting some data to feed into a repeating neural network. My data is given by a three-dimensional tensor filed in the placeholder x. I want to divide xby the 3rd dimension, and for this I have (note that it n_timestepscorresponds to the length xalong the 3rd dimension):

# Split the previous 3d tensor to get a list of 'n_timesteps' 2d tensors of
# shape (batch_size, features_dimension)
x = tf.split (x, n_timesteps, axis = 2)

Although, as I tried with numpy:

x = np.split (x, n_timesteps, axis = 2)

If it xis 3d ndarray, it np.splitwill return a list of arrays n_timestepswith size 3, so the 3-dimensional dimension is single-point. C numpyI know that I can easily solve this, using, np.squeezetogether with the list, to remove the size of a singleton:

x = [np.squeeze(a, axis=2) for a in np.split(x, n_timesteps, axis=2)]

But how can I do the same on TF?

+4
2

Tensorflow (tf.squeeze) Tensorflow (tf.scan) .

tf.scan(lambda a, x_i: tf.squeeze(x_i, [2]), x, initializer=tf.constant(0, shape=[n_dim0, n_dim1]))
0

, tf.unstack op:

x = tf.unstack(x, axis=2)
+2

Source: https://habr.com/ru/post/1671075/


All Articles