Skip to main content
Version: 0.1

Get Started

In this tutorial, we will install the tools, set up the build environment, create your first PyTorch Live project and see it running in an emulator or your phone.

PyTorch Live's command line tool torchlive-cli will automate most of the setup process. Here's a sneak peek of the PyTorch Live app when the setup is complete:

Let's get started!

Prerequisites

Installation

Setting up the build environment can be tedious and difficult. PyTorch Live provides a setup routine to install the required dependencies automatically for you. It will try to install the following libraries and tools:

note

The PyTorch Live CLI currently does not support the Apple M1 chipset. However, there are instructions by the community for how to install React Native on an Apple M1 without Rosetta.

Here's what you will see during the automatic setup process:

note

Check out the manual installation process if your operating system is Windows or Linux or if the PyTorch Live command line tool torchlive-cli fails for you!

Now let's run this setup-dev command and get the build environment ready for development:

❯ npx torchlive-cli setup-dev
note

You will need administrator access (using sudo) to run this command. It may take 20 minutes to complete, depending on your laptop configurations.

You only need to run this once to install the dependencies. No need to run this again to start a new project.

Check installations

If everything goes well, the terminal will looks similar to the following output. If you run into any issues, please check the FAQ.

Expected output
❯ npx torchlive-cli setup-dev
_ _ _ _
| |_ ___ _ __ ___| |__ | (_)_ _____
| __/ _ \| '__/ __| '_ \| | \ \ / / _ \
| || (_) | | | (__| | | | | |\ V / __/
\__\___/|_| \___|_| |_|_|_| \_/ \___|

torchlive version 0.0.2-alpha.5
Password:
↓ Homebrew (3.1.7) [SKIPPED]
✔ OpenJDK (1.8.0)
✔ Watchman (4.9.0)
↓ Node (16.1.0) [SKIPPED]
✔ Yarn (1.22.10)
✔ Android SDK
✔ Android SDK Manager
✔ Android Emulator
✔ Android Emulator Skin

Check Python version

Currently, python3 is required to bootstrap PyTorch Mobile models used in the example app. In macOS Catalina and Big Sur, python3 is pre-installed. Run the following command to check if python3 is installed:

❯ python3 --version
Python 3.9.4
note

The version installed on your machine might be slightly different, but should at least be version 3.7 or above.

If python3 is not installed, you can install it via Homebrew on macOS:

brew install python3

Create a New Project

Now that we have set up the build environment, let's create a new PyTorch Live project and see it running in an emulator or on your device. It's as simple as running two commands using the torchlive-cli tool.

Initialize Your Project

For PyTorch Live beta, we provide a bootstrap React Native app, packed with AI demos and practical examples. Use the npx torchlive-cli init command to initialize your first PyTorch Live project.

npx torchlive-cli init MyFirstProject

Behind the scene, the tool created a new React Native project and configured the build tools for mobile development. It also added a couple on-device AI models as well as examples to run them.

This is what you should see after the project is initialized:

Expected output
❯ npx torchlive-cli init MyFirstProject
_ _ _ _
| |_ ___ _ __ ___| |__ | (_)_ _____
| __/ _ \| '__/ __| '_ \| | \ \ / / _ \
| || (_) | | | (__| | | | | |\ V / __/
\__\___/|_| \___|_| |_|_|_| \_/ \___|

torchlive version 0.0.2-alpha.5
✔ project MyFirstProject

Run Your Project

We are almost there. Now let's navigate to the newly created PyTorch Live project folder:

cd MyFirstProject

And run the PyTorch Live project on Android:

npx torchlive-cli run-android

By default, the PyTorch Live app will run in an emulator. You can also run it on your own phone which may improve performance. To see it on your phone, plug it into your computer and enable Android's developer mode.

note

On Android 4.1 and lower, the Developer options screen is available by default. On Android 4.2 and higher, you must enable this screen. To enable developer options, go to Settings > Developer options and tap the Build Number option 7 times.

More details are on the Android configure on-device developer options.

Welcome to PyTorch Live

Start by trying out the various Examples in the app. When you are ready to experiment, take a look at the Toolbox demos and follow along with a tutorial: recognizing objects in photographs or answering questions about some text.

PyTorch Live is in beta. Your feedback will help us improve tremendously. Please file issues and share ideas on GitHub.

Show us what you've made with PyTorch Live by tagging #playtorch in your social media posts too.

Give us feedback