use_session_with_seed() not working in RStudio

Hello!

I'm trying to set a seed for my session so that my results with keras/tensorflow are reproducible, using use_session_with_seed. I ran use_session_with_seed(42) right after installing and calling the libraries for Keras and TensorFlow, and get the following error:

Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'tensorflow.keras.backend' has no attribute 'set_session'

Does anyone have any idea how I may get this to work?

I installed TensorFlow and Keras using:
install.packages('tensorflow')
library(tensorflow)
install_tensorflow()
install.packages('keras')
library(keras)

Here is the conda version being used:
"conda 4.8.3"

And here is my session info:
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] randomForest_4.6-14 class_7.3-16 pROC_1.16.2 ROSE_0.0-3 e1071_1.7-3
[6] caret_6.0-86 ggplot2_3.2.1 lattice_0.20-38 keras_2.3.0.0 tensorflow_2.2.0

loaded via a namespace (and not attached):
[1] reticulate_1.16 tidyselect_1.0.0 xfun_0.12 purrr_0.3.3 reshape2_1.4.3
[6] splines_3.6.2 colorspace_1.4-1 vctrs_0.3.0 generics_0.0.2 stats4_3.6.2
[11] base64enc_0.1-3 survival_3.1-8 prodlim_2019.11.13 rlang_0.4.6 ModelMetrics_1.2.2.2
[16] pillar_1.4.3 glue_1.3.1 withr_2.1.2 foreach_1.4.8 lifecycle_0.2.0
[21] plyr_1.8.5 lava_1.6.7 stringr_1.4.0 timeDate_3043.102 munsell_0.5.0
[26] gtable_0.3.0 recipes_0.1.13 codetools_0.2-16 labeling_0.3 knitr_1.26
[31] tfruns_1.4 Rcpp_1.0.3 scales_1.1.0 ipred_0.9-9 jsonlite_1.6.1
[36] farver_2.0.3 digest_0.6.23 stringi_1.4.4 dplyr_0.8.4 grid_3.6.2
[41] tools_3.6.2 magrittr_1.5 lazyeval_0.2.2 tibble_3.0.1 crayon_1.3.4
[46] whisker_0.4 pkgconfig_2.0.3 zeallot_0.1.0 ellipsis_0.3.0 MASS_7.3-51.5
[51] Matrix_1.2-18 data.table_1.12.8 lubridate_1.7.8 gower_0.2.2 assertthat_0.2.1
[56] rstudioapi_0.10 iterators_1.0.12 R6_2.4.1 rpart_4.1-15 nnet_7.3-12
[61] nlme_3.1-142 compiler_3.6.2

Thanks!

The syntax is different between TF version 1.X and 2.x. Here is how the embed package deals with it. This code can be used to get the version number.

Also, I would suggest installing the devel version of reticulate so that you can avoid another bug that can show up.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

This worked! Thank you - I really appreciate it.