0

I'm importing and doing inference with an object recognition model in my c# script. It's being done multiple times in the script like this:

var model = ModelLoader.Load(modelSource);
var worker = BarracudaWorkerFactory.CreateWorker(BarracudaWorkerFactory.Type.ComputePrecompiled, model);

var tensor = new Tensor(texture, channelCount);
worker.Execute(tensor);
var Out = worker.Peek();

It seems to me that the last three lines need to be repeated when doing inference, but the first ones seem like a one-time thing.

c# lets me only put it within the scope of a function. I've tried it like this, but it doesn't work:

public class Critic : MonoBehaviour
{
  public static NNModel modelSource;
  private static object model = ModelLoader.Load(modelSource);
  private object worker = BarracudaWorkerFactory.CreateWorker(BarracudaWorkerFactory.Type.ComputePrecompiled, (Model) model);

The error I get is:

NullReferenceException: Object reference not set to an instance of an object
Barracuda.ModelAnalyzer.GetDefaultInputName (Barracuda.Model model) (at <68dd6e4acc004c7c8bb12c0e7eb964f9>:0)
Barracuda.GenericWorker..ctor (Barracuda.Model model, Barracuda.IOps ops, Barracuda.IVars vars, System.Boolean verbose) (at <68dd6e4acc004c7c8bb12c0e7eb964f9>:0)
Barracuda.BarracudaWorkerFactory.CreateWorker (Barracuda.BarracudaWorkerFactory+Type type, Barracuda.Model model, System.String[] additionalOutputs, System.String[] trimOutputs, System.Boolean verbose, Barracuda.BarracudaWorkerFactory+Type compareAgainstType) (at <68dd6e4acc004c7c8bb12c0e7eb964f9>:0)
Barracuda.BarracudaWorkerFactory.CreateWorker (Barracuda.BarracudaWorkerFactory+Type type, Barracuda.Model model, System.String[] additionalOutputs, System.String[] trimOutputs, System.Boolean verbose) (at <68dd6e4acc004c7c8bb12c0e7eb964f9>:0)

when I execute

var tensor = new Tensor(texture, channelCount);

in one of the class' functions

Any suggestions? Thanks!

SumakuTension
  • 542
  • 1
  • 9
  • 26

0 Answers0