-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpredict.py
More file actions
executable file
·46 lines (32 loc) · 1.44 KB
/
Copy pathpredict.py
File metadata and controls
executable file
·46 lines (32 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# Author: Simeon Babatunde
# Date : 15 Nov 2020
# Purpose: This script uses TFlite to predicts the inter-vehicle distance of a CACC application using six vehicle mobility features.
# from tflite_runtime.interpreter import Interpreter
import numpy as np
# import argparse
# parser = argparse.ArgumentParser(description='CACC inter-vehicle distance')
# parser.add_argument('--model_path', type=str, help='Specify the tflite model path', required=True)
# args = parser.parse_args()
# model_path = args.model_path
# Load TFLite model and allocate tensors
interpreter = Interpreter(model_path='cacc_model.tflite')
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Resize input and output tensors to handle input of 6 feature columns
interpreter.resize_tensor_input(input_details[0]['index'], (1, 6))
interpreter.resize_tensor_input(output_details[0]['index'], (1, 1))
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
while True:
# Read in input features for prediction
print("Input features")
features = np.fromstring(input(), dtype='f', sep=',')
print(features)
# Point to data and run interpreter
interpreter.set_tensor(input_details[0]['index'], features)
interpreter.invoke()
tflite_results = interpreter.get_tensor(output_details[0]['index'])
print(tflite_results)