Theano Dimshuffle equivalent in Google's TensorFlow?

dimshuffle theano
theano squeeze
tensorflow transpose
tensorflow swap axes
tensorflow permute
tensorflow transpose op
array_ops transpose
transpose of matrix tensorflow

I have seen that transpose and reshape together can help but I don't know how to use.

Eg. dimshuffle(0, 'x')

What is its equivalent by using transpose and reshape? or is there a better way? Thank you.

dimshuffle in theano, Now i do dimshuffle to A i.e. and make it (2,5,4,1) i.e. make 2nd dimension to 1st dimension, make 4th dim--> 2nd dim, make 1st dim--> 3rd dim  dimshuffle (*pattern). Returns a view of this tensor with permuted dimensions. Typically the pattern will include the integers 0, 1, ndim-1, and any number of ‘x’ characters in dimensions where this tensor should be broadcasted.

I implemented dimshuffle for TensorFlow in our framework Returnn (here). The code is this:

def expand_multiple_dims(x, axes, name="expand_multiple_dims"):
  :param tf.Tensor x:
  :param list[int]|tuple[int] axes: after completion, tf.shape(y)[axis] == 1 for axis in axes
  :param str name: scope name
  :return: y where we have a new broadcast axis for each axis in axes
  :rtype: tf.Tensor
  with tf.name_scope(name):
    for i in sorted(axes):
      x = tf.expand_dims(x, axis=i, name="expand_axis_%i" % i)
    return x

def dimshuffle(x, axes, name="dimshuffle"):
  Like Theanos dimshuffle.
  Combines tf.transpose, tf.expand_dims and tf.squeeze.

  :param tf.Tensor x:
  :param list[int|str]|tuple[int|str] axes:
  :param str name: scope name
  :rtype: tf.Tensor
  with tf.name_scope(name):
    assert all([i == "x" or isinstance(i, int) for i in axes])
    real_axes = [i for i in axes if isinstance(i, int)]
    bc_axes = [i for (i, j) in enumerate(axes) if j == "x"]
    if x.get_shape().ndims is None:
      x_shape = tf.shape(x)
      x = tf.reshape(x, [x_shape[i] for i in range(max(real_axes) + 1)])  # will have static ndims
    assert x.get_shape().ndims is not None

    # First squeeze missing axes.
    i = 0
    while i < x.get_shape().ndims:
      if i not in real_axes:
        x = tf.squeeze(x, axis=i)
        real_axes = [(j if (j < i) else (j - 1)) for j in real_axes]
        i += 1

    # Now permute.
    assert list(sorted(real_axes)) == list(range(x.get_shape().ndims))
    if real_axes != list(range(x.get_shape().ndims)):
      x = tf.transpose(x, real_axes)

    # Now add broadcast dimensions.
    if bc_axes:
      x = expand_multiple_dims(x, bc_axes)
    assert len(axes) == x.get_shape().ndims
    return x

Basic Tensor Functionality, Use reshape or dimshuffle to turn your vector into a row or column matrix. All the above methods are equivalent to NumPy for Theano on the current tensor. I can fix the problem by doing a input.dimshuffle(0,2,3,1) and putting the dimensions as the shape[3] and then do another dimshuffle(0,3,1,2) to bring it back to normal for the next convolution but that doesn't seem like the right solution and inefficient (definitely not what the creators of theano had in mind).

If tensorflow is your backend

from keras import baskend as K
K.permute_dimension should do

Theano+Dimshuffle+equivalent+in+Google+s+TensorFlow+, from theano.tensor.elemwise import Elemwise, DimShuffle​com/p/acyclic. #. # The next equivalent to operating inplace on the variable to. Hi, In tensorflow, a 5D tensor is given to tensorflow.nn.softmax(input, dim=2) function. I would like to do the same with theano, and I am very new. Could you help me to create an equivalent functi

tf.transpose is probably what you are looking for. it takes an arbitrary permutation.

Theano/ at master · Theano/Theano · GitHub, Theano is a Python library that allows you to define, optimize, and efficiently Fix crash about dimshuffle. The infer shape mechanism now force that broadcasted dimensions have a shape know to be equivalent to one during compilation. Pingdom Monitoring Google Object Storage and Download Analytics Sentry  the x is a TensorVariable instance. The T.fmatrix object itself is an instance of TensorType . Theano knows what type of variable x is because x.type points back to T.fmatrix. This chapter explains the various ways of creating tensor variables, the attributes and methods of TensorVariable

Theano · PyPI, Of these, I've only previously had time to learn Theano — one of the more… Once installed, I tested it out using an example script from Google, reproduced below: Here's a rough equivalent in Theano: The dimshuffle calls aren't actually unnecessary, and I picked this up during the port (they'll be removed in a future  How can I find the Tensorflow equivalent of Theano's dimshuffle function. mask = mask.dimshuffle(0, 1, "x") I'm doing this I have tried many ways but couldn't find.

Theano vs Tensorflow, This page provides Python code examples for theano.tensor.arange. prior, chain_potentials: log_sum_exp(prior.dimshuffle(0, 1, 'x') + obs.dimshuffle('x', 'x', 0​) + The numpy equivalent is reference[np.arange(batch_size), indices], https​:// size = 9​  Here’s a rough equivalent in Theano: These two little scripts actually encapsulate a great deal of the difference between the two frameworks. Each starts off with two identically-generated numpy arrays describing the input, and the target output (it’s mathematically z = 0.1 * x + 0.2 * y).

theano.tensor.arange Python Example, The T.fmatrix object itself is an instance of TensorType . Theano knows what type of variable x is because x.type points back to T.fmatrix. This chapter explains the various ways of creating tensor variables, the attributes and methods of TensorVariable and TensorType , and various basic symbolic math and arithmetic