了解用于姿态检测的mediapestflite模型的输出形状



我正在尝试使用mediapipes预训练的tflite模型之一在android (java)中执行姿势地标检测,它为我提供了关于人体33个地标的信息。我知道有不同的方法,例如使用ML Kit,但为了获得更好的结果,使用mediapes模型之一会更好。

我想使用(https://google.github.io/mediapipe/solutions/models.html) Pose地标模型。

要在android中使用这个模型,有必要知道(尤其是理解)模型的输出形状。这些可以在java(或python)中读取:

  • 五个输出:[195],[1],[256、256、1],[64、64、1],[117]如果我没弄错的话。

但是在模型的模型卡中,输出数组被定义为[33,5],这是有意义的,因为目标是检测33个地标,每个地标有5个值。

谁能解释一下tflite模型的输出形状以及如何使用它们,或者在我错过的文档上给我一个提示。

使用的代码是从android studio自动生成的,并由"示例代码"部分提供。的ml文件夹中的模型(遵循这些说明https://www.tensorflow.org/lite/inference_with_metadata/codegen#mlbinding,但使用以下方法获得相同的形状https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_java):

try {
PoseDetection model = PoseDetection.newInstance(getApplicationContext());
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 224, 224, 3}, DataType.FLOAT32);
// imageBuffer is the image as ByteBuffer
inputFeature0.loadBuffer(imageBuffer);
// Runs model inference and gets result.
PoseDetection.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();
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
}

我通过使用调试器检查outputFeatures来获得形状。

谢谢你。

考虑到MediaPipe文档中的提示"免责声明:在Windows上运行MediaPipe是实验性的"。(https://developers.google.com/mediapipe/framework/getting_started/install#installing_on_windows),我按照@Morrison Chang建议的google.github.io/mediapipe/getting_started/android.html的说明进行操作。这种方法需要很长时间才能理解,但它具有很高的可定制性和良好的效果。那解决了我的问题,旧的方法似乎不合适了。

最新更新