mlverse / torchvision

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

Torchvision random transform is not selecting a transform correctly #95

Closed MCodrescu closed 1 year ago

MCodrescu commented 1 year ago
# Example Image
x <- array(1, dim = c(3, 200, 200))

# Transforms
color_transform <- function(img) torchvision::transform_color_jitter(
    img, brightness = 0.5, contrast = 0.5, saturation = 0.5, hue = 0.5
)
resize_crop <- function(img) torchvision::transform_random_resized_crop(img, size = c(200, 200))
hflip <- function(img) torchvision::transform_random_horizontal_flip(img)
vflip <- function(img) torchvision::transform_random_vertical_flip(img)
rotate <- function(img) torchvision::transform_random_rotation(img, 20)
identity <- function(img) img

# Select a Random Transform to Apply
torchvision::transform_random_choice(
    x,
    list(
        color_transform,
        resize_crop,
        hflip,
        vflip,
        rotate,
        identity
    )
)
#> Error in transforms[[i]]: recursive indexing failed at level 2

Created on 2023-07-07 with reprex v2.0.2

dfalbel commented 1 year ago

Thanks very much for reporting @MCodrescu . Should be fixed in the dev version now