Closed faltinl closed 4 years ago
It seems to me that your installation is working fine.
is_keras_available
is not the way to check if Keras is installed. It just checks if the keras python implementation is installed, but tensorflow also proivides a keras implementation.
keras.backend.backend()
is not a function from the keras R package. You should use k_backend()
for that.
Sorry - I can' t follow. My primary aim is, of course, not to pass tests but to run otherwise proven ML programmes. The test, btw, is not passed, as the following two lines show:
> k_backend()
Error: ImportError: cannot import name 'tf_utils'
But, quite more important, a short programme produces identical error messages at each line containing keras-specific commands, like
...
> y2 <- iris$Species %>% as.numeric() %>% to_categorical()
Error: Python module keras was not found.
Detected Python configuration:
python: C:\Anaconda3\envs\r-tensorflow\python.exe
libpython: C:/Anaconda3/envs/r-tensorflow/python36.dll
pythonhome: C:\ANACON~1\envs\R-TENS~1
version: 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16)
[MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: [NOT FOUND]
keras: C:\ANACON~1\envs\R-TENS~1\lib\site-packages\keras\__init__.p
NOTE: Python version was forced by use_python function
...
and the same for cases like
...
> input <- layer_input(shape = 3)
...
> dense <- layer_dense(input, units = 32)
...
> model <-
+ keras_model(inputs = input, outputs = list(output1, output2))
... etc ...
and
> model %>% compile(
+ optimizer = "adam",
+ loss = list(loss_mean_squared_error, loss_categorical_crossentropy)
+ )
Error in eval(lhs, parent, parent) : object 'model' not found
So, much to my regret, I don't have the impression of an installation working fine...
Can you try installing older versions of the keras R package and the tensorflow package? We are no longer supporting TensorFlow v1.5 in the recent versions of the R package.
You can do this by running:
remotes::install_version("keras", version = "2.1.4", repos = "http://cran.us.r-project.org")
remotes::install_version("tensorflow", version = "1.5", repos = "http://cran.us.r-project.org")
You can also consider using a cloud based computing ennvironment that uses a more recent CPU. You can install rstudio server in any provider like AWS, google cloud or azure and then install tensorflow and keras. You could also try using TF in rstudio.cloud.
Thank you for these helpful hints, which I really appreciate. I did as suggested and, in a first step, declined all requests for package updates (for tensorflow, reticulate, jsonlite, rlang & yaml). Thus Keras 2.1.4, Tensorflow 1.5., and (from my earlier installation, see above).
Results were exactly the same as in my first post above.
In a second go, I accepted all requests for updates, which led to tensorflow 2.0.0 and reticulate 1.14. There was a partial improvement insofar, as numpy has been found:
numpy: C:/Anaconda3/envs/r-tensorflow/Lib/site-packages/numpy
numpy_version: 1.18.1
k_backend()
, however still produced Error: ImportError: cannot import name 'tf_utils'
, as above and keras commands in the test program led to the same error messages as above, too.
Just as a random experiment I replaced keras 2.1.4 by keras 2.2.5 which surprisingly had keras commands in my test programm accepted down to layer definitions, but compile() and fit() again produced error messages like the following:
> model %>% compile(optimizer = "adam",
loss = list(loss_mean_squared_error, loss_categorical_crossentropy) )
Error in UseMethod("compile") :
no applicable method for 'compile' applied to an object of class
"c('keras._impl.keras.engine.training.Model',
'keras._impl.keras.engine.topology.Network',
'tensorflow.python.layers.network.GraphNetwork',
'keras._impl.keras.engine.topology.Layer',
'tensorflow.python.layers.base.Layer',
'python.builtin.object')"
Moreover something strange happend:
> k_backend()
Error: Keras loaded from tensorflow v1.5, however version 1.9 is required.
Please update with tensorflow::install_tensorflow().
And installing tensorflow 1.9 led to a repeated request to install tensorflow 2.0.0 again, thus completing a whole cycle of inconsistence. -
In the meantime I'm concluding that I have to accept the situation as it is: there is no way back to pre-TF2.0 Keras. I'll have to look for other approaches to continue my work with Keras for R - which I find really more practical than Python, I openly confess. Following your suggestions to use a suitable cloud based environment definitely is a viable alternative.
Fortunately, there seems to be an opportunity to use a much more recent computer than my present one. It has an Intel Core i7-9750H processor with instruction set extensions Intel SSE4.1, SSE4.2 & AVX2, which should permit to use the cpu-version of tensorflow 2.0.0 without any further tinkering around. And, additionally, there is a built-in NVIDIA GeForce RTX 2060 gpu, too, which I suppose should enable a further step forward for me. How do you think about that?
Yes, definitely using a new computer with a recent CPU (and GPU!) seems to me like the best option.
System information
Problem From Tensorflow 2.0.0 cpu, import error: DLL load failed #36138 I learned that my processor does not have AVX (Advanced Vector Extension) and is therefore unable to support Tensorflow 2.0. My HW limits the SW setup to tensorflow<1.6 and keras<2.2.0.
I have used Keras for R for the last 3 yrs under RStudio and recently tried to update my installation to level TF 2.0. This led to losing my working installation setup described above since attempts to restore the whole SW setup as it was from a back-up failed. However, trying to turn time back by re-installing everything as it was (i.e. R, RStudio, package versions & Anaconda3) did not succeed either.
When the standard conda installation sequence
was completed, the start sequence for using Keras followed,
producing the following:
General test results
Functional test for Tensorflow
Tests for Keras
Conclusion Obviously, Tensorflow is working, but Keras (backend) is not available.
What I noticed during the installation runs: regardless of the version of Keras and the other two components (I tried more or less every combination admitted by various dependencies) from R perspective, among the list of newly installed Python packages invariably the packages
used to show up. And that cannot be correct because when I installed the original setup about 2 yrs ago, a Python version keras 2.3.1-py... most probably wasn't known yet. However, how can I find out more about this and where do I get a suitable previous version of this module using Anaconda (if this should really be the cause of the actual problem)?
Thank you in advance for any useful hints.