Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android/TFlite调用会导致NPE_Android_Tensorflow_Object Detection - Fatal编程技术网

Android/TFlite调用会导致NPE

Android/TFlite调用会导致NPE,android,tensorflow,object-detection,Android,Tensorflow,Object Detection,我们正在尝试在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_confi

我们正在尝试在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上


我们使用Tensorflow tflite演示作为起点,形成Tensorflow存储库

事实证明tflite\u转换脚本中的输入数组和输出数组是错误的

我们成功地使用以下命令生成的tflite图调用了tflite,而无需NullPointer:

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的支持下,我们解决了这个问题。