Update, April 2022: As of now, you will no longer be able to port new models to Runway or update existing models. Models which you have already ported will remain available for the foreseeable future.
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:
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!)
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 āØ:
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:
generate
Ā ,runway.vector
Ā input 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.
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.
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. š©
Once the model has been built, you can add it to your workspace and start exploring! š¦
If you want to learn more about how Runway works, check out the links below. We would love to get your feedback!