MLComponent
ClassUsed to integrate machine learning models into a Lens.
- Available on all platforms
Index
Properties
Methods
Remarks
This component allows developers to use neural networks for processing inputs such as textures or data arrays to produce specific outputs, which could be in the form of processed textures or data alterations. The MLComponent relies on MLAsset that defines the neural network model used. It supports tasks like image classification, object detection, etc.
Example
//@input Asset.MLAsset model
var mlComponent = script.sceneObject.createComponent('MLComponent');
mlComponent.model = script.model;
Extends
Properties
autoRun
autoRun:
boolean
Runs the MLComponent automatically when the object or component it's on is enabled.
Since
Lens Scripting Version 161
Default Value
false
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
inferenceMode
inferenceMode:
InferenceMode
Controls the inference mode that MLComponent will run in. For example, GPU, CPU, etc.
Default Value
MachineLearning.InferenceMode.Auto
isBeingDestroyed
readonlyisBeingDestroyed:boolean
Returns true if this Component is currently being destroyed. Becomes true as soon as
destruction begins via Component#destroy or destruction of its owning SceneObject,
before any OnDestroyEvent callbacks fire.
Since
Lens Scripting Version 364
Example
if (!script.isBeingDestroyed) {
// Component is still fully alive
}
Inherited from
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
Component.isEnabledInHierarchy
model
model:
MLAsset
Binary ML model supplied by the user.
Default Value
null
onLoadingFailed
onLoadingFailed: (
error) =>void
Bind a function that is triggered when the component fails to load a model.
Parameters
| Parameter | Type |
|---|---|
error | string |
Returns
void
Default Value
null
onLoadingFinished
onLoadingFinished: () =>
void
Function that gets called when model loading is finished.
Returns
void
Default Value
null
onRunningFailed
onRunningFailed: (
error) =>void
Bind a function that is triggered when the component fails to run a model.
Parameters
| Parameter | Type |
|---|---|
error | string |
Returns
void
Default Value
null
onRunningFinished
onRunningFinished: () =>
void
Function that gets called when the model stops running.
Returns
void
Default Value
null
renderOrder
renderOrder:
number
Render order of the MLComponent.
Default Value
0
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
state
readonlystate:ModelState
Returns the current status of the neural network model.
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
build()
build(
placeholders):void
Builds the MLComponent model when all placeholders are determined. Config is an array of Input and Output placeholders.
Parameters
| Parameter | Type |
|---|---|
placeholders | BasePlaceholder[] |
Returns
void
buildAsync()
buildAsync(
placeholders):Promise<void>
Build the MLComponent asynchronously.
Parameters
| Parameter | Type |
|---|---|
placeholders | BasePlaceholder[] |
Returns
Promise<void>
Since
Lens Scripting Version 323
cancel()
cancel():
void
Stops running the MLComponent. The onRunningFinished callback will not be executed.
Returns
void
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getInput()
getInput(
name):InputPlaceholder
Returns the InputPlaceholder with the matching name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
getInputs()
getInputs():
InputPlaceholder[]
Returns an array of InputPlaceholders of the MLComponent's model with default settings. Returns empty array if the model asset is not set.
Returns
Since
Lens Scripting Version 143
getOutput()
getOutput(
name):OutputPlaceholder
Returns the OutputPlaceholder with the matching name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
getOutputs()
getOutputs():
OutputPlaceholder[]
Returns an array of OutputPlaceholders of MLComponent's model with default settings. Returns empty array if the model is not set.
Returns
Since
Lens Scripting Version 143
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getScheduledEnd()
getScheduledEnd():
FrameTiming
Returns the end time of the scheduled MLComponent run.
Returns
getScheduledStart()
getScheduledStart():
FrameTiming
Returns the start time of the scheduled MLComponent run.
Returns
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<MLComponent>
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<MLComponent>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isRecurring()
isRecurring():
boolean
Returns true if running is requested on each frame.
Returns
boolean
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
runImmediate()
runImmediate(
sync):void
Runs the MLComponent once.
Parameters
| Parameter | Type |
|---|---|
sync | boolean |
Returns
void
runScheduled()
runScheduled(
recurring,startTiming,endTiming):void
Schedules the MLComponent to run at the start timing and terminate at the end timing. The scheduled running will recur if recurring is true.
Parameters
| Parameter | Type |
|---|---|
recurring | boolean |
startTiming | FrameTiming |
endTiming | FrameTiming |
Returns
void
stop()
stop():
void
Stops running the MLComponent.
Returns
void
waitOnLoading()
waitOnLoading():
void
If loading asynchronously, makes the entire system wait until loading is finished.
Returns
void
waitOnRunning()
waitOnRunning():
void
If running asynchronously, makes the entire system wait until the last run is finished.
Returns
void