Upgrade from Sentis 1.3 to Sentis 1.4
To upgrade from Sentis 1.3 to Sentis 1.4, do the following:
- Reimport models that were previously imported in an earlier version of Sentis.
- Reexport serialized .sentis files and encrypted serialized models using Sentis 1.4.
- Replace uses of
IWorker.FinishExecutionAndDownloadOutputwithIWorker.TakeOutputOwnership. - Replace uses of
Tensor.TakeOwnershipwithTensor.CompleteOperationsAndDownload. - Replace uses of
Tensor.tensorOnDevicewithTensor.dataOnBackend. - Replace uses of
Tensor.ZeroswithTensor.AllocZeros. - Replace uses of the
Tensor.shapesetter withTensor.Reshape. - Remove uses of
Tensor.ShallowReshape, useTensor.Reshapeto reshape a tensor in place orTensor.AllocNoDataandIBackend.Reshapeto create a new reshaped tensor. - Remove uses of
Tensor.DeepCopy, useTensor.AllocNoDataandIBackend.MemCopyto copy a tensor. - Remove uses of the
ModelAPI, use the functional API to edit models:- Remove
Model.AddInput, useInputDeffor inputs in aFunctional.Compilecall. - Remove
Model.AddConstant, useFunctional.Tensorin aFunctional.Compilecall. - Remove
Model.AddLayerandLayerconstructors, useFunctionalmethods in aFunctional.Compilecall.
- Remove
- Edit
Model.AddOuputparameters to include both the output name and output index (from the inspector). - When calling
Model.outputs, useModel.Output.nameto get the name of the output. - Replace uses of
Layer.nameandConstant.namewithLayer.indexandConstant.index. - Remove uses of the
OpsAPI, use the functional API to build models to operate on tensors, or useIBackendto operate on allocated tensors. - Replace uses of
ArrayTensorDataandSharedArrayTensorDatawithBurstTensorData. - Remove
CustomLayercustom ONNX layer importers as these are not compatible with Sentis 1.4 serialization. These will be reimplemented in an upcoming release. - Replace uses of
IBackend.deviceTypewithIBackend.backendTypeto get the back end type. - Remove allocation of tensors using
IBackendmethods, either allocate tensors withTensororIModelStorage. - Remove offset from constructors of
BurstTensorData, if the offset needs to be greater than zero use aNativeTensorArrayFromManagedArrayin theBurstTensorDataconstructor. - Replace uses of
IWorker.StartManualSchedulewithIWorker.ExecuteLayerByLayer. - Replace uses of
ITensorData.shapewithTensor.shape. - Remove uses of
ITensorData.AsyncReadbackRequestandITensorData.IsAsyncReadbackRequestDone, useTensor.ReadbackRequest,Tensor.ReadbackRequestAsync, andTensor.IsReadbackRequestDonefor async readback of tensor data. - Remove uses of
Model.Metadata, this is not compatible with Sentis 1.4 serialization. - Remove references to
Model.Warnings, these are not compatible with Sentis 1.4 serialization, use the console to view importer errors and warnings. - Remove uses of
Model.CreateWorker, useWorkerFactory.CreateWorkerto create a worker. - Remove uses of
Model.ShallowCopy, use the functional API to copy a model. - Replace constructors of
SymbolicTensorDimwithSymbolicTensorDim.Int,SymbolicTensorDim.ParamandSymbolicTensorDim.Unknownstatic methods.
Upgrade from Sentis 1.1 or 1.2 to Sentis 1.3
To upgrade from Sentis 1.1 or 1.2 to Sentis 1.3, do the following:
- Reimport models that were previously imported in an earlier version of Sentis.
Upgrade from Sentis 1.0 to Sentis 1.1
To upgrade from Sentis 1.0 to Sentis 1.1, do the following:
- Use
MakeReadableon GPU output tensor before indexing (seeUse tensor indexing methodssample). - Remove
prepareCacheForAccessparameter when callingPeekOutputand instead useMakeReadableon the returned tensor before reading it. - Use AsyncReadbackRequest for async readbacks from GPU (see
Read output asynchronouslysample). - Replace
: Layerwith: CustomLayerfor custom layers and implementInferOutputDataTypesmethod (seeAdd a custom layersample). - Replace instances of
IOpswithOps. - Replace
uploadCachewithclearOnInitwhen using .Pin method. - Replace uses of
CopyOutputwithFinishExecutionAndDownloadOutput.
Upgrade from Barracuda 3.0 to Sentis 1.0
To upgrade from Barracuda 3.0 to Sentis 1.0, do the following:
- Replace references to
BarracudawithSentis. - Update tensor operations in your project.
- Use
TensorFloatorTensorIntfor input and output tensors. - Update methods that convert between tensors and textures.
- Convert the model asset type.
- Convert back end types.
- Update getting output from intermediate layers.
- Replace
asFloatsandasInts.
Replace references to Barracuda with Sentis
All namespaces now use Sentis instead of Barracuda. To upgrade your project, change all references to Barracuda. For example, change using Unity.Barracuda to using Unity.Sentis.
Update tensor operations in your project
The way tensors work has changed. Sentis no longer converts tensors to different layouts automatically, so you might need to update your code to make sure input and output tensors are the layout you expect. Refer to Tensor fundamentals for more information.
Use TensorFloat or TensorInt to create tensors
Sentis supports tensors that contain floats or ints.
If you use the new Tensor() constructor in your code, you must replace it with either new TensorFloat() or new TensorInt().
You can no longer pass dimension sizes to the constructor directly. Instead, you can use the TensorShape constructor to create a tensor shape, then pass the TensorShape to the TensorFloat or TensorInt constructor.
The following example creates a 1D tensor of length 4:
TensorFloat inputTensor = new TensorFloat(new TensorShape(4), new[] { 2.0f, 1.0f, 3.0f, 0.0f });
Refer to Create input for a model for more information.
Update methods that convert between tensors and textures
You can no longer pass a texture as a parameter to a Tensor constructor directly. Use the TextureConverter.ToTensor API instead. Refer to Convert a tensor to a texture for more information.
For example:
TensorFloat inputTensor = TextureConvert.ToTensor(inputTexture);
Refer to Use output data for more information.
Convert the model asset type
The NNModel object is now called ModelAsset. Update your code with the new name.
For example, when you create a runtime model:
using UnityEngine;
using Unity.Sentis;
public class CreateRuntimeModel : MonoBehaviour
{
ModelAsset modelAsset;
void Start()
{
Model runtimeModel = ModelLoader.Load(modelAsset);
}
}
Refer to Import a model for more information.
Convert back end types
Update your code to reflect the following changes to back end type names:
- Use
BackendType.GPUComputeinstead ofWorkerFactory.Type.Compute,WorkerFactory.Type.ComputeReforWorkerFactory.Type.ComputeRefPrecompiled. - Use
BackendType.CPUinstead ofWorkerFactory.Type.CSharpBurst,WorkerFactory.Type.CSharpReforWorkerFactory.Type.CSharp.
For example, use the following to create a worker that runs on the GPU with Sentis compute shaders:
IWorker worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, runtimeModel);
Update getting output from intermediate layers
To get output from layers other than the output layers from the model, you now need to use AddOutput before you create the worker and use PeekOutput.
For example:
// Add the layer to the model outputs in the runtime model
runtimeModel.AddOutput("ConvolutionLayer");
// Create a worker
worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, runtimeModel);
// Run the model with the input data
worker.Execute(inputTensor);
// Get the output from the model
TensorFloat outputTensor = worker.PeekOutput() as TensorFloat;
// Get the output from the ConvolutionLayer layer
TensorFloat convolutionLayerOutputTensor = worker.PeekOutput("ConvolutionLayer") as TensorFloat;
You should only use this for debugging. Refer to Profile a model for more information.
Replace asFloats and asInts
The Tensor classes no longer contain the asFloats and asInts methods. Use ToReadOnlyArray instead.