File size: 686 Bytes
9d20d64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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