使用在谷歌云TPU训练模式,我训练的SSD MobileNet V1 FPN模型来识别两种类型的对象。该模型中训练没有错误,我能够在TensorBoard评估。继转化为TensorFlow精简版,并尝试运行在目标检测演示应用程序的模式,这个模式失败,关于定制操作是未实现的一个错误,尽管TensorFlow的文档说明该操作在精简版实现的基础之上。
我训练使用在谷歌云一个TPU的模型,并从网上下载存储桶模型。
接下来,我出口使用对象检测模型(路径是故意通用)的最新版本的模型:
python -m object_detection/export_tflite_ssd_graph \
--pipeline_config_path=$PATH_TO_CONFIG_FILE \
--trained_checkpoint=model.ckpt-$CHECKPOINT \
--output_directory=$OUTPUT_DIR \
--add_postprocessing_op=true
接下来,我用转换从TensorFlow的Git仓库(使用巴泽勒0.21避免巴泽勒错误)的最新1.12标签型号:
bazel run -c opt //tensorflow/contrib/lite/toco:toco \
--incompatible_package_name_is_a_function=false \
-- \
--input_file=$OUTPUT_DIR/tflite_graph.pb \
--output_file=$OUTPUT_DIR/detect.tflite \
--input_shapes=1,640,640,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
接下来,我编辑的巴泽尔建立封闭,包括我的模型,我复制到应用程序目录,并编辑了DetectionActivity的Java文件,以引用我的模型:
# out of context
assets = [
#"//tensorflow/contrib/lite/examples/android/app/src/main/assets:labels_mobilenet_quant_v1_224.txt",
#"@tflite_mobilenet//:mobilenet_quant_v1_224.tflite",
#"@tflite_conv_actions_frozen//:conv_actions_frozen.tflite",
#"//tensorflow/contrib/lite/examples/android/app/src/main/assets:conv_actions_labels.txt",
#"@tflite_mobilenet_ssd//:mobilenet_ssd.tflite",
"//tensorflow/contrib/lite/examples/android/app/src/main/assets:detect.tflite",
#"//tensorflow/contrib/lite/examples/android/app/src/main/assets:box_priors.txt",
"//tensorflow/contrib/lite/examples/android/app/src/main/assets:pascal_labels.txt",
],
# out of context
private static final int TF_OD_API_INPUT_SIZE = 640;
private static final boolean TF_OD_API_IS_QUANTIZED = false;
private static final String TF_OD_API_MODEL_FILE = "file:///android_asset/detect.tflite";
private static final String TF_OD_API_LABELS_FILE = "file:///android_asset/pascal_labels.txt";
最后,我建立并使用以下命令部署的应用程序:
bazel build -c opt --config=android_arm64 --cxxopt='--std=c++11' "//tensorflow/contrib/lite/examples/android:tflite_demo"
adb install -r bazel-bin/tensorflow/contrib/lite/examples/android/tflite_demo.apk
所有我修改了代码,否则是股票在https://github.com/tensorflow/models/tree/master/research/object_detection库。
我希望得到的结果是一个工作的应用程序,通过构建应用程序,而不进行任何修改程序(股票从资料库)论证。
实际结果是在与下面的错误消息,以捕获logcat中立即启动该应用程序崩溃:
2019-02-09 16:38:28.229 32716-32716/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.tensorflow.lite.demo, PID: 32716
java.lang.RuntimeException: java.lang.IllegalArgumentException: Internal error: Cannot create interpreter: Didn't find custom op for name 'ResizeNearestNeighbor' with version 1
Registration failed.
at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.create(TFLiteObjectDetectionAPIModel.java:124)
at org.tensorflow.demo.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:110)
at org.tensorflow.demo.CameraActivity$5.onPreviewSizeChosen(CameraActivity.java:362)
at org.tensorflow.demo.CameraConnectionFragment.setUpCameraOutputs(CameraConnectionFragment.java:401)
at org.tensorflow.demo.CameraConnectionFragment.openCamera(CameraConnectionFragment.java:408)
at org.tensorflow.demo.CameraConnectionFragment.access$000(CameraConnectionFragment.java:64)
at org.tensorflow.demo.CameraConnectionFragment$1.onSurfaceTextureAvailable(CameraConnectionFragment.java:95)
at android.view.TextureView.getHardwareLayer(TextureView.java:390)
at android.view.TextureView.draw(TextureView.java:339)
at android.view.View.updateDisplayListIfDirty(View.java:18150)
at android.view.View.draw(View.java:18928)
at android.view.ViewGroup.drawChild(ViewGroup.java:4240)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4026)
at android.view.View.updateDisplayListIfDirty(View.java:18141)
at android.view.View.draw(View.java:18928)
at android.view.ViewGroup.drawChild(ViewGroup.java:4240)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4026)
at android.view.View.draw(View.java:19203)
at android.view.View.updateDisplayListIfDirty(View.java:18150)
at android.view.View.draw(View.java:18928)
at android.view.ViewGroup.drawChild(ViewGroup.java:4240)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4026)
at android.view.View.updateDisplayListIfDirty(View.java:18141)
at android.view.View.draw(View.java:18928)
at android.view.ViewGroup.drawChild(ViewGroup.java:4240)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4026)
at android.view.View.updateDisplayListIfDirty(View.java:18141)
at android.view.View.draw(View.java:18928)
at android.view.ViewGroup.drawChild(ViewGroup.java:4240)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4026)
at android.view.View.draw(View.java:19203)
at com.android.internal.policy.DecorView.draw(DecorView.java:825)
at android.view.View.updateDisplayListIfDirty(View.java:18150)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:669)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:675)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:783)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3098)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2912)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2465)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1453)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6958)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalArgumentException: Internal error: Cannot create interpreter: Didn't find custom op for name 'ResizeNearestNeighbor' with version 1
Registration failed.
at org.tensorflow.lite.NativeInterpreterWrapper.createInterpreter(Native Method)
2019-02-09 16:38:28.229 32716-32716/? E/AndroidRuntime: at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:70)
at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:175)
at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:163)
at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.create(TFLiteObjectDetectionAPIModel.java:122)
... 51 more
这里是所有的资源,我可以提供帮助调试此问题:
我找到了解决这一问题。使用TensorFlow v1.13.0-rc1
出现在这一点上解决问题。
这是因为TensorFlow精简版的ResizeNearestNeighbor
操作并不存在,直到V1.13,我意识到,我的主要错误是在看文档V1.13尽管使用V1.12。