我正在运行以下代码,并在运行最后一部分添加图层时出错。我不确定如何解决该错误。我使用的是Keras的2.1.5版本和R的3.5.1版本。
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(可调用,dots $ args,dots $ keywords)错误: ValueError:使用不是符号张量的输入调用了density_1层。接收的类型:类“ keras.engine.sequential.Sequential”。完整输入:位于0x000000002A2B90F0的keras.engine.sequential.Sequential对象。该层的所有输入应为张量。