注意
您正在阅读 MMEditing 0.x。 MMEditing 0.x 会在 2022 年末开始逐步停止维护,建议您及时升级到 MMEditing 1.0 版本,享受由 OpenMMLab 2.0 带来的更多新特性和更佳的性能表现。阅读 MMEditing 1.0 的发版日志、 代码 和 文档 以了解更多。
mmedit.models.common.downsample 源代码
# Copyright (c) OpenMMLab. All rights reserved.
[文档]def pixel_unshuffle(x, scale):
"""Down-sample by pixel unshuffle.
Args:
x (Tensor): Input tensor.
scale (int): Scale factor.
Returns:
Tensor: Output tensor.
"""
b, c, h, w = x.shape
if h % scale != 0 or w % scale != 0:
raise AssertionError(
f'Invalid scale ({scale}) of pixel unshuffle for tensor '
f'with shape: {x.shape}')
h = h // scale
w = w // scale
x = x.view(b, c, h, scale, w, scale)
x = x.permute(0, 1, 3, 5, 2, 4)
return x.reshape(b, -1, h, w)