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,.,.) = 
#>  -0.8682 -1.6562
#>  -2.1373  1.1568
#> 
#> (1,2,.,.) = 
#>   0.3764 -0.3428
#>  -1.0380 -2.2824
#> 
#> (1,3,.,.) = 
#>   0.7356  0.0035
#>  -1.0773  0.4430
#> 
#> (1,4,.,.) = 
#>   0.3227  1.2577
#>  -0.3418 -1.1024
#> [ CPUFloatType{1,4,2,2} ]
#> torch_tensor
#> (1,1,.,.) = 
#>  -0.8682 -1.6562
#>  -2.1373  1.1568
#> 
#> (1,2,.,.) = 
#>   0.7356  0.0035
#>  -1.0773  0.4430
#> 
#> (1,3,.,.) = 
#>   0.3764 -0.3428
#>  -1.0380 -2.2824
#> 
#> (1,4,.,.) = 
#>   0.3227  1.2577
#>  -0.3418 -1.1024
#> [ CPUFloatType{1,4,2,2} ]