Porting a machine learning model from GitHub to RunwayML in 5 minutes 🍅

You can take an existing machine learning model, written in any deep learning framework, and add it to Runway with just a few lines of code. Learn how to do it here 👇

Cristobal Valenzuela
Runway
4 min readJul 30, 2019

--

Running Progressive Growing of GANs (PGAN) in Runway 🦄

For this short tutorial, we will be porting Progressive Growing of GANs (PGAN), an open-source model that creates high-quality images, available in the Pytorch Hub and GitHub. The code to run and generate an image with a pre-trained PGAN checkpoint from the Pytorch hub is short and simple, let’s review the base code we will be using:

Sample code to generate an image using a pre-trained PGAN checkpoint from the Pytorch Hub

Creating a Runway model

Let’s start by creating a file called runway_model.py, pasting our sample code from above and adding the runway-python SDK. We will also add numpy for some minor post-processing. (Be sure to install the Runway python SDK with pip install runway-python first!)

Adding the Runway SDK

Now, let’s wrap the loading of the model with Runway’s setup decorator. The setup decorator will only run once, at the beginning of the inference process, and should always return a model:

The setup function is used to load the checkpoints and render any UI elements in Runway that will be part of the initial model configuration. In this case, just by defining a runway.category and adding the default PGAN checkpoint as options we get this nice UI in Runway ✨:

Adding a nice searchable checkpoint element to our model đź’…

Next, let’s wrap the inference part of the model in a Runway command function. A command is a special function that is used to define a way you can interact with a model. This will allow you to define input and output types.

A command decorator function is built with three options:

  • The name of the command: in this case generate ,
  • The input type: PGAN generates images from a noise vector of length 512, so we need to provide it with the runway.vector input type.
  • The output type: In this case, the output will be an image type.

Defining a command that takes a vector as input creates a vector grid interface to navigate the latent space of PGAN and show the resulting image as the output.

Now, we are ready to add our model to Runway! Let’s create a runway.yml file, next to our runway_model.py defining how our model should run:

This file provides instructions for defining an environment, installing dependencies, and running your model in a standard and reproducible manner.

That’s it! Let’s create a GitHub repo and push our code to GitHub and get our model in Runway.

Adding the model to Runway via GitHub

Runway can take any existing repository that contains a runway_model.py and runway.yml file and create a model that you can use and share in Runway.

Open Runway and click “From GitHub” in the lower-left corner of the models' directory, select your repository and follow the steps to add a model.

Add any model from GitHub!

Once the model has been added, Runway will start the build process automatically. You can check the process on the versions tab. Every time you push a commit to GitHub, Runway creates a new version of your model. 🎩

Every time you push a commit to GitHub, Runway creates a new version of your model.

Once the model has been built, you can add it to your workspace and start exploring! 🦄

Running Progressive Growing of GANs (PGAN) in Runway 🦄

If you want to learn more about how Runway works, check out the links below. We would love to get your feedback!

Links

--

--

Cristobal Valenzuela
Runway
Editor for

Building creative tools with artificial intelligence | Co-Founder of @runwayml (We’re hiring!) | prev Research Resident @ITP_NYU — @ml5js