Is it possible to get the shapes of the output tensors? They are visible in the Editor, but Model.outputs contains only the tensor names.
Before or after model execution?
- after:
var output = worker.PeekOutput();
output.shape();
- before
This one is a bit more tricky. In a lot cases input shapes are set as unknown in the model, or there is some dynamic layer that makes that we cannot fully know the output shapes all the time.
Internally we do some clever symbolic logic to figure out best we can. We call this partial tensor shape, and part of the shape can be known/unknown or symbolic.
var ctx = new ShapeInferenceContext();
ShapeInferenceAnalysis.InferModelShapes(model, ctx);
ctx.GetSymbolicTensorShape(name);
I hope everything is public but not sure.
Given that this can be complicated we have probably not exposed everything you need to access this.
We could only this api if it’s something that you want to have
Thank you!
My question was about the output tensor shape before execution. And yes, you’re right: ShapeInferenceContext and ShapeInferenceAnalysis are currently inaccessible.
But I think I can move the logic concerning output shapes after the model execution, to be on the safe side.
I’m considering porting my code from Barracuda to Sentis at this time.
In Barracuda, Model.GetShapeByName() made it easy to get the shape of the output layer before running inference.
But, I have not been able to find an replacement this method to this in Sentis.
I hope this method will be implemented in the next version.
Thanks,
You can actually call
var ctx = PartialInferenceAnalysis.InferModelPartialTensors(m_Model, false);
foreach (var output in outputs)
{
var partialTensor = ctx.GetPartialTensor(output);
items.Add($"<b>{output}</b> {m_Model.GetSymbolicTensorShapeAsString(partialTensor.shape)}, {partialTensor.dataType}");
}
That should be public?
I’m using Sentis 1.2.0-exp.2. However, Its API does not seem to be publicly available yet.
I hope this feature (get the shape of the output layer before running inference) will be access to developers in some way.
Thank you for reporting this, It’s known internally as task 178.