Move interpreter check before modifying the allocation type.

This commit is contained in:
Jacob Hegna 2022-10-12 04:36:34 +00:00
parent 9d93a98f85
commit 17095dfe36
1 changed files with 6 additions and 2 deletions

View File

@ -121,6 +121,11 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
tflite::InterpreterBuilder Builder(*Model, Resolver);
Builder(&Interpreter);
if (!Interpreter) {
invalidate();
return;
}
// We assume the input buffers are valid for the lifetime of the interpreter.
// By default, tflite allocates memory in an arena and will periodically take
// away memory and reallocate it in a different location after evaluations in
@ -130,8 +135,7 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
Interpreter->tensor(I)->allocation_type =
TfLiteAllocationType::kTfLiteArenaRwPersistent;
if (!Interpreter ||
Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
if (Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
invalidate();
return;
}