Running Models - Interactml/iml-unreal GitHub Wiki

Running a Model

This is where you actually put the trained models to good use. By running them you can recognise patterns in input parameters and be notified in the form of pre-defined output values.

🧠 Trained Model + 🕹ī¸ Live Parameters --> 🎚ī¸ Outputs

The Run Node

To run a Model you use the Machine Learning Robot blueprint node with the required model plugged into it (or directly selected in the node input drop-down UI).


Hooking up a Model asset variable

Setting a specific Model asset

See Asset Types for information on Model assets 👉

See Model Types to find out about the models available 👉

Parameters

Just like when Recording Examples, input parameters are provided in the form of a structure type (called "InteractMLParameters") and can be built using the "Collect All The Things!" Blueprint node from a variety of input data types (int, float, bool, vector, etc.).

It is these parameters that are compared with the trained state of the model when it is running.

See Collecting Parameters to learn about sourcing parameter values 👉

User Interaction

Running a model can be user triggered but would normally run based on some scripted logic:

  1. Continuous - providing constant output values that change as the input parameters change (e.g. monitoring player position)
  2. Triggered - only run when some application state requires a new output (e.g. a photo was taken)
  3. Burst - run on an accumulated set of input parameters in one go (e.g. a handwritten gesture was completed)

Continuous Run

Applies To: Classification and Regression models only.

The simplest form of this is just to set the Run input of the node true permanently. This means it will always run and be continuously evaluating the input parameters to produce output values.

Triggered Run

Applies To: All model types.

A more advanced form of running is to only run in response to an event, the simplest example of which would be the user pressing a button or key.

For Classification and Regression models this would run continuously whilst the key is held down. For Dynamic Timewarp input parameters are accumulated while the key is down and the model run on them when the key is released. You might also run the model when some in-world criteria is met such as the user moving into a trigger zone or perhaps on a timer.

Burst Run

Applies To: Dynamic Timewarp model only.

For the Dynamic Timewarp model, a series of input parameters is needed. A series is recorded whilst the Run input is true and the accumulated values are fed into the model to produce an output only when the Run input returns to false. This is matched against the trained series of parameters to find one that resembles the way the parameters changed over time. Once the recognition phase of the run has completed, a new output is present at the Output pin.

This could be triggered from a button press, but it's likely that more complicated logic will be required to decide when to start/stop recording ready for the model to run. The DynamicTimewarp_Gesture level in the Demo Project does this based on the mouse button being pressed, mouse movement, and a small delay to allow for multiple strokes within a single gesture.

Results

When a model has run, the result of the recognition process is presented at the Output pin:

Output Type

By default a model has a simple numerical output, but if it has been trained on data with a composite output type, the Machine Learning Robot node needs it's output type to be set to the matching Label type definition.

See Labels for more on composite outputs 👉

💡 It is important that the Run node Output pin type matches the Recording node Expected Output pin type for the Training Set the Model was trained on. If they don't, unpredictable results or failure to do anything will result. Check the Unreal Output Log window for any relevant error messages to help diagnose such an issue.

Output Values

The output values can be used to drive a variety of things, here are some examples for the simple numerical and composite label types:


Simple numerical output driving a text display

Composite label output driving the colour of a light

💡 For Regression, numerical output types are interpolated and produce a continuous range of values. This can be useful in conjunction with the composite Label definitions and Label Tables for driving all sorts of objects and systems directly. See Labels for more info 👉

Background Running

Models can be run asynchronously as a background task to free up the engine to continue operating and avoid any stalls or stuttering of your application. Depending on the type of model, the complexity of its training, and the number of output values, some model runs can take a bunch of milliseconds to complete.

See Model Types for performance information 👉

To avoid this, a run node can be switched to Background Operation in the details panel for the node.

This changes the nodes outputs slightly, adding two new pins.

  • Running - Is the model currently running? (true whilst run ongoing in the background)
  • Completed - Execution output that is fired for one tick after the run has completed

These can be hooked up to provide feedback to the user or trigger a sequence of events that follow a new output value becoming available.


👈 Training Models | 🏠 Home | Training Set 👉

⚠ī¸ **GitHub.com Fallback** ⚠ī¸