Skip to content

Instantly share code, notes, and snippets.

@kratsg
Created October 31, 2022 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kratsg/e8bf750c8b4ccbda42b6c9bf39e0a6df to your computer and use it in GitHub Desktop.
Save kratsg/e8bf750c8b4ccbda42b6c9bf39e0a6df to your computer and use it in GitHub Desktop.
import numpy as np
import onnx
import onnxruntime
from onnx import numpy_helper
import uproot
model="./model.onnx"
session = onnxruntime.InferenceSession(model, None)
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
print(input_name)
print(output_name)
with open("./inputs/branches_21.2.87-1.list.2") as fp:
branches = [line.strip() for line in fp.readlines()]
print(branches)
m_gluino = 2300
m_lsp = 1200
isGtt = 0
for chunk in uproot.iterate("./inputs/DAOD_TRUTH3.GG_ttn1_2300_5000_1200_nominal.root:ntuple", expressions=branches, library="np", how=tuple):
step_size = len(chunk[0])
data = np.stack([*chunk, [isGtt]*step_size, [m_gluino]*step_size, [m_lsp]*step_size]).T
result = session.run([output_name], {input_name: data.astype('float32')})
print('result=',result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment