I am trying to get keras_model_sequential
to work in R:
library(tidyverse)
library(keras)
model <- keras_model_sequential(input_shape = c(8))
model %>%
layer_dense(units = 32) %>%
layer_activation('softmax')
Defining model goes just fine. Running the last line, however, gives the following error.
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_5, built=False> (of type <class 'keras.src.models.sequential.Sequential'>)
Run `reticulate::py_last_error()` for details.
Following the advice in the last line I get
── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
▆
1. ├─model %>% layer_dense(units = 32) %>% ...
2. ├─keras::layer_activation(., "softmax")
3. │ └─keras::create_layer(...)
4. └─keras::layer_dense(., units = 32)
5. └─keras::create_layer(...)
6. ├─keras:::compose_layer(object, layer)
7. └─keras:::compose_layer.default(object, layer)
8. └─reticulate (local) layer(object, ...)
9. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
See `reticulate::py_last_error()$r_trace$full_call` for more details.
I do not know what to make of this. I have tried to look online what the error means, but I am not getting problems that look similar, mostly a bunch of Python code.
In my efforts to solve this, I have updated my RStudio to 2024.09.0, Keras to 2.15.0 and R to 4.4.1 However, I am still getting exactly the same error.
How can I solve this error and successfully run keras_model_sequential
?
The error seems to be a bug with current release of keras
package. Please remove it and try keras3
instead as suggested here