In a previous topic, t.kalinowski invited me to ask "here" about problems I had with the keras tutorials at
https://tensorflow.rstudio.com/tutorials/quickstart/ after updating R package keras to keras3. I have been unable to get the specific tutorial "QuickStart/Advanced" to work. Specifically, it fails at the last section starting with "EPOCHS = 1". I made the following 4 changes to the code to get it working up to that point:
- Installed keras3 as per "Getting Started with Keras • keras3" with:
keras3::install_keras(backend = "tensorflow") - loaded MNIST editing "keras" to "keras3:
"c(c(x_train, y_train), c(x_test, y_test)) %<-% keras3::dataset_mnist() - adding "library(tfdatasets)", needed for "tensor_slices_dataset()", and perhaps for other functions,
- changing "tf_function" to "tensorflow::tf_function", evidently not included in the keras3 tensorflow install.
With those changes, the code worked up to the last section starting with "EPOCHS = 1", where the code abended with the message and traceback as follows:
"Error in py_get_attr(x, name) :
AttributeError: 'Mean' object has no attribute 'reset_states'
Run reticulate::py_last_error()
for details.
reticulate::py_last_error()
── Python Exception Message ──────────────────────────────────────────────────────────────
AttributeError: 'Mean' object has no attribute 'reset_states'
── R Traceback ───────────────────────────────────────────────────────────────────────────
▆
- └─global reset_metrics()
- ├─metric$reset_states
- └─reticulate:::
$.python.builtin.object
(metric, "reset_states") -
└─reticulate:::py_get_attr_or_item(x, name, TRUE)
-
└─reticulate::py_get_attr(x, name)
See reticulate::py_last_error()$r_trace$full_call
for more details.
reset_metrics()
Error in py_get_attr(x, name) :
AttributeError: 'Mean' object has no attribute 'reset_states'
Runreticulate::py_last_error()
for details.
train(train_ds)
Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
TypeError: enter() missing 1 required positional argument: 'self'
Runreticulate::py_last_error()
for details.
test(test_ds)
Error in assert_all_dots_named(envir, call) :
RuntimeError: All arguments provided to...
must be named.
Call with unnamed arguments in dots:
test_loss(t_loss)
Runreticulate::py_last_error()
for details."
I didn't understand these messages.
I would be very grateful if t.kalinowski or one of the keras3 team can update the code in this keras tutorial so that I can run it successfully with R package keras3. Thanks. Larry Hunsicker
Running R 4.4.1 and RStudio 2024.04.2 Build 764 on a 64 bit Windows 11 laptop.