Declares the Python packages BirdNET needs to run on a GPU. Call it once at
the top of a script, before Python starts (loading a model, birdnet_sitrep()
and the birdnet_list_*() functions that use Python all start it): the
packages are resolved when Python starts, so afterwards it is too late and
the function errors (restart R and call it first).
Usage
birdnet_use_gpu(backend = c("pt", "pb"))Value
Invisibly returns TRUE. If RETICULATE_PYTHON points at your own
Python environment, birdnetR cannot install anything there: the function
warns and returns FALSE.
Details
Choose one backend per R session. TensorFlow ("pb") and PyTorch ("pt")
each bring their own CUDA libraries, and installing both can conflict, so
asking for the other backend later in the same session is an error.
Requirements by platform:
Linux,
"pt"(default): installsbirdnet[pt]. If the environment variableUV_TORCH_BACKENDis not set, it is set to"auto"so that uv picks the torch build matching your GPU driver. For AMD GPUs, set e.g.Sys.setenv(UV_TORCH_BACKEND = "rocm7.2")before callingbirdnet_use_gpu()(ROCm support is experimental).Linux,
"pb": installsbirdnet[and-cuda]. An NVIDIA driver and CUDA must already be installed on the system. TensorFlow 2.21.0 is left out, because it does not find the GPU.macOS (Apple silicon),
"pb": installsbirdnet[tf]plustensorflow-metal.
Any other combination (for example Windows) has no automatic setup and
errors; vignette("gpu", package = "birdnetR") shows how to set up your own
Python environment instead, and covers everything else about GPUs.
Afterwards, load a model for the chosen backend with
birdnet_load(backend = "pt") (or birdnet_load_perch(device = "GPU")) and
use device = "GPU" in birdnet_predict() and birdnet_encode().
Examples
if (FALSE) { # \dontrun{
# at the top of a script, before loading any model
birdnet_use_gpu("pt")
model <- birdnet_load("acoustic", "3.0", backend = "pt")
audio_file <- system.file("extdata", "soundscape.mp3", package = "birdnetR")
pred <- birdnet_predict(model, audio_file, device = "GPU")
# AMD GPU (experimental)
Sys.setenv(UV_TORCH_BACKEND = "rocm7.2")
birdnet_use_gpu("pt")
} # }
