Skip to content

MLP Mojo

Structs

struct MLP

A Mojo wrapper for a PyTorch MLP model using Python interop.

For example usage, see TorchMlp.mojo in the Examples folder.

Traits: AnyType, Copyable, Movable, UnknownDestructibility

MLP Parameters

Name Type Default Description
input_size Int 2 The size of the input vector.
output_size Int 16 The size of the output vector.

MLP Functions

struct MLP . fn init

Initialize the MLP struct.

fn init Signature

__init__(out self, world: UnsafePointer[MMMWorld], file_name: String, namespace: Optional[String] = None, trig_rate: Float64 = 25)

fn init Arguments

Name Type Default Description
world UnsafePointer Pointer to the MMMWorld.
file_name String The path to the model file.
namespace Optional None Optional namespace for the Messenger.
trig_rate Float64 25 The rate in Hz at which to trigger inference.

fn init Returns : Self

Static Method

This is a static method.

struct MLP . fn reload_model

Reload the MLP model from a specified file.

fn reload_model Signature

reload_model(mut self: MLP[input_size, output_size], var file_name: String)

fn reload_model Arguments

Name Type Default Description
file_name String The path to the model file.

struct MLP . fn next

Function for Audio Thread. Call this function every sample in the audio thread. The MLP will only perform inference at the rate specified by trig_rate (and if inference_gate is True).

The model input is taken from model_input, and the output is written to model_output. fn next Signature

next(mut self: MLP[input_size, output_size])

Documentation generated with mojo doc from Mojo version 0.25.6.1