Performs evaluation for input image over specified model. Args: interpreter: TFLite interpreter initialized with model to execute. input_image: Image input to the model. Returns: output: output tensor of model being executed.
(interpreter, input_image)
| 44 | |
| 45 | |
| 46 | def run_eval(interpreter, input_image): |
| 47 | """Performs evaluation for input image over specified model. |
| 48 | |
| 49 | Args: |
| 50 | interpreter: TFLite interpreter initialized with model to execute. |
| 51 | input_image: Image input to the model. |
| 52 | |
| 53 | Returns: |
| 54 | output: output tensor of model being executed. |
| 55 | """ |
| 56 | |
| 57 | # Get input and output tensors. |
| 58 | input_details = interpreter.get_input_details() |
| 59 | output_details = interpreter.get_output_details() |
| 60 | |
| 61 | # Test model on the input images. |
| 62 | input_image = np.reshape(input_image, input_details[0]['shape']) |
| 63 | interpreter.set_tensor(input_details[0]['index'], input_image) |
| 64 | |
| 65 | interpreter.invoke() |
| 66 | output_data = interpreter.get_tensor(output_details[0]['index']) |
| 67 | output = np.squeeze(output_data) |
| 68 | return output |
| 69 | |
| 70 | |
| 71 | def main(_): |
no test coverage detected