Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tflite转换android的掩码RCNN模型_Python_Android_Image Segmentation_Tensorflow Lite - Fatal编程技术网

Python 使用tflite转换android的掩码RCNN模型

Python 使用tflite转换android的掩码RCNN模型,python,android,image-segmentation,tensorflow-lite,Python,Android,Image Segmentation,Tensorflow Lite,我正在尝试在android中部署这个掩码rcnn模型。我能够加载keras权重,冻结模型并使用TFLite1.13将其转换为.tflite模型 这个模型似乎使用了一些tflite中不支持的tf_操作。因此,我不得不使用 converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,tf.lite.OpsSet.SELECT_TF_OPS] 以转换模型。现在,当我尝试使用python解释器推断此模型时,解释器.invoke()中出现分段错误,pyt

我正在尝试在android中部署这个掩码rcnn模型。我能够加载keras权重,冻结模型并使用TFLite1.13将其转换为.tflite模型

这个模型似乎使用了一些tflite中不支持的tf_操作。因此,我不得不使用

converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,tf.lite.OpsSet.SELECT_TF_OPS]
以转换模型。现在,当我尝试使用python解释器推断此模型时,解释器.invoke()中出现分段错误,python脚本崩溃

def run_tf_model(model_path="mask_rcnn_coco.tflite"):
    interpreter = tf.lite.Interpreter(model_path)
    interpreter.allocate_tensors()

    # Get input and output tensors.
    input_details = interpreter.get_input_details()[0]
    output_details = interpreter.get_output_details()[0]
    print(" input_details", input_details)
    print("output_details",output_details)

    # Test model on random input data.
    input_shape = input_details['shape']
    print("input_shape tflite",input_shape)
    input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
    interpreter.set_tensor(input_details['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['index'])
    print(output_data)
因此,我无法确定转换后的模型是否正确转换

另外,我计划在android中使用这个模型,但我对android(java或kotlin)tflite api几乎没有经验。如果有人能指出学习这方面的任何资源,也会很有帮助


编辑:我还尝试使用JavaAPI在android上运行推断。但是出现以下错误
tensorflow/lite/kernels/gather.cc:80 0您可以使用tflite python解释器验证您的定制训练tflite模型


您可以使用tflite python解释器验证您的定制训练tflite模型

import numpy as np
import tensorflow as tf

# Load the TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test the model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), 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)