Setting Up Keras and TensorFlow in R
Install the keras R package, configure a Python backend, and verify setup.
Deep Learning in R with Keras
The keras R package provides a high-level interface to TensorFlow. It is maintained by Posit (formerly RStudio) and mirrors the Python Keras API closely. R keras uses reticulate to call Python TensorFlow under the hood, so you get the full power of TensorFlow with R syntax.
# Install the R package from CRAN
# install.packages('keras')
# Then install TensorFlow Python environment
library(keras)
install_keras() # creates a Python venv with TF installed
# For GPU-enabled TensorFlow:
# install_keras(tensorflow = 'gpu')install_keras() and Backends
install_keras() creates a dedicated Python environment (Miniconda or virtualenv) and installs TensorFlow and its dependencies. You can specify the TensorFlow version, the Python version, and whether to install CPU or GPU support. By default it installs the latest stable CPU version.
library(keras)
# Install specific TF version in a custom env
install_keras(
method = 'conda',
envname = 'r-keras-tf2',
tensorflow = '2.15',
version = 'default'
)
# Check which Python environment is active
reticulate::py_config()All lessons in this course
- Setting Up Keras and TensorFlow in R
- Building Sequential Models
- Convolutional Neural Networks Basics
- Training, Validation, and Preventing Overfitting