Ejemplo n.º 1
0
def run_tflite_graph(tflite_model_buf, input_data):
    """ Generic function to execute TFLite """
    input_data = convert_to_list(input_data)

    interpreter = interpreter_wrapper.Interpreter(
        model_content=tflite_model_buf)
    interpreter.allocate_tensors()

    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()

    # set input
    assert len(input_data) == len(input_details)
    for i in range(len(input_details)):
        interpreter.set_tensor(input_details[i]['index'], input_data[i])

    # Run
    interpreter.invoke()

    # get output
    tflite_output = list()
    for i in range(len(output_details)):
        tflite_output.append(interpreter.get_tensor(
            output_details[i]['index']))

    return tflite_output
Ejemplo n.º 2
0
@Contact: [email protected]
@Date: 2019/7/14
@Description:
"""
import os
import time
import numpy as np
import tensorflow as tf
import cv2
from tensorflow.contrib import lite
from ..utils.preprocessor import process_img
from ..utils.inference import load_image

# Load TFLite model and allocate tensors.
interpreter = lite.Interpreter(
    model_path="../trained_models/emotion_models/RAF_MobileNet_20190714.tflite"
)
image_path = "../images/happy1.jpg"  # 选择测试图片

rgb_image = load_image(image_path, color_mode='rgb')
face_image = cv2.resize(rgb_image, (64, 64))
face_image = process_img(face_image)
face_image = np.expand_dims(face_image, 0)

interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(input_details)
print(output_details)

all_time = 0