Keras with PlaidML not working on Windows

Hi,
I've installed plaidml in Windows in its own conda environment and it works.

(plaidml) C:\Users\avv>plaidbench keras mobilenet
c:\users\avv\appdata\local\continuum\anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Running 1024 examples with mobilenet, batch size 1
INFO:plaidml:Opening device "opencl_intel_intel(r)_hd_graphics_620.0"
Model loaded.
Compiling network...
Warming up ...
Main timing
Example finished, elapsed: 2.9983203411102295 (compile), 69.59246873855591 (execution), 0.067961395252496 (execution per example)
Correctness: PASS, max_error: 1.3988229511596728e-05, max_abs_error: 6.966292858123779e-07, fail_ratio: 0.0

Then I'm trying to use it as the keras backend in R with the model from https://tensorflow.rstudio.com/blog/keras-fraud-autoencoder.html and I get the following error:

It really happens with any model.

Session info ---------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, mingw32             
 ui       RStudio (1.1.442)           
 language (EN)                        
 collate  Spanish_Spain.1252          
 tz       Europe/Berlin               
 date     2018-06-04                  

Packages -------------------------------------------------------------------------------------------------------------------------------------------------
 package     * version    date       source                         
 assertthat    0.2.0      2017-04-11 CRAN (R 3.4.4)                 
 backports     1.1.2      2017-12-13 CRAN (R 3.4.3)                 
 base        * 3.4.4      2018-03-15 local                          
 base64enc     0.1-3      2015-07-28 CRAN (R 3.4.1)                 
 bindr         0.1.1      2018-03-13 CRAN (R 3.4.4)                 
 bindrcpp    * 0.2.2      2018-03-29 CRAN (R 3.4.4)                 
 broom         0.4.4      2018-03-29 CRAN (R 3.4.4)                 
 cellranger    1.1.0      2016-07-27 CRAN (R 3.4.4)                 
 cli           1.0.0      2017-11-05 CRAN (R 3.4.4)                 
 colorspace    1.3-2      2016-12-14 CRAN (R 3.4.4)                 
 compiler      3.4.4      2018-03-15 local                          
 crayon        1.3.4      2017-09-16 CRAN (R 3.4.4)                 
 data.table  * 1.10.4-3   2017-10-27 CRAN (R 3.4.4)                 
 datasets    * 3.4.4      2018-03-15 local                          
 devtools      1.13.5     2018-02-18 CRAN (R 3.4.3)                 
 digest        0.6.15     2018-01-28 CRAN (R 3.4.3)                 
 dplyr       * 0.7.4      2017-09-28 CRAN (R 3.4.3)                 
 forcats     * 0.3.0      2018-02-19 CRAN (R 3.4.4)                 
 foreign       0.8-69     2017-06-22 CRAN (R 3.4.4)                 
 ggplot2     * 2.2.1      2016-12-30 CRAN (R 3.4.4)                 
 glue          1.2.0      2017-10-29 CRAN (R 3.4.4)                 
 graphics    * 3.4.4      2018-03-15 local                          
 grDevices   * 3.4.4      2018-03-15 local                          
 grid          3.4.4      2018-03-15 local                          
 gtable        0.2.0      2016-02-26 CRAN (R 3.4.4)                 
 haven         1.1.1      2018-01-18 CRAN (R 3.4.4)                 
 here          0.1        2017-05-28 CRAN (R 3.4.4)                 
 hms           0.4.2      2018-03-10 CRAN (R 3.4.4)                 
 htmltools     0.3.6      2017-04-28 CRAN (R 3.4.4)                 
 htmlwidgets   1.0        2018-01-20 CRAN (R 3.4.4)                 
 httr          1.3.1      2017-08-20 CRAN (R 3.4.4)                 
 jsonlite      1.5        2017-06-01 CRAN (R 3.4.4)                 
 keras       * 2.1.5.9001 2018-04-15 Github (rstudio/keras@50bb9f5) 
 lattice       0.20-35    2017-03-25 CRAN (R 3.4.4)                 
 lazyeval      0.2.1      2017-10-29 CRAN (R 3.4.4)                 
 lubridate     1.7.4      2018-04-11 CRAN (R 3.4.4)                 
 magrittr      1.5        2014-11-22 CRAN (R 3.4.4)                 
 Matrix        1.2-12     2017-11-30 CRAN (R 3.4.4)                 
 memoise       1.1.0      2017-04-21 CRAN (R 3.4.4)                 
 methods     * 3.4.4      2018-03-15 local                          
 mnormt        1.5-5      2016-10-15 CRAN (R 3.4.1)                 
 modelr        0.1.1      2017-07-24 CRAN (R 3.4.4)                 
 munsell       0.4.3      2016-02-13 CRAN (R 3.4.4)                 
 nlme          3.1-131.1  2018-02-16 CRAN (R 3.4.4)                 
 parallel      3.4.4      2018-03-15 local                          
 pillar        1.2.1      2018-02-27 CRAN (R 3.4.4)                 
 pkgconfig     2.0.1      2017-03-21 CRAN (R 3.4.4)                 
 plotly      * 4.7.1      2017-07-29 CRAN (R 3.4.4)                 
 plyr          1.8.4      2016-06-08 CRAN (R 3.4.4)                 
 psych         1.8.3.3    2018-03-30 CRAN (R 3.4.4)                 
 purrr       * 0.2.4      2017-10-18 CRAN (R 3.4.4)                 
 R6            2.2.2      2017-06-17 CRAN (R 3.4.4)                 
 Rcpp          0.12.17    2018-05-18 CRAN (R 3.4.4)                 
 readr       * 1.1.1      2017-05-16 CRAN (R 3.4.4)                 
 readxl        1.0.0      2017-04-18 CRAN (R 3.4.4)                 
 reshape2      1.4.3      2017-12-11 CRAN (R 3.4.4)                 
 reticulate    1.7        2018-04-28 CRAN (R 3.4.4)                 
 rlang         0.2.0      2018-02-20 CRAN (R 3.4.4)                 
 rprojroot     1.3-2      2018-01-03 CRAN (R 3.4.4)                 
 rstudioapi    0.7        2017-09-07 CRAN (R 3.4.4)                 
 rvest         0.3.2      2016-06-17 CRAN (R 3.4.4)                 
 scales        0.5.0      2017-08-24 CRAN (R 3.4.4)                 
 stats       * 3.4.4      2018-03-15 local                          
 stringi       1.1.7      2018-03-12 CRAN (R 3.4.4)                 
 stringr     * 1.3.0      2018-02-19 CRAN (R 3.4.4)                 
 tensorflow    1.5        2018-01-17 CRAN (R 3.4.4)                 
 tfruns        1.3        2018-05-24 Github (rstudio/tfruns@03fb652)
 tibble      * 1.4.2      2018-01-22 CRAN (R 3.4.4)                 
 tictoc      * 1.0        2014-06-17 CRAN (R 3.4.1)                 
 tidyr       * 0.8.0      2018-01-29 CRAN (R 3.4.4)                 
 tidyverse   * 1.2.1      2017-11-14 CRAN (R 3.4.4)                 
 tools         3.4.4      2018-03-15 local                          
 utils       * 3.4.4      2018-03-15 local                          
 viridisLite   0.3.0      2018-02-01 CRAN (R 3.4.4)                 
 whisker       0.3-2      2013-04-28 CRAN (R 3.4.4)                 
 withr         2.1.2      2018-03-15 CRAN (R 3.4.4)                 
 xml2          1.2.0      2018-01-24 CRAN (R 3.4.4)                 
 yaml          2.1.19     2018-05-01 CRAN (R 3.4.4)                 
 zeallot       0.1.0      2018-01-28 CRAN (R 3.4.4)  

When you run keras in R, keep in mind that this function activates a specific conda environment:

library(keras)
reticulate::py_config()

Result:

python:         C:\tools\Anaconda3\envs\r-tensorflow\python.exe

This means that if you want to use additional python libaries with keras, you have to install these in the same conda environment.

Try using the conda_install() function to install additional libraries.

?conda_install()

I haven't tried this, but the call will be something like this:

reticulate::conda_install("r-tensorflow", packages = "plaidml")

Hi @andrie, thanks for your quick answer.

Have you review the docs about using PlaidML backend with Keras R Interface to Keras • keras3?

It says that you can use any previous environment where you have PlaidML configured.

Also, PlaidML is not available in the conda repositories.

Any other ideas?

Thanks.

1 Like