Class GenericWorker
Represents a generic implementation of an IWorker.
Inherited Members
Namespace: Unity.Sentis
Assembly: Unity.Sentis.dll
Syntax
public class GenericWorker : IWorker, IDisposable
Constructors
GenericWorker(Model, IBackend, IModelStorage, bool)
Initializes and returns an instance of GenericWorker
for the specified model
and ops
.
Declaration
public GenericWorker(Model model, IBackend backend, IModelStorage vars, bool takeoverWeights = false)
Parameters
Type | Name | Description |
---|---|---|
Model | model | The model to execute. |
IBackend | backend | The backend to use for execution. |
IModelStorage | vars | The stored tensor variables to use for execution. |
bool | takeoverWeights | Whether to allow the worker to take ownership of the model weights during execution. |
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
public float scheduleProgress { get; }
Property Value
Type | Description |
---|---|
float |
Methods
Dispose()
Disposes of the worker and any associated memory.
Declaration
public void Dispose()
Execute()
Schedules the execution of the model on the worker. This is non-blocking.
Declaration
public IWorker Execute()
Returns
Type | Description |
---|---|
IWorker | The |
Execute(IDictionary<string, Tensor>)
Sets multiple tensors as the inputs of the model and schedules execution of the model. This is non-blocking.
Declaration
public IWorker Execute(IDictionary<string, Tensor> inputs)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<string, Tensor> | inputs |
Returns
Type | Description |
---|---|
IWorker | The |
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
public IWorker Execute(Tensor input)
Parameters
Type | Name | Description |
---|---|---|
Tensor | input |
Returns
Type | Description |
---|---|
IWorker | The |
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
public IEnumerator ExecuteLayerByLayer()
Returns
Type | Description |
---|---|
IEnumerator | The |
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
public IEnumerator ExecuteLayerByLayer(IDictionary<string, Tensor> inputs)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<string, Tensor> | inputs |
Returns
Type | Description |
---|---|
IEnumerator | The |
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
public IEnumerator ExecuteLayerByLayer(Tensor input)
Parameters
Type | Name | Description |
---|---|---|
Tensor | input |
Returns
Type | Description |
---|---|
IEnumerator | The |
~GenericWorker()
Finalizes the GenericWorker
.
Declaration
protected ~GenericWorker()
GetBackend()
Gets the backend used by the worker for execution.
Declaration
public IBackend GetBackend()
Returns
Type | Description |
---|---|
IBackend | The backend used for execution. |
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
public 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
public 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
public void SetInput(string name, Tensor x)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the input to set. |
Tensor | x |
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
public 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
public 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. |