I am trying to implement a deep learning model in R using Keras. Let's say I had a dataset of people's faces and a CSV with information about the person's age, gender, and ethnicity. I want to train the model to predict a person's age from their photo.
For this, I have to use convolutional neural networks. Here is my pseudocode:
library(keras) model <- keras_model_sequential() model %>% ## define CNN model’s architecture. ## I will figure this out later # configure model model %>% compile( loss='mean_squared_error', optimizer='adam', metrics='mae' ) history <- model %>% fit( # train_array is a 300x100x100x1 array # train_array stores the pixel values of 300 grayscale images # of resolution 100x100 x = train_array, y = ???, epochs = 10, batch_size = 30, )
My question is regarding the
??? marked above. I have three pieces of useful information to train the model:
ethnicity. How do I add this information to the model? Again, I want the model to predict a single prediction of age.
I looked at the Keras fit function documentation but couldn't figure it out. It says that
y is a "Vector, matrix, or array of target (label) data (or list if the model has multiple outputs)..."
That makes sense. Now the question is how do I set up the
x list? Here's what I have so far:
trainFeatures <- list(pixels = train_array, gender = as.factor(trainGenders), ethnicity = as.factor(trainEthnicity)) history <- model %>% fit( x = trainFeatures, y = trainAge, epochs = 10, batch_size = 30, )
I downloaded a toy dataset and set up a quick CNN model. I got the following error message:
Error in py_get_attr_impl(x, name, silent) :
AttributeError: 'list' object has no attribute 'dtype'