I use convolution instead of the shuffle operation in net
class ShuffleChannel(HybridBlock):
def __init__(self, groups):
super(ShuffleChannel, self).__init__()
self.groups = groups
def hybrid_forward(self, F, x):
# shuffleOp
# x.reshape((0, -4, self.groups, -1, -2)).swapaxes(1, 2).reshape((0, -3, -2))
# return x
# MineOp
N, C, H, W = x.shape
channels_per_group = C // self.groups
conv_kernel = nd.zeros((C, C, 1, 1))
for k in range(C):
index = (k % self.groups) * channels_per_group + k // self.groups
conv_kernel[k, index, 0, 0] = 1
return nd.Convolution(x, conv_kernel, no_bias=True, kernel=(1,1), num_filter=C)
In training process, it works well and I want to convert the model to symbol format.But I got Errors:
......
File "E:\AntiSpoofing\shuffleNetv2-mxnet\shufflenetv2.py", line 27, in hybrid_forward
N, C, H, W = x.shape
AttributeError: 'Symbol' object has no attribute 'shape'
Could I specify the input 'x' to be in ndarray format or change the func code?