所以我尝试使用
keras
和 这个初学者教程来学习 RNN:
我正在逐步完成本教程,但在添加输入层后遇到了一个奇怪的错误。这是导致问题的行:
# our input layer
model %>%
layer_dense(input_shape = dim(X_train)[2:3], units = max_len)
这是错误:
Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
ValueError: Only input tensors may be passed as positional arguments. The following argument value should be passed as a keyword argument: <Sequential name=sequential_6, built=False> (of type <class 'keras.src.models.sequential.Sequential'>)
Run `reticulate::py_last_error()` for details.
肯定和我安装的R有关,但我不知道哪里出错了。我从 R、RStudio 和 Python 的官方网站安装了最新版本。我使用的是 Windows 10。这是我的安装方式
keras
:
devtools::install_github("rstudio/keras")
我遇到了同样的问题。我通过使用 R 版本 4.2.3 而不是 4.3.3 并重新安装tensorflow和keras包解决了这个问题:
install.packages("tensorflow")
library(tensorflow)
tensorflow::install_tensorflow()
install.packages("keras")
keras::install_keras()
library(keras)
版本为:tensorflow 2.15.0 和 keras 2.13.0。