Я использую предварительно натренированную модель тензорного потока для получения образца, используя короткую программу, которую я создал:
import cv2 as cv
import numpy as np
import os
import tensorflow as tf
import numpy as np
def decode_img(img):
# convert the compressed string to a 3D uint8 tensor
img = tf.image.decode_jpeg(img, channels=3)
# Use `convert_image_dtype` to convert to floats in the [0,1] range.
img = tf.image.convert_image_dtype(img, tf.float32)
# resize the image to the desired size.
return tf.reshape(tf.image.resize(img, [257, 257]), [1, 257, 257, 3])
model = tf.lite.Interpreter('models\posenet_mobilenet_v1_100_257x257_multi_kpt_stripped.tflite')
input_details = model.get_input_details()
output_details = model.get_output_details()
img = tf.io.read_file('photos\standing\\1.jpg')
input_data = decode_img(img)
print('input shape: {}'.format(input_data.shape))
model.set_tensor(input_details[0]['index'], input_data)
model.invoke()
output_data = model.get_tensor(output_details[0]['index'])
print('output: {}'.format(output_data))
После того, как форма ввода напечатана на консоли, больше ничего не происходит, программа концы. Строка, которая предположительно должна выводить вывод, никогда не выполняется.
output:
C: \ python imagetest.py INFO: Инициализированная среда выполнения TensorFlow Lite. 2020-01-21 08: 07: 32.567619: I tenorflow / core / platform / cpu_feature_guard. cc: 145] Этот двоичный файл TensorFlow оптимизирован с помощью Intel (R) MKL-DNN для использования следующих инструкций ЦП в критически важных для производительности операциях: AVX AVX2 Чтобы включить их в операциях, отличных от MKL-DNN, перестройте TensorFlow с помощью соответствующих флагов компилятора. 2020-01-21 08: 07: 32.578283: I tenorflow / core / common_runtime / process_util. cc: 115] Создание нового пула потоков с настройкой взаимодействия по умолчанию: 8. Настройтесь с помощью inter_op_parallelism_threads для лучшей производительности. форма ввода: (1, 257, 257, 3)
Как правильно использовать предварительно обученную модель tflite с использованием класса Interpreter?