Hi,
I recently installed keras
/tensorflow
on my computer (macOS), and I am trying to run one of the standard examples (the one on the front page of https://keras.rstudio.com), and I receive the following error when fitting my model:
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: update() takes from 2 to 3 positional arguments but 4 were given
Does anyone have any clue what could be causing it? I copied and pasted the code straight from the website.
My code is pasted here:
library(keras)
use_condaenv("r-tensorflow")
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y
# 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
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')
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = c('accuracy')
)
history <- model %>% fit(
x_train, y_train,
epochs = 30, batch_size = 128,
validation_split = 0.2
)
The error shows up on the last part of the code. The traceback is as follows:
18.
stop(structure(list(message = "TypeError: update() takes from 2 to 3 positional arguments but 4 were given",
call = py_call_impl(callable, dots$args, dots$keywords),
cppstack = structure(list(file = "", line = -1L, stack = c("1 reticulate.so 0x0000000107d4b7f4 _ZN4Rcpp9exceptionC2EPKcb + 276",
"2 reticulate.so 0x0000000107d4b630 _ZN4Rcpp4stopERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 48", ...
17.
update_with_patch at progbar.py#23
16.
on_batch_end at callbacks.py#331
15.
on_batch_end at callbacks.py#113
14.
_fit_loop at training.py#1241
13.
fit at training.py#1712
12.
fit at models.py#963
11.
(structure(function (...)
{
dots <- py_resolve_dots(list(...))
result <- py_call_impl(callable, dots$args, dots$keywords) ...
10.
do.call(object$fit, args)
9.
fit(., x_train, y_train, epochs = 30, batch_size = 128, validation_split = 0.2)
8.
function_list[[k]](value)
7.
withVisible(function_list[[k]](value))
6.
freduce(value, `_function_list`)
5.
`_fseq`(`_lhs`)
4.
eval(quote(`_fseq`(`_lhs`)), env, env)
3.
eval(quote(`_fseq`(`_lhs`)), env, env)
2.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1.
model %>% fit(x_train, y_train, epochs = 30, batch_size = 128,
validation_split = 0.2)
Thanks for your help!