OS: Kubuntu 14.04, Tensorflow version = 0.12, Python version = 2.7
After my last layer the output of my neural net has the shape[batch, height, width, 2]
which is [64, 32, 256, 2]
in my case.
After that I use
output = tf.contrib.layers.flatten(input=output)
which produces a Tensor with the shape[64, 16384]
For evaluation purposes I would like to reverse this flattening in a different function to get the original [64, 32, 256, 2]
Tensor back.
How would one do that?
To flatten the tensor, we're going to use the TensorFlow reshape operation. So tf. reshape, we pass in our tensor currently represented by tf_initial_tensor_constant, and then the shape that we're going to give it is a -1 inside of a Python list.
flip(tensor_a) will reverse all tensor, and torch. flip(tensor_a, dims=(1,)) will reverse every row, like [1, 2, 3] --> [3, 2, 1] .
A tensor can be flattened into a one-dimensional tensor by reshaping it using the method torch. flatten(). This method supports both real and complex-valued input tensors. It takes a torch tensor as its input and returns a torch tensor flattened into one dimension.
Simply reshape
to the shape you want: tf.reshape(output, [-1, 32, 256, 2])
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With