我正在尝试实现类似于ShuffleNet函数channel_shuffle的功能,请参见Keras中的ShuffleNet。该函数如下所示:
def channel_shuffle(x, groups):
"""
Parameters
----------
x:
Input tensor of with `channels_last` data format
groups: int
number of groups per channel
Returns
-------
channel shuffled output tensor
Examples
--------
Example for a 1D Array with 3 groups
>>> d = np.array([0,1,2,3,4,5,6,7,8])
>>> x = np.reshape(d, (3,3))
>>> x = np.transpose(x, [1,0])
>>> x = np.reshape(x, (9,))
'[0 1 2 3 4 5 6 7 8] --> [0 3 6 1 4 7 2 5 8]'
"""
height, width, in_channels = x.shape.as_list()[1:]
channels_per_group = in_channels // groups
x = K.reshape(x, [-1, height, width, groups, channels_per_group])
x = K.permute_dimensions(x, (0, 1, 2, 4, 3)) # transpose
x = K.reshape(x, [-1, height, width, in_channels])
return x
这在已知网络的输入形状(例如(256、256、3))时有效。但是,如果我尝试将其更改为(None,None,3)以启用不同大小的图像,则它会崩溃。这是因为由于高度和宽度均为“无”,所以无法重塑x的形状。我的问题是,是否可以更改此功能以启用此功能,如果可以,如何?