| 24 | interpreter.invoke() |
| 25 | |
| 26 | def run_inference(test_data_folder, model_filename, inputs, delegates=None): |
| 27 | model_path = os.path.join(test_data_folder, model_filename) |
| 28 | interpreter = tflite.Interpreter(model_path=model_path, |
| 29 | experimental_delegates=delegates) |
| 30 | interpreter.allocate_tensors() |
| 31 | |
| 32 | # Get input and output tensors. |
| 33 | input_details = interpreter.get_input_details() |
| 34 | output_details = interpreter.get_output_details() |
| 35 | |
| 36 | # Set inputs to tensors. |
| 37 | for i in range(len(inputs)): |
| 38 | interpreter.set_tensor(input_details[i]['index'], inputs[i]) |
| 39 | |
| 40 | interpreter.invoke() |
| 41 | |
| 42 | results = [] |
| 43 | for output in output_details: |
| 44 | results.append(interpreter.get_tensor(output['index'])) |
| 45 | |
| 46 | return results |
| 47 | |
| 48 | def compare_outputs(outputs, expected_outputs): |
| 49 | assert len(outputs) == len(expected_outputs), 'Incorrect number of outputs' |