Python

Keras installation in R

DS-Lee 2023. 4. 11. 08:45
# install the Tensorflow R package
install.packages("tensorflow")

# configure R with a Python installation
library(reticulate)
path_to_python <- install_python()
virtualenv_create("r-reticulate", python = path_to_python)

# install Tensorflow
library(tensorflow)
install_tensorflow(envname = "r-reticulate")

# install Keras
install.packages("keras")
library(keras)
install_keras(envname = "r-reticulate")

# === TEST ===
# configure reticulate
library(reticulate)
use_virtualenv("r-reticulate")

# use Tensorflow
library(tensorflow)
tf$constant("Hello Tensorflow!")

# use Keras
network <- keras_model_sequential() %>%
  layer_dense(units = 8, activation = "relu", input_shape = c(4)) %>%
  layer_dense(units = 1, activation = "linear")
summary(network)

 

Reference
[1] https://tensorflow.rstudio.com/install/

 

TensorFlow for R - Quick start

Prior to using the tensorflow R package you need to install a version of Python and TensorFlow on your system. Below we describe how to install to do this as well the various options available for customizing your installation. Note that this article princ

tensorflow.rstudio.com

[2] https://rstudio.github.io/reticulate/