Tensorflow Lite对象检测,Android Studio,SSD移动电视V2,相同的结构不同的Tflite文件,但几乎0检测

发布于 2025-02-02 02:05:21 字数 1493 浏览 5 评论 0原文

I want to make object detection application base on this github https://github.com/bendahouwael /车辆 - 探测器app-android

该GitHub代码使用基于SSD Mobilenet V1的TFLITE。因此,我根据SSD Mobilenet V2制作了自定义模型。我遵循此链接制作自己的Tflite模型。

来自 https://netron.app/ 我检查了模型结构几乎相同。请参阅下面的图片。

第一张图片是关于SSD Mobilenet V1结构的。

第二张图片是基于SSD Mobilenet V2的我自己的自定义模型。

我认为这两个模型的结构都是相同的。因此,我刚刚用标签TXT文件将自己的模型粘贴到App Code(资产文件夹)中。

该应用程序很好地显示了其实时图像,但没有检测到我决定要检测到的对象。我知道ssd mobilenet v1类型是unit8和我自己的模型(基于ssd mobilenet v2)类型是float32 。但这不是一个问题,我猜它的代码中的b/c都设置了有关是否量化。

因此,请谁有任何想法,告诉我我的应用程序如此糟糕的原因。

PS1)我忘了谈论调试。它没有显示任何错误消息。这让我很难工作

I want to make object detection application base on this github https://github.com/bendahouwael/Vehicle-Detection-App-Android.

That github code uses tflite based on ssd mobilenet v1. So I made my custom model based on ssd mobilenet v2. I followed this link https://colab.research.google.com/drive/1qXn9q6m5ug7EWJsJov6mHaotHhCUY-wG?usp=sharing to make my own TFLITE model.

From https://netron.app/ I checked the model structure both almost same. Please see the pictures below.
This structure is about SSD MOBILENET V1

First picture is about SSD MOBILENET V1 Structure.

enter image description here

Second picture is about my own custom model based on SSD MOBILENET V2.

I think both models' structure is same. So I just pasted my own model into app code(to asset folder) with label txt file.

The application showed its real time image well but did not detect the objects that I decided what to detect. I know ssd mobilenet V1 type is unit8 and my own model (which is based on ssd mobilenet v2) type is float32. But this is not a problem I guess b/c in the code it has setting about quantized or not.

So please who has any ideas, tell me the reason why my application works so bad.

ps1) I forgot to say about debugging. It did not show any error messages. This makes me much hard to work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狠疯拽 2025-02-09 02:05:21

如果您仔细查看输入零件,

  • 则使用mobilenet v1有:类型:unit8 [1,300,300,1]
  • 带有> Mobilenet v2您有:类型:float [1,300,300,1]

这意味着第一个模型被量化(更多信息:在这里),为重量和偏见使用整数值。 (这是针对推理速度完成的)

现在,如果您转到tflite对象检测类(或可能命名为不同),通常您将拥有一种称为stunceimage()类似的方法(这是部分(这是部分)创建填充bytebuffer):

imgData.rewind();
for (int i = 0; i < inputSize; ++i) {
  for (int j = 0; j < inputSize; ++j) {
    int pixelValue = intValues[i * inputSize + j];
    if (isModelQuantized) {
      // Quantized model
      imgData.put((byte) ((pixelValue >> 16) & 0xFF));
      imgData.put((byte) ((pixelValue >> 8) & 0xFF));
      imgData.put((byte) (pixelValue & 0xFF));
    } else { // Float model
      imgData.putFloat((((pixelValue >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
      imgData.putFloat((((pixelValue >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
      imgData.putFloat(((pixelValue & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
    }
  }
}

其中:

  private static final float IMAGE_MEAN = 128.0f;
  private static final float IMAGE_STD = 128.0f;

因此,在第一种情况下设置ismodelQuantized = true,对于Mobilenet V2,您设置了iSmodelQuantized = false = false

If you look closely at INPUT part,

  • with MobileNet V1 you have: type: unit8[1, 300, 300, 1]
  • with MobileNet V2 you have: type: float[1, 300, 300, 1]

This means that the first model is quantized (more info: here) and for the weight and biases use integer values. (this is done for inference speed)

Now if you go to your TFlite Object Detection class (or maybe named different), usually you will have a method called recognizeImage() similar like this (this is the part when you create fill the ByteBuffer):

imgData.rewind();
for (int i = 0; i < inputSize; ++i) {
  for (int j = 0; j < inputSize; ++j) {
    int pixelValue = intValues[i * inputSize + j];
    if (isModelQuantized) {
      // Quantized model
      imgData.put((byte) ((pixelValue >> 16) & 0xFF));
      imgData.put((byte) ((pixelValue >> 8) & 0xFF));
      imgData.put((byte) (pixelValue & 0xFF));
    } else { // Float model
      imgData.putFloat((((pixelValue >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
      imgData.putFloat((((pixelValue >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
      imgData.putFloat(((pixelValue & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
    }
  }
}

where:

  private static final float IMAGE_MEAN = 128.0f;
  private static final float IMAGE_STD = 128.0f;

So in the first case set the isModelQuantized = true, and for MobileNet V2 you set isModelQuantized = false

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文