I’m experiencing editor freezing issues when using InvokeRepeating
with Sentis model predictions. Interestingly, the freezing only occurs when I use a boolean flag to check the prediction state - removing this flag prevents the freezing.
Code
Here’s my implementation based on the Sentis documentation:
// PredictionModelServer class
public void startPredict()
{
currentState = PredictionState.Predicting;
tensor = new Tensor<float>(shape, data.ToArray());
worker.Schedule(tensor);
outputTensor = worker.PeekOutput() as Tensor<float>;
outputTensor.ReadbackRequest();
}
public void PredictResult()
{
var outputArray = outputTensor.DownloadToArray();
/* display outputArray[0] */
outputTensor.Dispose();
tensor.Dispose();
currentState = PredictionState.Ready;
}
// In another class - this gets called by InvokeRepeating
public void InvokedFunction()
{
if (isPredict) // <-- Causes freezing when this flag is present
{
if (ModelServer.Model.IsReady())
{
ModelServer.Model.startPredict();
}
else if (ModelServer.Model.IsPredicting())
{
ModelServer.Model.PredictResult();
}
}
}
When isPredict flag is present: Editor freezes
When isPredict flag is removed: Works fine, no freezing
P.S. I’ve tried to use the editor version 2022.3.39, 2022.3.56 and 2023.2.20 and the problem exposed same.