Skip to contents

Channel_shuffle

Usage

torch_channel_shuffle(self, groups)

Arguments

self

(Tensor) the input tensor

groups

(int) number of groups to divide channels in and rearrange.

Divide the channels in a tensor of shape

math:(*, C , H, W) :

Divide the channels in a tensor of shape \((*, C , H, W)\) into g groups and rearrange them as \((*, C \frac g, g, H, W)\), while keeping the original tensor shape.

Examples

if (torch_is_installed()) {

input <- torch_randn(c(1, 4, 2, 2))
print(input)
output <- torch_channel_shuffle(input, 2)
print(output)
}
#> torch_tensor
#> (1,1,.,.) = 
#>  -1.6767  1.3305
#>   0.6794 -0.2483
#> 
#> (1,2,.,.) = 
#>   1.2727 -0.8747
#>   0.0301  0.7751
#> 
#> (1,3,.,.) = 
#>  -0.7408 -0.6161
#>  -0.0006  1.2580
#> 
#> (1,4,.,.) = 
#>  -0.1315 -0.3347
#>   0.7305  1.8353
#> [ CPUFloatType{1,4,2,2} ]
#> torch_tensor
#> (1,1,.,.) = 
#>  -1.6767  1.3305
#>   0.6794 -0.2483
#> 
#> (1,2,.,.) = 
#>  -0.7408 -0.6161
#>  -0.0006  1.2580
#> 
#> (1,3,.,.) = 
#>   1.2727 -0.8747
#>   0.0301  0.7751
#> 
#> (1,4,.,.) = 
#>  -0.1315 -0.3347
#>   0.7305  1.8353
#> [ CPUFloatType{1,4,2,2} ]