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.6140  2.1915
#>  -1.1439 -0.6537
#> 
#> (1,2,.,.) = 
#>   1.1468 -0.6219
#>   0.6974  0.8079
#> 
#> (1,3,.,.) = 
#>  -1.7238 -0.3450
#>   0.2372 -0.6565
#> 
#> (1,4,.,.) = 
#>   1.1268 -0.0199
#>  -0.6402  1.3421
#> [ CPUFloatType{1,4,2,2} ]
#> torch_tensor
#> (1,1,.,.) = 
#>   0.6140  2.1915
#>  -1.1439 -0.6537
#> 
#> (1,2,.,.) = 
#>  -1.7238 -0.3450
#>   0.2372 -0.6565
#> 
#> (1,3,.,.) = 
#>   1.1468 -0.6219
#>   0.6974  0.8079
#> 
#> (1,4,.,.) = 
#>   1.1268 -0.0199
#>  -0.6402  1.3421
#> [ CPUFloatType{1,4,2,2} ]