How to install package keras in R

≡放荡痞女 提交于 2020-07-07 05:47:35

问题


I'm trying to install deep learning package keras on RStudio using this website. I installed keras using

install.packages("keras") 
library(keras)
install_keras()

but when I tried to open the MNIST dataset

mnist <- dataset_mnist()

I keep getting the error

Error: ModuleNotFoundError: No module named 'absl'

I thought keras installed tensorflow but do I need to install tensorflow separately?


回答1:


I had the same problem and it is solved by installing the package in two steps:

install keras: install.packages("keras")
keras::install_keras()

There you go!




回答2:


If you follow the TUT and still got error, try running py_config() and check the python and libpython if it is pointing to an r-tensorflow environment. If not, best to try manually install keras in your manually set up conda environment.

Step 1: Install keras in your R just like in the link above.

#Open rstudio and run the following command
devtools::install_github("rstudio/keras") 
#Don't close rstudio after running this, okay?

Step 2: Manually install keras (and tensorflow) in your machine ##. When i say “manual” it means using python specifically through conda. Here’s the link I followed: https://medium.com/i-want-to-be-the-very-best/installing-keras-tensorflow-using-anaconda-for-machine-learning-44ab28ff39cb .

In summary, the link will teach you to install anaconda, create an environment and install necessary libraries. Just follow it. I named my environment as “r-tensorflow” because that is the name of the environment that the install_keras() in R will do :)

Step 3: Point rstudio to use the python in your newly created environment using use_python() function

Open your rstudio (if you close it after following step 1) and type the following code

library(keras)
library(reticulate)
# in case you run into error run this : reticulate::py_discover_config("keras") 
use_python("<yourpath>/Anaconda3/envs/r-tensorflow/Scripts/python.exe")
# change <yourpath> approriately
# write all the codes for building model in keras (or tensorflow) e.g. mnist<-dataset_mnist()

Important note on Step 3: If you still got the "not found module" after following step 3, you must start a new fresh R session and ensure to delete the workspace (.RData) because more likely your current script will still use the old python configuration though you used use_python




回答3:


Please install "reticulate" library using command install.packages("reticulate") and then load using library(reticulate) then install absl using command conda_install('r-tensorflow','absl-py')



来源:https://stackoverflow.com/questions/49684605/how-to-install-package-keras-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!