mlverse / torchvision

R interface to torchvision
https://torchvision.mlverse.org
Other
62 stars 14 forks source link

transform_rotate changes shape of input #101

Open sebffischer opened 10 months ago

sebffischer commented 10 months ago

Maybe I don't fully understand the transform_rotate() function, but below it yields a (for me) unexpected output shape.

library(torchvision)
library(torch)
#> Warning: package 'torch' was built under R version 4.3.1

x = torch_randn(1, 3, 200, 150)

transform_rotate(x, angle = 0, expand = TRUE)$shape
#> [1]   1   3 150 150
transform_rotate(x, angle = 0, expand = FALSE)$shape
#> [1]   1   3 150 150

Created on 2023-10-25 with reprex v2.0.2

cregouby commented 1 week ago

Hello @sebffischer,

When angle = 0 I guess the transform is the identity, so no change in values nor shape is expected...

I gess expand works as expected when angle != 0

library(torchvision)
library(torch)

x = torch_randn(1, 3, 200, 150)

transform_rotate(x, angle = 6, expand = TRUE)$shape
#> [1]   1   3 166 166
transform_rotate(x, angle = 6, expand = FALSE)$shape
#> [1]   1   3 150 150

Created on 2024-08-31 with reprex v2.1.1

Could you be more explicit on your expectation ?

sebffischer commented 1 week ago

my question is why the shape is not c(1, 3, 200, 150) afterwards

cregouby commented 1 week ago

You're right sorry, I didn't see the difference bw H and W dimensions. I've proposed a P.R. to fix it.