mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Also move the ignores for imports to the bottom in `mypy.ini`, those are much less interesting - start with the stuff people want to work on. Second commit tests the instructions: remove an ignore, fix the issue. Pull Request resolved: https://github.com/pytorch/pytorch/pull/37594 Differential Revision: D21434858 Pulled By: ezyang fbshipit-source-id: 4f1a6868cdb4cb59d072bcf105f48c3a5ba3ff98
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
from .module import Module
|
|
from .. import functional as F
|
|
|
|
|
|
class ChannelShuffle(Module):
|
|
r"""Divide the channels in a tensor of shape :math:`(*, C , H, W)`
|
|
into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`,
|
|
while keeping the original tensor shape.
|
|
|
|
Args:
|
|
groups (int): number of groups to divide channels in.
|
|
|
|
Examples::
|
|
|
|
>>> channel_shuffle = nn.ChannelShuffle(2)
|
|
>>> input = torch.randn(1, 4, 2, 2)
|
|
>>> print(input)
|
|
[[[[1, 2],
|
|
[3, 4]],
|
|
[[5, 6],
|
|
[7, 8]],
|
|
[[9, 10],
|
|
[11, 12]],
|
|
[[13, 14],
|
|
[15, 16]],
|
|
]]
|
|
>>> output = channel_shuffle(input)
|
|
>>> print(output)
|
|
[[[[1, 2],
|
|
[3, 4]],
|
|
[[9, 10],
|
|
[11, 12]],
|
|
[[5, 6],
|
|
[7, 8]],
|
|
[[13, 14],
|
|
[15, 16]],
|
|
]]
|
|
"""
|
|
__constants__ = ['groups']
|
|
|
|
def __init__(self, groups):
|
|
super(ChannelShuffle, self).__init__()
|
|
self.groups = groups
|
|
|
|
def forward(self, input):
|
|
return F.channel_shuffle(input, self.groups)
|
|
|
|
def extra_repr(self):
|
|
return 'groups={}'.format(self.groups)
|