Views
No views yet
1import numpy as np
2from numpy import random
3import pandas as pd
4import onnxruntime as ort
5
6# Load the saved file
7model_path = "rd2l_forest.onnx"
8session = ort.InferenceSession(model_path)
9
10# Define default naming scheme
11input_name = session.get_inputs()[0].name
12output_name = session.get_outputs()[0].name
13
14def prediction(input_data : np.ndarray) -> float
15 """
16 Performs inference on the loaded ONNX model using the provided input data.
17
18 Args:
19 input_data (np.ndarray): An array of size (263,), this represents all of a singular players information
20
21 Returns:
22 float: The predicted cost of the player
23
24 """
25
26 # Convert to onnx input format and reshape
27 input_data = input_data.to_numpy(dtype=np.float32).reshape(1, -1)
28
29 # Create prediction
30 predictions = session.run([output_name], {input_name: input_data})
31
32 # Convert to individual value
33 return round(float(predictions[0][0][0]), 2)
34
35sample_df = pd.DataFrame(np.random.rand(263))
36
37prediction(sample_df)