[英]How to install package keras in R
我正在嘗試使用此網站在 RStudio 上安裝深度學習包keras
。 我使用安裝了keras
install.packages("keras")
library(keras)
install_keras()
但是當我嘗試打開MNIST
數據集時
mnist <- dataset_mnist()
我不斷收到錯誤
錯誤:ModuleNotFoundError:沒有名為“absl”的模塊
我以為 keras 安裝了 tensorflow 但我需要單獨安裝 tensorflow 嗎?
我遇到了同樣的問題,它通過分兩步安裝軟件包來解決:
install keras: install.packages("keras")
keras::install_keras()
你去吧!
如果您按照 TUT 操作仍然出錯,請嘗試運行py_config()
並檢查 python 和 libpython 是否指向 r-tensorflow 環境。 如果沒有,最好嘗試在手動設置的 conda 環境中手動安裝 keras。
#Open rstudio and run the following command
devtools::install_github("rstudio/keras")
#Don't close rstudio after running this, okay?
總之,該鏈接將教您安裝anaconda,創建環境並安裝必要的庫。 只要跟着它。 我將我的環境命名為“r-tensorflow”,因為這是 R 中的 install_keras() 將執行的環境的名稱:)
打開您的 rstudio(如果您在執行第 1 步后將其關閉)並輸入以下代碼
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()
關於第 3 步的重要說明:如果在執行第 3 步之后仍然出現“未找到模塊”,則必須啟動一個新的 R 會話並確保刪除工作區 (.RData),因為您當前的腳本更有可能仍使用舊的python 配置雖然你使用了 use_python
請使用命令install.packages("reticulate")
安裝“reticulate”庫,然后使用library(reticulate)
加載,然后使用命令conda_install('r-tensorflow','absl-py')
安裝 absl
嘗試:
install.packages("devtools")
devtools::install_github("rstudio/keras")
library(keras)
mnist<-dataset_mnist()
我有同樣的問題,但我的問題是通過用雙引號括起來的keras
解決的。
install.packages("keras") ## worked for me,
install.packages(keras) ## never worked.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.