Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

inference_onnx.py 695 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  1. import tensorflow as tf
  2. import numpy as np
  3. import onnxruntime as rt
  4. from PIL import Image
  5. class FEPredictor:
  6. def __init__(self, model_path):
  7. self.ort_session = rt.InferenceSession(model_path)
  8. def infer(self, image=None):
  9. input_name = self.ort_session.get_inputs()[0].name
  10. # label_name = self.ort_session.get_outputs()[0].name
  11. tensor_image = tf.convert_to_tensor(np.array(Image.open(image)), dtype=tf.float32)[np.newaxis, :]
  12. return self.ort_session.run(None, {input_name: tensor_image})[0]
  13. if __name__ == "__main__":
  14. image = "image path"
  15. predictor = FEPredictor("models/1/emotionModel.onnx")
  16. print(predictor.infer(image))
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...