0

我正在使用梭子鱼在 Unity 中使用 ONNX 模型。输入是一个 96x96 的灰度渲染纹理。我想在android中使用它,但我担心性能,因为每次使用都会分配4.3 kb的内存。难道我做错了什么?还是梭子鱼还没准备好?您还有什么建议可以达到可接受的性能?

探查器

    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();
    }
4

0 回答 0