我正在我的 c# 脚本中导入对象识别模型并进行推理。它在脚本中多次执行,如下所示:
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();
在我看来,在进行推理时需要重复最后三行,但第一行似乎是一次性的。
c# 让我只把它放在一个函数的范围内。我试过这样,但它不起作用:
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);
我得到的错误是:
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)
当我执行
var tensor = new Tensor(texture, channelCount);
在类的功能之一
有什么建议么?谢谢!