【发布时间】:2020-12-02 14:57:18
【问题描述】:
我正在将一个 tflite 模型(SsdMobilenetV2320x320Coco17Tpu8 从 TF detection zoo 和 ocnverter 在 tflite 转换器的帮助下导入到 tf lite。)到 Android 工作室的应用程序中。我使用 new->other->tf lite 模型方法来导入模型并添加依赖项。然而,有一个我不知道的“背景”。
SsdMobilenetV2320x320Coco17Tpu8 model = SsdMobilenetV2320x320Coco17Tpu8.newInstance(context);
来自 tf (https://www.tensorflow.org/lite/guide/android) 的帮助文档没有说明这个“上下文”是什么!
我发现的其他解决方案是 Classifier 类,我认为它对我没有用处,因为这是一个对象检测网络。
这是 .ml.SsdMobilenetV2320x320Coco17Tpu8 文件中给出的代码示例:
try {
SsdMobilenetV2320x320Coco17Tpu8 model = SsdMobilenetV2320x320Coco17Tpu8.newInstance(context);
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 1, 1, 3}, DataType.UINT8);
inputFeature0.loadBuffer(byteBuffer);
// Runs model inference and gets result.
SsdMobilenetV2320x320Coco17Tpu8.Outputs outputs = model.process(inputFeature0);
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
TensorBuffer outputFeature1 = outputs.getOutputFeature1AsTensorBuffer();
TensorBuffer outputFeature2 = outputs.getOutputFeature2AsTensorBuffer();
TensorBuffer outputFeature3 = outputs.getOutputFeature3AsTensorBuffer();
TensorBuffer outputFeature4 = outputs.getOutputFeature4AsTensorBuffer();
TensorBuffer outputFeature5 = outputs.getOutputFeature5AsTensorBuffer();
TensorBuffer outputFeature6 = outputs.getOutputFeature6AsTensorBuffer();
TensorBuffer outputFeature7 = outputs.getOutputFeature7AsTensorBuffer();
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
}
}
关于inputFeature0.loadBuffer(byteBuffer); 的任何帮助也都得到了应用,我猜这是在创建实例后从内存中引导数据。
【问题讨论】:
标签: android tensorflow tensorflow-lite