image | description | from | size | metrics | build status |
---|---|---|---|---|---|
reticulate | R-3.3.3, RStudio, Python 3.4.2, Anaconda and the reticulate package |
rocker/rstudio:3.3.3 | |||
tensorflowr | Adds tensorflow and keras, installed in python virtualenv and conda environment | andrie/reticulate |
This repository will be useful to test any R code that connects to Python using the reticulate
package. The repository uses rocker/rstudio:3.3.3 as the base, and adds:
- Python 3.4.2
- Anaconda
- R packages for:
- Typical development tools, including
devtools
,roxygen2
andrmarkdown
Rcpp
reticulate
, an interface layer between R and python, installed from CRAN
- Typical development tools, including
This repository builds two environments that contain tensorflow
(tensorflow.org) and keras
(keras.io):
-
Python virtual environment, containing:
- At location
/tensorflow
- Python 3.4.2
tensorflow
,keras
andh5py
- Activate this environment using
source /tensorflow/bin/activate
- A CRAN mirror pointing to a static MRAN snapshot of 2017-06-01
- At location
-
Anaconda environment (conda env) containing:
- conda environment
tensorflow
- Python 3.4.2
tensorflow
,keras
andh5py
- Activate this environment using
source activate tensorflow
- conda environment
-
The R package
reticulate
(available on CRAN) communicates between R and python. -
The
reticulate
package needs to know where python is installed, so the repository writes environment variables into theRenviron
file to configurereticulate
correctly:TENSORFLOW_PYTHON = "/tensorflow/bin/python" RETICULATE_PYTHON = "/tensorflow/bin/python"
To pull and build the image, use:
docker pull andrie/tensorflowr
Since the repository contains rocker/rstudio
, you can run RStudio in your web browser by pointing to https://localhost:8787 if you map the ports. The following line creates a container and names it tensorflowr
, so you can easily refer to this later.
docker run -d --name tensorflowr -p 8787:8787 andrie/tensorflowr
To execute code inside the running container:
docker exec -ti tensorflowr bash
To test tensorflow
, try the Hallo world
example from the tensorflow
R package:
library(tensorflow)
sess = tf$Session()
hello <- tf$constant('Hello, TensorFlow!')
sess$run(hello)
To test keras
, try the code from the kerasR
vignette:
library(kerasR)
mod <- Sequential()
mod$add(Dense(units = 50, input_shape = 13))
mod$add(Activation("relu"))
mod$add(Dense(units = 1))
keras_compile(mod, loss = 'mse', optimizer = RMSprop())
boston <- load_boston_housing()
X_train <- scale(boston$X_train)
Y_train <- boston$Y_train
X_test <- scale(boston$X_test)
Y_test <- boston$Y_test
keras_fit(mod, X_train, Y_train,
batch_size = 32, epochs = 200,
verbose = 1, validation_split = 0.1)
pred <- keras_predict(mod, normalize(X_test))
sd(as.numeric(pred) - Y_test) / sd(Y_test)
© Andrie de Vries