knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Although, Python and PyTorch can be installed directly from the R console, before start running
rTorch, I would recommend installing PyTorch first in a new Python or Python-Anaconda environment. Then, testing if PyTorch and Torchvision packages are imported alright. The advantage of doing it this way is that you define in advanced the base Python or Anaconda version to install. Although the same can be done from rTorch you will need to get familiar passing parameters through one its functions.
If you opt to install PyTorch from R, rTorch has functions that could help you install PyTorch from the R console.
This function is public and can be invoked with
This function will allow you to indicate (i) the Python version; (ii) the PyTorch version; (iii) the name of the conda environment; (iv) which channel (
nightly); (v) if you require CUDA (GPU) computation; (vi) additional packages such as
pandas; (vii) more.
install_pytorch( method = c("conda", "virtualenv", "auto"), conda = "auto", version = "default", envname = "r-torch", extra_packages = NULL, restart_session = TRUE, conda_python_version = "3.6", pip = FALSE, channel = "stable", cuda_version = NULL, dry_run = FALSE, ... )
If you prefer do it manually, use this example:
Create a conda environment with
conda create -n my-torch python=3.7 -y
Activate the new environment with
conda activate my-torch
Inside the new environment, install PyTorch and related packages with:
conda install python=3.6 pytorch torchvision matplotlib pandas -c pytorch
Note: If you you don't specify a version,
condawill install the latest PyTorch. As of this writing (August-September 2020), the latest PyTorch version is 1.6.
Alternatively, you could create and install a conda environment a specific PyTorch version with:
conda create -n my-torch python=3.6 pytorch=1.3 torchvision matplotlib pandas -c pytorch -y
conda will resolve the dependencies and versions of the other packages automatically, or let you know your options.
pandas are not really necessary, but I was asked if
pandas would work in PyTorch. Then, I decided to put them for testing and experimentation. They both work.
In rTorch there is an automatic detection of Python built in in the package that will ask you to install
Miniconda first if you don't have any Python installed in your machine. For instance, in
macOS, Miniconda will be installed under
After Miniconda is installed, you could proceed to install the flavor or PyTorch you want, and the packages you want, with a command like this:
rTorch:::install_conda(package="pytorch=1.4", envname="r-torch", conda="auto", conda_python_version = "3.6", pip=FALSE, channel="pytorch", extra_packages=c("torchvision", "cpuonly", "matplotlib", "pandas"))
The command above will install the stable PyTorch 1.4 version on Python 3.6, including three additional packages:
NOTE. My experience with
Minicondais spotty and not 100% reliable, specially in macOS. I would strongly recommend using full conda for your PyTorch installation.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.