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
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 |
GetBackend()
Declaration
IBackend GetBackend()
Returns
Type | Description |
---|---|
IBackend |
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.
If you want to dispose of the worker but keep the tensor, use FinishExecutionAndDownloadOutput()
instead, or use TakeOwnership()
on the output tensor.
Declaration
Tensor PeekOutput()
Returns
Type | Description |
---|---|
Tensor |
PeekOutput(String)
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 FinishExecutionAndDownloadOutput()
instead, or use TakeOwnership()
on the output tensor.
Declaration
Tensor PeekOutput(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the output tensor to peek. |
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 |