【问题标题】:Android / TFlite call results in a NPEAndroid / TFlite 调用导致 NPE
【发布时间】:2019-02-28 11:10:12
【问题描述】:

我们正在尝试在 Android 应用中进行对象检测。为此,我们使用了 ssdlite_mobilenet_v2_coco 预训练网络并继续训练我们自己的数据集。

为了训练,我们使用了 Ubuntu 18.04 和 TensorFlow 1.11.0 + GPU 支持。我们使用这些脚本创建了 tflite 模型:

python3 ~/tensorflow/models/research/object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path input/ssdlite_mobilenet_v2_coco/pipeline.config \
--trained_checkpoint_prefix input/ssdlite_mobilenet_v2_coco/model.ckpt-381700 \
--output_directory output/ \
--add_postprocessing_op=true

tflite_convert \
--output_file=output/ssdlite_mobilenet_v2_coco.tflite \
--graph_def_file=input/ssdlite_mobilenet_v2_coco.pb \
--input_arrays=FLOAT \
--output_arrays=concat,concat_1 \
--input_shape=1,300,300,3

这个应用程序的基本功能是,它需要一个预先录制的视频,使用 FFmpegMediaMetadataRetriever 逐帧解码,并将位图传递到 tflite 以检测那里的对象。该应用程序是使用 gradle 构建的,我们使用的是 'org.tensorflow:tensorflow-lite:1.12.0',但我们基本上得到了与 1.11 相同的错误。

我们将位图缩小到 300x300 并将其从 ARGB 转换为 3 个浮点通道,然后像这样调用 tflite:

Log.v(TAG, "Feeding TFLite")
outputLocations = Array(1) { Array(NUM_DETECTIONS) { FloatArray(4) } }
outputClasses = Array(1) { FloatArray(NUM_DETECTIONS) }
outputScores = Array(1) {FloatArray(NUM_DETECTIONS)}
numDetections = FloatArray(1)

val inputArray = arrayOf<Any>(imgData!!)
val outputMap = HashMap<Int, Any>()
outputMap.put(0, outputLocations!!)
outputMap.put(1, outputClasses!!)
outputMap.put(2, outputScores!!)
outputMap.put(3, numDetections!!)


Log.v(TAG, "Running TFLite")
tflite!!.runForMultipleInputsOutputs(inputArray, outputMap)
Log.v(TAG, "Returning from TFLite")

val recognitions = ArrayList<Recognition>(NUM_DETECTIONS)

我们得到的错误是:

2019-02-28 11:52:33.486 26807-26879/com.package.xxxxxx A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 26879 (.xxxxxx), pid 26807 (.xxxxxx)
2019-02-28 11:52:33.600 26890-26890/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2019-02-28 11:52:33.601 26890-26890/? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86/generic_x86:9/PSR1.180720.075/5124027:userdebug/dev-keys'
2019-02-28 11:52:33.601 26890-26890/? A/DEBUG: Revision: '0'
2019-02-28 11:52:33.601 26890-26890/? A/DEBUG: ABI: 'x86'
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG: pid: 26807, tid: 26879, name: .xxxxxx  >>> com.package.xxxxxx <<<
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG: Cause: null pointer dereference
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG:     eax 00000000  ebx 00000000  ecx 00000000  edx 00000000
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG:     edi c75094a8  esi 00000000
2019-02-28 11:52:33.604 26890-26890/? A/DEBUG:     ebp c75090f8  esp c7509070  eip c757c77b
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG: backtrace:
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #00 pc 0007277b  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #01 pc 00074fe0  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #02 pc 0007590d  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #03 pc 000755b0  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #04 pc 00076322  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.606 26890-26890/? A/DEBUG:     #05 pc 0013389c  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.607 26890-26890/? A/DEBUG:     #06 pc 00132fa7  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.607 26890-26890/? A/DEBUG:     #07 pc 00132e37  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.607 26890-26890/? A/DEBUG:     #08 pc 0016550e  /data/app/com.package.xxxxxx-yGil4a0ylttBBhPIo26SWA==/lib/x86/libtensorflowlite_jni.so
2019-02-28 11:52:33.607 26890-26890/? A/DEBUG:     #09 pc 0008f065  /system/lib/libc.so (__pthread_start(void*)+53)
2019-02-28 11:52:33.607 26890-26890/? A/DEBUG:     #10 pc 0002485b  /system/lib/libc.so (__start_thread+75)
2019-02-28 11:52:34.197 1761-1761/? E//system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_35

正如您所见,NPE 发生在 libtensorflow 的深处,我们基本上没有办法解决它,因此我们非常感谢您的帮助。它发生在物理设备和 android 沙箱 (API 28) 上

我们使用this 作为起点,并使用 TensorFlow 存储库中的 Tensorflow tflite 演示。

【问题讨论】:

    标签: android tensorflow object-detection


    【解决方案1】:

    原来 tflite_convert 脚本中的输入数组和输出数组是错误的。

    我们成功地(没有 NullPointer)使用由以下命令生成的 tflite 图调用 tflite:

    tflite_convert \ 
    --graph_def_file=tflite_graph.pb \ 
    --output_file=output.tflite \ 
    --input_shapes=1,300,300,3 \ 
    --std_dev_values=128 \ 
    --mean_values=128 \ 
    --input_arrays=normalized_input_image_tensor \ 
    --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' \ 
    --allow_custom_ops 
    

    【讨论】:

    • 哇!我也面临这个问题。你从哪里得到关于输入和输出数组应该是什么的信息?
    • 我在 github github.com/tensorflow/tensorflow/issues/26484 上问了同样的问题,在那里的支持下,我们得以解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多