The generator.py

The generator loads the weights onto the GPU and turns an image into a mesh. Expose a class with a generate() method:

generator.py
from modly import Generator   # interface provided by Modly

class MyGenerator(Generator):

    def load(self, variant):
        # Load the variant's weights onto the GPU
        self.model = load_weights(variant["url"])

    def generate(self, image):
        # image (PIL) -> 3D mesh
        mesh = self.model.run(image)
        return mesh   # trimesh object / .glb file

List Python dependencies in requirements.txt — Modly installs them automatically when the extension is added.

← Previous
The manifest.json
Next →
Test & Publish