Closed maitra closed 11 months ago
Can you post a little more detail about your setup? What is the output of sessionInfo()
and reticulate::py_config()
? Also, what is the output from reticulate::py_last_error()
(what is the R traceback?)
If you're on Windows, I suspect you might be encountering some variation of this issue: https://github.com/rstudio/reticulate/issues/1473. Alternatively, a more recent version of TensorFlow might now have more strict type promotion semantics.
The error message suggests that a well-placed tf$cast(x, "float32")
should fix the error.
Thanks for looking into this! Sorry, I am on Fedora 38 Linux OS. Here are the outputs:
> reticulate::py_last_error()
── Python Exception Message ────────────────────────────────────────────────────
Traceback (most recent call last):
File "/home/maitra/.virtualenvs/r-reticulate/lib64/python3.11/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/maitra/.virtualenvs/r-reticulate/lib64/python3.11/site-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute
except TypeError as e:
tensorflow.python.framework.errors_impl.NotFoundError: Graph execution error:
Detected at node 'ReadFile' defined at (most recent call last):
File "<string>", line 4, in fn
File "/usr/lib64/R/library/reticulate/python/rpytools/call.py", line 7, in python_function
value, error = rpycall.call_r_function(f, *args, **kwargs)
Node: 'ReadFile'
coast.jpg; No such file or directory
[[{{node ReadFile}}]] [Op:__inference_fn_5336]
── R Traceback ─────────────────────────────────────────────────────────────────
▆
1. └─reticulate (local) preprocess_image(base_image_path)
2. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
And here is:
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 38 (Thirty Eight)
Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP; LAPACK version 3.11.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/Chicago
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tensorflow_2.14.0 keras_2.13.0
loaded via a namespace (and not attached):
[1] backports_1.4.1 R6_2.5.1 base64enc_0.1-3 Matrix_1.6-4
[5] lattice_0.22-5 reticulate_1.34.0 magrittr_2.0.3 rappdirs_0.3.3
[9] png_0.1-8 generics_0.1.3 lifecycle_1.0.4 cli_3.6.1
[13] grid_4.3.2 zeallot_0.1.0 tfautograph_0.3.2 tfruns_1.5.1
[17] compiler_4.3.2 rprojroot_2.0.4 here_1.0.1 whisker_0.4.1
[21] Rcpp_1.0.11 rlang_1.1.2 jsonlite_1.8.7
And here is:
> reticulate::py_config()
python: /home/maitra/.virtualenvs/r-reticulate/bin/python
libpython: /usr/lib64/libpython3.11.so
pythonhome: /home/maitra/.virtualenvs/r-reticulate:/home/maitra/.virtualenvs/r-reticulate
version: 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)]
numpy: /home/maitra/.virtualenvs/r-reticulate/lib/python3.11/site-packages/numpy
numpy_version: 1.24.3
tensorflow: /home/maitra/.virtualenvs/r-reticulate/lib64/python3.11/site-packages/tensorflow
What am I casting here with tf$cast(x, "float32")
? Where would I place this? Thank you again for your help!
What version of TensorFlow and Keras are you using?
tensorflow::tf_config()
keras::keras$`__version__`
Thank you again!
> tensorflow::tf_config()
TensorFlow v2.13.1 (~/.virtualenvs/r-reticulate/lib64/python3.11/site-packages/tensorflow)
Python v3.11 (~/.virtualenvs/r-reticulate/bin/python)
> keras::keras$`__version__`
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'tensorflow.keras' has no attribute '__version__'
Run `reticulate::py_last_error()` for details.
I guess that is odd:
> reticulate::py_last_error()
── Python Exception Message ────────────────────────────────────────────────────
AttributeError: module 'tensorflow.keras' has no attribute '__version__'
── R Traceback ─────────────────────────────────────────────────────────────────
▆
1. ├─keras::keras$`__version__`
2. └─reticulate:::`$.python.builtin.module`(keras::keras, `__version__`)
3. └─reticulate:::`$.python.builtin.object`(x, name)
4. └─reticulate:::py_get_attr_or_item(x, name, TRUE)
5. └─reticulate::py_get_attr(x, name)
6. └─reticulate:::py_get_attr_impl(x, name, silent)
See https://github.com/t-kalinowski/deep-learning-with-R-2nd-edition-code/commit/5d666f93d52446511a8a8e4eb739eba1c0ffd199 for how to fix the error. Thank you for reporting!
Thanks for looing into this!
I run the following code:
But I get the error:
No sure why there is a type mismatch.