1

Is there any method to convert the ggplot image directly to an image array/vector (ex. CIMG format) to process in a Convolutional Neural Network, without having to save these files on local disk and reload them?

Issue Faced:

Saving each plot as a jpeg file is taking up to 5 hours currently.

The process that I have followed is given below:

  1. Generate over 10,000 plots through looping
  2. Use GGsave to save the plot as png (or jpeg) on local disk (looping through the save function)
  3. Load the files using ImageR (or openCV if using python)
  4. Manipulate RGB matrix (128,128,3 images) for Convolutional Neural Network.

    plts = list()

    plt_names = c()

    idx = 1

    for (i in seq(length(df_example$cats))){

    df_plot = df_example[i+(i+10)] %>% ggplot(aes(x = time, y = cats)) + geom_density(color = 'blue')

    plts[idx] = df_plot

    plt_names = c(plt_names, paste0(df_example$time[i+10]))

    idx = idx + 1 }

    for(i in seq(plt_len)){

    ggsave(filename = paste0(plt_names[i],'.jpeg'),plot = plts[[i]]) }

Vinny
  • 11
  • 3
  • Are you sure the bottle neck is really writing to disc? Or is it the processing of actually rendering the image to pixels. My guess is the latter. So you just want to turn them into arrays of RGB pixel values? It would be nice to have some sort of [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and output so we can test possible solutions and see exactly what the desired result is. – MrFlick May 16 '18 at 16:52
  • Yes, I just want to turn them into arrays of RGB pixel values for CNN input. Please see my edits. Thanks. – Vinny May 16 '18 at 17:40
  • The edit isn't very helpful because we can't actually run it to test it. And it only shows how you were creating the plots, it doesn't show how you you need to load the data for later analysis. – MrFlick May 16 '18 at 19:21

0 Answers0