R Keras Error: все входные данные для слоя должны быть тензорами - PullRequest
0 голосов
/ 06 ноября 2018

Я запускаю следующий код и получаю сообщение об ошибке, когда я запускаю последнюю часть, добавляя слои. Я не уверен, как исправить ошибку. Я использую версию 2.1.5 Keras и 3.5.1 R.

library(keras)

    mnist <- dataset_mnist()
    x_train <- mnist$train$x
    y_train <- mnist$train$y
    x_test <- mnist$test$x
    y_test <- mnist$test$y

    #     The x data is a 3-d array (images,width,height) of grayscale values . 
    #     To prepare the data for training we convert the 3-d arrays into matrices by reshaping 
    #     width and height into a single dimension (28x28 images are flattened into length 784 vectors). 
    #     Then, we convert the grayscale values from integers ranging between 0 to 255 into 
    #     floating point values ranging between 0 and 1:

    # reshape

    x_train <- array_reshape(x_train, c(nrow(x_train), 784))
    x_test <- array_reshape(x_test, c(nrow(x_test), 784))

    # rescale

    x_train <- x_train / 255
    x_test <- x_test / 255

    #   Note that we use the array_reshape() function rather than the dim<-() function to reshape the array. 
    #   This is so that the data is re-interpreted using row-major semantics (as opposed to R’s default 
    #   column-major semantics), which is in turn compatible with the way that the numerical libraries 
    #   called by Keras interpret array dimensions.

    #   The y data is an integer vector with values ranging from 0 to 9. To prepare this data for training 
    #   we one-hot encode the vectors into binary class matrices using the Keras to_categorical() function:

    y_train <- to_categorical(y_train, 10)
    y_test <- to_categorical(y_test, 10)

    model <- keras_model_sequential() 
    model %>% 
      layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>% 
      layer_dropout(rate = 0.4) %>% 
      layer_dense(units = 128, activation = 'relu') %>%
      layer_dropout(rate = 0.3) %>%
      layer_dense(units = 10, activation = 'softmax')

Ошибка в py_call_impl (вызываемый, точки $ args, точки $ ключевые слова): ValueError: Слой density_1 был вызван с вводом, который не является символическим тензором. Полученный тип: класс 'keras.engine.sequential.Sequential'. Полный ввод: keras.engine.sequential.Sequential объект в 0x000000002A2B90F0. Все входы в слой должны быть тензорами.

...