'Unity Barracuda package GC alloc
I'm using Barracuda to use ONNX models inside Unity. The input is a 96x96 Render Texture in grayscale. I want to use it in android, but I'm worried about performance, because 4.3 kb of memory is allocated for each use. Am I doing something wrong? or Barracuda is not ready? What else can you advise that achieves acceptable performance?
public struct Prediction
{
public int predictedValue;
public float[] predicted;
public void SetPrediction(Tensor t)
{
predicted = t.AsFloats();
predictedValue = Array.IndexOf(predicted, predicted.Max());
}
}
public Prediction prediction;
private void TakeScreenShot()
{
var inputX = new Tensor(rendTexture_forNeuro, 1, _name_of_tensor);
ExecuteInParts(_engine, inputX);
prediction.SetPrediction(inputX);
inputX.Dispose();
Receive();
}
private Tensor ExecuteInParts(IWorker worker, Tensor I, int syncEveryNthLayer = 5)
{
var executor = worker.StartManualSchedule(I);
var it = 0;
bool hasMoreWork;
do
{
hasMoreWork = executor.MoveNext();
if (++it % syncEveryNthLayer == 0)
worker.FlushSchedule();
} while (hasMoreWork);
return worker.CopyOutput();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
