1

I intend to feed neural net with image data. Originally I have them stored as a list of arrays with dims 10,10,3 (height, length, color channel).

  1. Does anyone know how to convert the list containing multiple cimg images into one cimg storing multiple images in R?

and/or

  1. Does anyone know how to convert list of arrays with dims 10,10,3 into the object acceptable by keras?
ramen
  • 691
  • 4
  • 20
  • Are the cimg(s) in the list named or just [10,10,3] arrays in a list? – Chris Nov 29 '21 at 15:13
  • They may be named or not (initially were named, for indexing & filtering purposes, however I can always set names(list) <- NULL – ramen Nov 29 '21 at 16:18
  • Does the approach below work for your purposes? – Chris Nov 29 '21 at 16:20
  • @Chris yes, it does, thank you very much. However I had also to use aperm() function to flip my array. – ramen Dec 01 '21 at 15:59
  • Why was that necessary (flipping) and what was the desired/resulting dim(arr)? – Chris Dec 02 '21 at 13:57
  • 1
    Flipping was necessary to adjust the array dims to the vector with labels. The input array dims should have following order: observations, height, width, channels. If it does not, then keras throws an error. – ramen Dec 02 '21 at 19:28
  • Understood, and thanks for updating on input requirements. So that this discussion of `keras` and images provides useful info to future searchers who may not read comments, I suggest you write up your process as an answer and then accept it as generally questions with answers are navigated to first. – Chris Dec 02 '21 at 23:50

1 Answers1

1

You can use simplify2array, which takes a list and returns an array.

my_images_arr <- simplify2array(my_list_of_cimg)

there after, make your data labels. keras doesn't appear to require that your array object have a class attribute, just be in a consistent form, in this case an array of images.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Chris
  • 1,647
  • 1
  • 18
  • 25