首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中的错误:保存和加载模型需要h5py Python包

R中的错误:保存和加载模型需要h5py Python包
EN

Stack Overflow用户
提问于 2017-10-19 05:03:54
回答 2查看 4K关注 0票数 6

我使用的是R 3.4.2。我正在遵循decryptr package的示例

代码语言:javascript
复制
library(decryptr)

# Download captchas
captcha <- download_tjmg(dest = 'img')
keras_tjmg <- decryptrModels::read_model('tjmg')

最后一行代码产生错误

代码语言:javascript
复制
Error in keras::load_model_hdf5(file_path) : 
  The h5py Python package is required to save and load models

我已经尝试从终端重新安装h5py包。我还安装了keras包。我可以在pyrthon中导入h5py包,但Rstudio不知何故无法识别它。

EN

回答 2

Stack Overflow用户

发布于 2017-10-19 07:26:06

我以前从来没有安装过这些包,但是我按照下面的步骤进行并成功了!它也花了一些时间,因为除了您报告的错误之外,它还给了我各种错误。

最后,我想到了这个:在终端中,

代码语言:javascript
复制
pip uninstall h5py
pip install h5py
pip uninstall keras
pip install keras

我在Python中检查了import h5py是否运行正确(第一次,它给了我一个DLL失败)。然后在R中,在重启之后,

代码语言:javascript
复制
install.packages("reticulate")
install.packages("tensorflow")
install.packages("keras")
install.packages("h5py")
devtools::install_github("decryptr/decryptr")
devtools::install_github("decryptr/decryptrModels")

library(keras)
install_keras()

# Check where Python's looked for
reticulate::py_config() 

library(decryptr)
library(decryptrModels)

captcha <- captcha_download_tjmg(dest = 'img')
keras_tjmg <- read_model('tjmg')

我的sessionInfo()如下:

代码语言:javascript
复制
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] decryptrModels_0.0.0.9000 decryptr_0.0.1.9000      
[3] keras_2.0.8.9001         
loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13          prettyunits_1.0.2     assertthat_0.2.0     
 [4] R6_2.2.2              jsonlite_1.5          magrittr_1.5         
 [7] httr_1.3.1            tfruns_1.0            rlang_0.1.2          
[10] progress_1.1.2        curl_2.8.1            whisker_0.3-2        
[13] reticulate_1.2.0.9005 tools_3.4.1           purrr_0.2.3          
[16] compiler_3.4.1        base64enc_0.1-3       tensorflow_1.4.0.9003

如果成功了,请让我知道。

票数 2
EN

Stack Overflow用户

发布于 2020-11-02 23:58:26

尽管我的回复晚了几年,但我可以通过安装libpython-dev来修复Ubuntu 18.04中的问题。reticulate似乎需要这个库来支持R中的Keras/Tensorflow:

sudo apt-获取更新-qq

sudo apt-get install -qq -y --no--推荐libpython-dev

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46819212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档