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.1339  0.6144
#>   0.1153 -1.7746
#> 
#> (1,2,.,.) = 
#>  -1.2917  0.2584
#>   0.1340  0.2300
#> 
#> (1,3,.,.) = 
#>   0.5395  0.4106
#>  -0.0600  1.7110
#> 
#> (1,4,.,.) = 
#>  -0.1674  0.5101
#>   0.0459  0.0494
#> [ CPUFloatType{1,4,2,2} ]
#> torch_tensor
#> (1,1,.,.) = 
#>  -0.1339  0.6144
#>   0.1153 -1.7746
#> 
#> (1,2,.,.) = 
#>   0.5395  0.4106
#>  -0.0600  1.7110
#> 
#> (1,3,.,.) = 
#>  -1.2917  0.2584
#>   0.1340  0.2300
#> 
#> (1,4,.,.) = 
#>  -0.1674  0.5101
#>   0.0459  0.0494
#> [ CPUFloatType{1,4,2,2} ]