fdavidcl / ruta

Unsupervised Deep Architechtures in R
https://deivi.ch/ruta
GNU General Public License v3.0
38 stars 4 forks source link

Support for differently shaped data (e.g. CIFAR10) #21

Open seonghobae opened 6 years ago

seonghobae commented 6 years ago

Hello, there!

I want to use this awesome software to learning CIFAR10 structured data. Could you support them?

Best, Seongho

fdavidcl commented 6 years ago

Hi!

Thanks for the suggestion. Currently autoencoders defined in Ruta can only treat one-dimensional instances. You could flatten the data beforehand, like in the following example:

library(ruta)
library(purrr)

cifar10 <- keras::dataset_cifar10()
cifar_shape <- as.integer(dim(cifar10$train$x)[-1])

x_train <- keras::array_reshape(
  cifar10$train$x, c(nrow(cifar10$train$x), prod(cifar_shape))
) / 255.0
x_test <- keras::array_reshape(
  cifar10$test$x, c(nrow(cifar10$test$x), prod(cifar_shape))
) / 255.0

ae <-
  autoencoder(
    input() +
      dense(100) + dense(10) + dense(100) +
      output("sigmoid")
  ) %>%
  train(x_train, epochs = 40)
decoded <- ae %>% reconstruct(x_test)

I know this is cumbersome and am working in a simpler solution which allows for treatment of differently shaped data.

Regards, David