Get symbol shape when using reshape function


#1

I have a y : (batch , c, h*w), and x: (batch, c, h, w)

h and w is not determined. Before I use net.hybridize(), I can use y.reshape(0, 0, *x.shape[2:]), however, after the hybridize, the symbol don’t have the shape attribute, so how to achieve the same purpose?


#2

you can now use the .reshape_like operator on only some dimensions of a tensor.
e.g.

import mxnet as mx
batch = 5
c = 3
h = 32
w = 32

y = mx.nd.ones((batch , c, h*w))
x = mx.nd.ones((batch, c, h, w))

print("x:{}, y:{}".format(x.shape, y.shape))
y = mx.nd.reshape_like(y, x, lhs_begin=2, rhs_begin=2)
print("x:{}, y:{}".format(x.shape, y.shape))
x:(5, 3, 32, 32), y:(5, 3, 1024)
x:(5, 3, 32, 32), y:(5, 3, 32, 32)