docs.unity3d.com
    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
    Syntax
    public interface IWorker : IDisposable

    Properties

    scheduleProgress

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

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

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

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

    Methods

    Execute()

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

    Declaration
    IWorker Execute()
    Returns
    Type Description
    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

    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

    FlushSchedule(Boolean)

    Schedules the execution of the part of the model that hasn't been scheduled yet. This is non-blocking.

    Declaration
    void FlushSchedule(bool blocking = false)
    Parameters
    Type Name Description
    Boolean blocking

    When the value is true, the method blocks further code until the model finishes executing.

    GetOps()

    Declaration
    IOps GetOps()
    Returns
    Type Description
    IOps

    PeekOutput(Boolean)

    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.

    If you want to dispose of the worker but keep the tensor, use CopyOutput() instead, or use TakeOwnership() on the output tensor.

    Declaration
    Tensor PeekOutput(bool prepareCacheForAccess = false)
    Parameters
    Type Name Description
    Boolean prepareCacheForAccess

    Schedules a non-blocking download from the GPU to the CPU.

    Returns
    Type Description
    Tensor

    PeekOutput(String, Boolean)

    Returns a reference to an output tensor with a given name. This is non-blocking.

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

    If you want to dispose of the worker but keep the tensor, use CopyOutput() instead, or use TakeOwnership() on the output tensor.

    Declaration
    Tensor PeekOutput(string name, bool prepareCacheForAccess = false)
    Parameters
    Type Name Description
    String name

    The name of the output tensor to peek.

    Boolean prepareCacheForAccess

    Whether to schedule a non-blocking download to the CPU.

    Returns
    Type Description
    Tensor

    PrepareForInput(IDictionary<String, TensorShape>)

    Prepares the worker to execute the model using inputs of given shapes.

    Declaration
    void PrepareForInput(IDictionary<string, TensorShape> inputShapes)
    Parameters
    Type Name Description
    IDictionary<String, TensorShape> inputShapes

    A dictionary mapping input names to tensor shapes.

    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.

    SetInput(Tensor)

    Sets a tensor as the default input of the model. For models with more than one input this sets the first input.

    Declaration
    void SetInput(Tensor inputTensor)
    Parameters
    Type Name Description
    Tensor inputTensor

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

    StartManualSchedule()

    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 StartManualSchedule()
    Returns
    Type Description
    IEnumerator

    StartManualSchedule(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 StartManualSchedule(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

    StartManualSchedule(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 StartManualSchedule(Tensor inputTensor)
    Parameters
    Type Name Description
    Tensor inputTensor

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

    Returns
    Type Description
    IEnumerator

    Summary()

    Returns a summary of the execution of the model.

    Declaration
    string Summary()
    Returns
    Type Description
    String

    Extension Methods

    WorkerExtensions.CopyOutput(IWorker)
    WorkerExtensions.CopyOutput(IWorker, String)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • scheduleProgress
    • Methods
      • Execute()
      • Execute(IDictionary<String, Tensor>)
      • Execute(Tensor)
      • FlushSchedule(Boolean)
      • GetOps()
      • PeekOutput(Boolean)
      • PeekOutput(String, Boolean)
      • PrepareForInput(IDictionary<String, TensorShape>)
      • SetInput(String, Tensor)
      • SetInput(Tensor)
      • StartManualSchedule()
      • StartManualSchedule(IDictionary<String, Tensor>)
      • StartManualSchedule(Tensor)
      • Summary()
    • Extension Methods
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023