Object Detection frozen models not working on Android
Hi.
I have a custom trained model I did using the Object Detection API, and the frozen version, produced by the export_inference_graph.py is not being compiled while trying to deploy it on Android, specifically the TF Detect project.
This is the error
11-17 16:27:14.092 12447-12447/org.tensorflow.demo E/tensorflow: CameraActivity: Exception!
java.lang.RuntimeException: Failed to load model from 'file:///android_asset/juan/ssd_mobilenet_v1_android_export.pb'
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.<init>(TensorFlowInferenceInterface.java:113)
at org.tensorflow.demo.TensorFlowObjectDetectionAPIModel.create(TensorFlowObjectDetectionAPIModel.java:91)
at org.tensorflow.demo.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:175)
at org.tensorflow.demo.CameraActivity.onPreviewFrame(CameraActivity.java:120)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1183)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.io.IOException: Not a valid TensorFlow Graph serialization: NodeDef mentions attr 'T' not in Op<name=Where; signature=input:bool -> index:int64>; NodeDef: Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/FilterGreaterThan/Where = Where[T=DT_BOOL](Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/FilterGreaterThan/Where/Cast). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.loadGraph(TensorFlowInferenceInterface.java:535)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.<init>(TensorFlowInferenceInterface.java:105)
at org.tensorflow.demo.TensorFlowObjectDetectionAPIModel.create(TensorFlowObjectDetectionAPIModel.java:91)
at org.tensorflow.demo.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:175)
at org.tensorflow.demo.CameraActivity.onPreviewFrame(CameraActivity.java:120)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1183)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
11-17 16:30:06.722 12447-12465/org.tensorflow.demo E/libGLESv1: HWUI Protection: wrong call from hwui context F:ES1-glDeleteTexturesSEC
11-17 16:30:21.832 12447-12459/org.tensorflow.demo E/BufferQueueProducer: [SurfaceTexture-0-12447-2] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=5 undequeued=1)
Is this the actual right way to freeze a model to used on Android? Or is there another way to freeze a model for that use case?
Thanks
@andrewharp can you offer any advice?
have u quantized the model? I met this issue after quantized the frozen model
@offbye What do you mean by that? Could you explain it? What I did is what is referred as "exporting a trained model for inference" or simply "freezing" the model. It is discussed here: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/exporting_models.md
I think you're doing something wrong. First, you freeze the model then you load it frozen on Android. You do freeze it on Android. Just check the Android FT app and see how it's loaded.
@mpeniak Mmm...as far I as understand, I am freezing the model first to generate my .pb file. Said .pb file is what I am trying to load to Android. I believe my loading "pipeline" is correctly, because the app is being created. However, upon opening it, I get the error I posted before.
My code on the Android side is basically a copy of the Android FT app. In fact, I was able to load one of the Android frozen model Google provides.
I have the exact same issue. Unable to load a frozen model that was trained on the cloud on my android phone. Gives the same error as above. Can someone help?
@sakethbsv how are you generating the model? Maybe we could help ourselves.
has anyone fine the solution?
i train faster_rcnn_resnet101_coco model in cloud, and export to frozen .pb file when i put it in android in DetectorActivity.java it's not work, what's problem ?
I have the same problem in Android Studio building the demo app with my retrained model. Please help
I have also same problem can anyone if try share to solve this problem.
maybe because faster_rcnn_resnet101_coco is very larger, cant run in android
when i choose ssd_mobilnet_v1, it's work fine
We have updated the instructions on this: https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193