Open lovalery opened 3 years ago
Hi, I am unable to reproduce the bug with the current release version of keras (2.6.0). Please me me know if you are still encountering this issue.
Automatically closed because there has not been a response for 30 days. When you're ready to work on this further, please comment here and the issue will automatically reopen.
Hi @t-kalinowski, Thank you very much for your feedback and sorry for the delay in replying. Indeed the update to version 2.6.0 solved the problem... but unfortunately when I want to execute the following line of code (still found in the book of F. Chollet and J.J. Allaire, at bottom of page 153), I get a new error (please, see reprex below).
Thank you in advance for helping me to solve this new problem.
library(keras)
model <- application_vgg16(
weights = "imagenet",
include_top = FALSE
)
layer_name <- "block3_conv1"
filter_index <- 1
layer_output <- get_layer(model, layer_name)$output
loss <- k_mean(layer_output[,,,filter_index])
grads <- k_gradients(loss, model$input)[[1]]
#> Error in py_call_impl(callable, dots$args, dots$keywords): RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.
#>
#> Detailed traceback:
#> File "C:\Users\toto\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\keras\backend.py", line 4103, in gradients
#> loss, variables, colocate_gradients_with_ops=True)
#> File "C:\Users\toto\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\ops\gradients_impl.py", line 172, in gradients
#> unconnected_gradients)
#> File "C:\Users\toto\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\ops\gradients_util.py", line 492, in _GradientsHelper
#> raise RuntimeError("tf.gradients is not supported when eager execution "
Created on 2021-10-02 by the reprex package (v2.0.1)
If needed, here are the details of my session:
sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 8.1 x64 (build 9600)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
#> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
#> [5] LC_TIME=French_France.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] keras_2.6.0
#>
#> loaded via a namespace (and not attached):
#> [1] digest_0.6.27 withr_2.4.2 magrittr_2.0.1 reprex_2.0.1
#> [5] evaluate_0.14 highr_0.9 stringi_1.7.4 rlang_0.4.11
#> [9] cli_3.0.1 rstudioapi_0.13 fs_1.5.0 rmarkdown_2.11
#> [13] tools_4.0.2 stringr_1.4.0 glue_1.4.2 xfun_0.26
#> [17] yaml_2.2.1 fastmap_1.1.0 compiler_4.0.2 htmltools_0.5.2
#> [21] knitr_1.34 tensorflow_2.6.0
Created on 2021-10-02 by the reprex package (v2.0.1)
Using k_gradients()
requires a non-eager context. The easiest way to enter graph mode is to wrap your code in a tf_function()
. Alternatively, you can use tf$GradientTape
in the eager context, though it has different semantics.
Some helpful links:
tf.gradients
(which powers k_gradients()
in R): https://www.tensorflow.org/api_docs/python/tf/gradientstf$GradientTape
in action: https://keras.rstudio.com/articles/new-guides/customizing_what_happens_in_fit.html#going-lower-level-1
Hello,
As a beginner, I read the very instructive and didactic book by François Chollet with J.J. Allaire "Deep Learning with R".
However, I am currently facing a problem when trying to visualize the convnet filters: when I try to reproduce the code of the book, R returns an error (see reprex below from the code of the book).
Is this an error in the code or is it deprecated due to a recent update of the library?
I would be very grateful if you could clarify this for me and provide a solution.
Kind regards Loïc
REPREX:
Created on 2021-06-29 by the reprex package (v2.0.0)
If needed, here are the details of my session:
Created on 2021-06-29 by the reprex package (v2.0.0)