human_emotion_detection / onnx_inference.py
Victorano's picture
All functionalities working fine
9d20d64
raw
history blame contribute delete
No virus
686 Bytes
import onnxruntime as rt
import cv2
import numpy as np
import time
providers = ['CPUExecutionProvider']
m_q = rt.InferenceSession(
"eff_quantized.onnx", providers=providers)
def emotions_detector(img_array):
time_init = time.time()
# Check if image is in grayscale and convert to rgb
if len(img_array.shape) == 2:
img_array = cv2.cvtColor(img_array, cv2.COLOR_GRAY2RGB)
# resize layer
test_image = cv2.resize(img_array, (256, 256))
im = np.float32(test_image)
img_array = np.expand_dims(im, axis=0)
onnx_pred = m_q.run(['dense_2'], {"input_1": img_array})
time_elapsed = time.time() - time_init
return onnx_pred, time_elapsed