簡體   English   中英

Tensorflow Lite Android Object 檢測 - 移動 SSD 型號預計正好有 4 個輸出,發現 8

[英]Tensorflow Lite Android Object Detection — Mobile SSD models are expected to have exactly 4 outputs, found 8

遇到的問題:

E/AndroidRuntime: FATAL EXCEPTION: main Process: org.tensorflow.lite.examples.detection, PID: 14719 java.lang.AssertionError: 初始化 ObjectDetector 時發生錯誤: 移動 SSD 模型預計有 44 個輸出

問題描述

  • Android 應用來源:TensorFlow Lite Object 檢測示例來自 Google
  • 啟動示例應用程序時顯示錯誤

Model 說明

  • 定制 Model 二手? 是的

  • 預訓練 Model 使用:ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8

  • 推理類型:FLOAT

  • 班數:4

系統信息

  • 操作系統平台和發行版:(Linux Ubuntu 20.14)
  • TensorFlow 版本:2.4.1
  • TensorFlow 安裝自:Pip

保存使用的 Model 轉換命令:

1. Saved_Model.pb 導出:

python./exporter_main_v2.py
--input_type image_tensor
--pipeline_config_path./models/ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8/pipeline.config
--trained_checkpoint_dir./models/ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8
--output_directory 導出模型/tflite

2. 將保存的 model (.pb) 轉換為 tflite

合作
--saved_model_dir./exported-models/tflite/saved_model
--emit-select-tf-ops 真
--allow_custom_ops
--graph_def_file./exported-models/tflite/saved_model/saved_model.pb
--output_file./exported-models/tflite/tflite/detect.tflite
--input_shapes 1,300,300,3
--input_arrays normalized_input_image_tensor
--output_arrays 'TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3'
--inference_type=FLOAT
--allow_custom_ops

備注我正在嘗試在 Google TensorFlow lite 提供的示例上使用經過訓練的自定義 model。 只是每次我打開應用程序時,它都會返回這樣的錯誤,Mobile SSD 模型預計正好有 4 個輸出,找到 8 個。model 被訓練識別 4 個類,所有這些都在 labelmap.txt 和管道配置中說明。

有人對這個錯誤有任何線索嗎?

After further study, I believe the aforementioned issue was raised since the model has 8 tensors output but the Android application written in Java can only support 4 tensors output (at least the example provided by Google only supports 4 tensors output)

我不太確定不同型號上張量 output 的數量。 So far as I understood and messed around with different models, models with fixed_shape_resizer of 640 x 640 are likely to require more than 4 tensors output ( 8 tensors output usually), which is not compatible with the Android application written in Java.

對於像我這樣的任何業余用戶,請找到以下先決條件以在Android 應用程序中使用您的自定義 model
建議設置(假設您使用的是 TensorFlow 版本 >= 2.3):

  • TensorFlow Model: SSD model,fixed_shape_resizer 為 320 x 320
    (就我而言,SSD MobileNet v2 320x320 工作得非常好)(張量 output 必須是 4)

  • Colab (非常適合 model 訓練和轉換)
    (我嘗試在我的本地機器上同時在 ZEDC9F0A5A5A5D57797BF68E37364743831Z 和 Windows 平台上執行訓練和轉換,不同工具和 package 的不兼容給我帶來了更多的麻煩。功能強大,並且與那些培訓工具和腳本具有很好的兼容性。)

  • @lu-wang-g編寫的元數據編寫器庫
    (In my case, after converting the trained model to.tflite, if you directly migrate the.tflite model to the Android application, the application will report tons of problem regarding the config of the.tflite model. Assume if you trained and converted the model 正確,您只需要上面的元數據寫入器庫。它會根據.tflite model 自動為您配置元數據。然后您可以直接將 Z20F35E630DAF44DBFA4C3F68F5399D8 遷移到應用程序。

有關詳細信息,請訪問我的 GitHub 問題:
https://github.com/tensorflow/tensorflow/issues/47595

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM