rstudio / tensorflow

TensorFlow for R
https://tensorflow.rstudio.com
Apache License 2.0
1.32k stars 317 forks source link

keras gradients error #581

Closed Hlaneunim closed 9 months ago

Hlaneunim commented 10 months ago

Calling k_gradients, this error presents me:

Error in py_call_impl(callable, call_args$unnamed, call_args$named) : RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead. Run reticulate::py_last_error() for details.

How do I disable eager in R? Searched without help

t-kalinowski commented 9 months ago

If you want to disable eager execution globally, you can call:

library(tensorflow)
tf$compat$v1$disable_eager_execution()

This should only be necessary for old codebases that were written for TF v1. With TF v2, the primary way users are expected to enter "graph" mode is via tf_function().