-
Notifications
You must be signed in to change notification settings - Fork 282
Description
Hi,
my installation of keras3 using GPU support and the torch backend failed. Before adding an installation issue on this Github page concerning this probem I tried to install the basic default installation steps as indicated below:
First I tried to resolve the installation issue by running the following in a fresh R session
# install the development version of packages, in case the
# issue is already fixed but not on CRAN yet.
install.packages("remotes")
remotes::install_github(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
if (is.null(reticulate::virtualenv_starter()))
reticulate::install_python()
keras3::install_keras()Up to this point there was no error.
Then I tested tensorflow
tensorflow::as_tensor("Hello World")This failed but following the recommendation on this page I issued
tensorflow::install_tensorflow()
After this (again after terminating R) the function call
tensorflow::as_tensor("Hello World")
succeeded. I saw tf.Tensor(b'Hello World', shape=(), dtype=string). So Tensorflow has been successfully installed.
But the first few lines of the keras3 MNIST example on https://keras3.posit.co/articles/examples/vision/mnist_convnet.html failed:
> library(keras3)
> num_classes <- 10
> input_shape <- c(28, 28, 1)
> c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()
Fehler: ModuleNotFoundError: No module named 'keras.ops'
Run `reticulate::py_last_error()` for details.
Therefore I gathered some diagnostic info after the RStudio - Session - Terminate R:
reticulate::py_config()
python: C:/Users/ulk/AppData/Local/Programs/Python/Python39/python.exe
libpython: C:/Users/ulk/AppData/Local/Programs/Python/Python39/python39.dll
pythonhome: C:/Users/ulk/AppData/Local/Programs/Python/Python39
version: 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/ulk/AppData/Local/Programs/Python/Python39/Lib/site-packages/numpy
numpy_version: 1.26.4
keras: C:\Users\ulk\AppData\Local\Programs\Python\Python39\lib\site-packages\keras
NOTE: Python version was forced by use_python() function
> tensorflow::tf_config()
TensorFlow v2.10.1 (C:\Users\ulk\AppData\Local\Programs\Python\Python39\lib\site-packages\keras)
Python v3.9 (C:/Users/ulk/AppData/Local/Programs/Python/Python39/python.exe)
> reticulate::import("tensorflow")
Module(tensorflow)
> reticulate::py_last_error()
NULL
> sessionInfo()
R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)
Matrix products: default
LAPACK version 3.12.1
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C LC_TIME=German_Germany.utf8
time zone: Europe/Berlin
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] keras3_1.4.0.9000
loaded via a namespace (and not attached):
[1] base64enc_0.1-3 codetools_0.2-20 Matrix_1.7-3 lattice_0.22-7
[5] magrittr_2.0.3 reticulate_1.42.0 glue_1.8.0 png_0.1-8
[9] generics_0.1.4 lifecycle_1.0.4 cli_3.6.5 tensorflow_2.16.0.9000
[13] vctrs_0.6.5 grid_4.5.1 zeallot_0.2.0 rsconnect_1.5.0
[17] tfruns_1.5.3 compiler_4.5.1 rstudioapi_0.17.1 tools_4.5.1
[21] whisker_0.4.1 pillar_1.11.0 dotty_0.1.0 Rcpp_1.1.0
[25] rlang_1.1.6 jsonlite_2.0.0
> How to resolve this installation problem?