I run an AImodel with following code
TensorFloat _OutputTensor = _Worker.Execute(_InputTensor).PeekOutput() as TensorFloat;
But it gives me an error at MakeReadable() because _OutputTensor is null.
What are some of the common cause of worker giving null output tensor?
The model I’m using worked fine with Barracuda.
I’m using Unity 2022.2.20 + Sentis 1.1.0 - exp.2
It is not giving any warning or error message so it is hard for me to debug.
Looking at your code, I would say that the output of your model is a TensorInt, and thus your cast to TensorFloat results in a null. (note that
as is a C# type casting and not a op.Cast which converts the whole tensor)
You can validate with tensor.dataType what type is your tensor. You can then cast it to the correct tensor type.
Wow that was exactly the issue!
Thank you for your super quick solution!
Could you also let me know how to cast TensorInt to TensorFloat?
Or if there is any way to do RenderToTexture with TensorInt?
Hi there, to cast from TensorInt to TensorFloat you can either use the ‘Ops’ method ‘Cast’, see
TensorFloat tensorFloat = ops.Cast(tensorInt, DataType.Float) as TensorFloat;
or even better you can add a Cast layer to your model
model.AddLayer(new Cast("Output_TensorFloat", "Output_TensorInt", DataType.Float));
before you create the worker. The “Output_TensorInt” string must match the previous name of your tensor int output layer (you can find this in the inspector or look at model.outputs). Then you can execute the model and get the tensor float output with
TensorFloat tensorFloat = worker.PeekOutput("Output_TensorFloat") as TensorFloat;