Я хочу создать функцию генератора для ввода данных изображения вместе с соответствующими метаданными.Существует более 20 тысяч изображений, поэтому я не могу просто прочитать их в память.Я попытался также использовать flow_from_dataframe, но в случае с несколькими входами это становится сложным.
Функция генератора выглядит следующим образом:
data_files_generator_train <- function(dir) {
files <- list.files(dir ,pattern = "jpg$")
next_file <- 0
function() {
next_file <<- next_file + 1
if (next_file > length(files))
{next_file <<- 1}
# determine the file name
file <- files[[next_file]]
image <- image_load(file, target_size = c(150,150)) %>%
image_to_array() %>%
array_reshape(dim = c(150, 150, 3)) %>%
imagenet_preprocess_input()
x_image <- image/ 255
x_attr <- paintings_attributes_train %>% filter(path == file) %>% select(-c(target, path))
y <- paintings_attributes_train %>% filter(path == file) %>% select(target)
x_attr <- matrix(x_attr, ncol = 16)
y <- matrix(y)
return(list(list(x_image, x_attr), y))
}}
Я получаю следующую ошибку:
Ошибка в py_call_impl (callable, dots $ args, dots $ Keywords): ValueError: Ошибка при проверке входных данных модели: список массивов Numpy, передаваемых в вашу модель, отличается от ожидаемого размера модели.Ожидается увидеть 2 массива (ов), но вместо этого получен следующий список из 1 массива: [массив ([[0,00769116, 0,17699115, 0,1436
) определение модели выглядит следующим образом:
vision_model <- keras_model_sequential()
vision_model %>%
layer_conv_2d(filters = 64,
kernel_size = c(3, 3),
activation = 'relu',
padding = 'same',
input_shape = c(150, 150, 3)) %>%
layer_max_pooling_2d(pool_size = c(2, 2)) %>%
layer_flatten()
# tensor with the output of our vision model:
image_input <- layer_input(shape = c(150, 150, 3))
encoded_image <- image_input %>% vision_model
tabular_input <- layer_input(shape = 16, dtype = 'float32')
mlp_model <- tabular_input %>%
layer_dense(
units = 16,
kernel_initializer = "uniform",
activation = "relu")
# concatenate the metadata vector and the image vector then
# train a linear regression on it
output <- layer_concatenate(c(mlp_model, encoded_image)) %>%
layer_dense(units = 1, activation='linear')
# This is our final model:
vqa_model <- keras_model(inputs = c(tabular_input, image_input), outputs = output)
Вопрос связан с Создание генератора смешанных данных (images, csv) в керасе .
Спасибо за любую помощь!