-
Notifications
You must be signed in to change notification settings - Fork 0
/
onnx_test.py
44 lines (32 loc) · 1.24 KB
/
onnx_test.py
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
import numpy as np
import onnxruntime as rt
import pandas as pd
import os
import json
from core.data_processor import DataLoader
def onnx():
# get hyperparameters from json
configs = json.load(open('config_2.json', 'r'))
if not os.path.exists(configs['model']['save_dir']): os.makedirs(configs['model']['save_dir'])
# get data from csv
filename = os.path.join('data', configs['data']['filename'])
cols = configs['data']['columns']
dataframe = pd.read_csv(filename)
data_full = dataframe.get(cols)
row = data_full.iloc[1613].values
print(row)
# Load the ONNX model
sess = rt.InferenceSession(
r'C:\Users\flash\OneDrive\桌面\LSTM_predict_therapist_trajectory\converted_models\cw2_z.onnx')
# Assume input_data is your input in numpy array format
# Make sure the input data type and shape match the model's expected input
input_data = np.array(row, dtype=np.float32)
input_data = input_data[np.newaxis, np.newaxis, :] # adds two dimensions
print(input_data)
# Get the name of the input node
input_name = sess.get_inputs()[0].name
# Make prediction
prediction = sess.run(None, {input_name: input_data})
print(prediction)
if __name__ == '__main__':
onnx()