docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IWorker

    An interface that allows you to execute neural networks (models).

    IWorker abstracts implementation details on different hardware devices such as the CPU and the GPU. IWorker lets you do the following:

    • Specify inputs.
    • Schedule the work.
    • Get outputs.

    Internally, IWorker translates the neural network from a Model into a set of operations, then sends the operations to the hardware device for asynchronous execution.

    Use WorkerFactory.CreateWorker or Model.CreateWorker to create a new instance of a worker.

    Inherited Members
    IDisposable.Dispose()
    Namespace: Unity.Sentis
    Assembly: Unity.Sentis.dll
    Syntax
    public interface IWorker : IDisposable

    Properties

    scheduleProgress

    Returns the proportion of the model scheduled for execution since the last call to ExecuteLayerByLayer.

    Returns 0.0 after you call ExecuteLayerByLayer. Returns 1.0 when the model is fully scheduled.

    The value increases each time you iterate on the IEnumerator that ExecuteLayerByLayer returns.

    Declaration
    float scheduleProgress { get; }
    Property Value
    Type Description
    float

    Methods

    Execute()

    Schedules the execution of the model on the worker. This is non-blocking.

    Declaration
    IWorker Execute()
    Returns
    Type Description
    IWorker

    The IWorker.

    Execute(IDictionary<string, Tensor>)

    Sets multiple tensors as the inputs of the model and schedules execution of the model. This is non-blocking.

    Declaration
    IWorker Execute(IDictionary<string, Tensor> inputTensors)
    Parameters
    Type Name Description
    IDictionary<string, Tensor> inputTensors

    The tensors to use as the inputs of the model as a dictionary mapping input names to tensors.

    Returns
    Type Description
    IWorker

    The IWorker.

    Execute(Tensor)

    Sets a tensor as the default input of the model and schedules the execution of the model on the worker. This is non-blocking. For models with more than one input this sets the first input.

    Declaration
    IWorker Execute(Tensor inputTensor)
    Parameters
    Type Name Description
    Tensor inputTensor

    The tensor to set to the default input of the model.

    Returns
    Type Description
    IWorker

    The IWorker.

    ExecuteLayerByLayer()

    Schedules the execution of the model one layer at a time. This is non-blocking.

    To schedule the execution of the next layer of the model, call MoveNext on the IEnumerator object this method returns.

    Declaration
    IEnumerator ExecuteLayerByLayer()
    Returns
    Type Description
    IEnumerator

    The IEnumerator for scheduling manual execution.

    ExecuteLayerByLayer(IDictionary<string, Tensor>)

    Sets multiple tensors as the inputs of the model and schedules execution of the model one layer at a time. This is non-blocking.

    To schedule execution of the next layer of the model, call MoveNext on the IEnumerator object this method returns.

    Declaration
    IEnumerator ExecuteLayerByLayer(IDictionary<string, Tensor> inputTensors)
    Parameters
    Type Name Description
    IDictionary<string, Tensor> inputTensors

    The tensors to use as the inputs of the model as a dictionary mapping input names to tensors.

    Returns
    Type Description
    IEnumerator

    The IEnumerator for scheduling manual execution.

    ExecuteLayerByLayer(Tensor)

    Sets a tensor as the default input of the model and schedules execution of the model one layer at a time. This is non-blocking. For models with more than one input this sets the first input.

    To schedule execution of the next layer of the model, call MoveNext on the IEnumerator object this method returns.

    Declaration
    IEnumerator ExecuteLayerByLayer(Tensor inputTensor)
    Parameters
    Type Name Description
    Tensor inputTensor

    The tensor to set to the default input of the model.

    Returns
    Type Description
    IEnumerator

    The IEnumerator for scheduling manual execution.

    GetBackend()

    Returns the backend used for execution.

    Declaration
    IBackend GetBackend()
    Returns
    Type Description
    IBackend

    The IBackend used.

    PeekOutput()

    Returns a reference to the default output tensor. This is non-blocking.

    For models with more than one output this returns a reference to the first output tensor.

    The reference is valid only until you call Execute() or Dispose() on the worker.

    Declaration
    Tensor PeekOutput()
    Returns
    Type Description
    Tensor

    The output tensor reference.

    PeekOutput(string)

    Returns a reference to the default output tensor. This is non-blocking.

    For models with more than one output this returns a reference to the first output tensor.

    The reference is valid only until you call Execute() or Dispose() on the worker.

    Declaration
    Tensor PeekOutput(string name)
    Parameters
    Type Name Description
    string name

    The name of the output tensor to peek.

    Returns
    Type Description
    Tensor

    The output tensor reference.

    SetInput(string, Tensor)

    Sets a tensor as a named input of the model.

    Declaration
    void SetInput(string name, Tensor inputTensor)
    Parameters
    Type Name Description
    string name

    The name of the input to set.

    Tensor inputTensor

    The tensor to set as the input.

    TakeOutputOwnership()

    Takes ownership of the default output tensor. This is non-blocking.

    For models with more than one output this returns a reference to the first output tensor.

    Declaration
    Tensor TakeOutputOwnership()
    Returns
    Type Description
    Tensor

    The output tensor.

    TakeOutputOwnership(string)

    Takes ownership of an output tensor with a given name. This is non-blocking.

    Declaration
    Tensor TakeOutputOwnership(string name)
    Parameters
    Type Name Description
    string name

    The name of the output tensor to take ownership of.

    Returns
    Type Description
    Tensor

    The output tensor.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)