#python-3.x #tensorflow2.0 #tensorflow-lite
#python-3.x #tensorflow2.0 #tensorflow-lite
Вопрос:
Я пытаюсь выяснить, как я могу сохранить прогнозируемую маску (выходные данные) из модели tensorflow, которые были преобразованы в модель tf.lite на моем ПК. Любые советы или идеи о том, как я могу визуализировать его или сохранить прогнозируемую маску в виде изображения .png. Я попытался использовать помехи tensorflow Lite от https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_python безуспешно.
Теперь вывод выглядит следующим образом:
[ 1 512 512 3]
[[[[9.7955531e-01 2.0444747e-02]
[9.9987805e-01 1.2197520e-04]
[9.9978799e-01 2.1196880e-04]
.......
.......
[9.9997246e-01 2.7536058e-05]
[9.9997437e-01 2.5645388e-05]
[1.9125430e-03 9.9808747e-01]]]]
Любая помощь очень ценится.
Большое спасибо
## Load the TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="tflite_model.tflite")
print(interpreter.get_input_details())
print(interpreter.get_output_details())
print(interpreter.get_tensor_details())
interpreter.allocate_tensors()
## Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
## Test the model on input data.
input_shape = input_details[0]['shape']
print(input_shape)
## Use same image as Keras model
input_data = np.array(Xall, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
## The function `get_tensor()` returns a copy of the tensor data.
## Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
output_data.shape
Ответ №1:
Это зависит от значения вывода вашей модели. Затем используйте библиотеки изображений, такие как cv2
или PIL
, чтобы нарисовать маску.
Например, первая строка:
9.7955531e-01 2.0444747e-02
Вам нужно выяснить, чему они соответствуют. Из-за ограниченной информации трудно догадаться из контекста.
Комментарии:
1. Спасибо, я новичок в этом, и просто объяснение того, что это строки, сделало его более понятным. еще раз спасибо!