models icon indicating copy to clipboard operation
models copied to clipboard

Tensorflow Object Detection API using Faster RCNN on Android devices.

Open AliceDinh opened this issue 8 years ago • 43 comments

Please go to Stack Overflow for help and support:

http://stackoverflow.com/questions/tagged/tensorflow

Also, please understand that many of the models included in this repository are experimental and research-style code. If you open a GitHub issue, here is our policy:

  1. It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).
  2. The form below must be filled out.

Here's why we have that policy: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.


System information

  • What is the top-level directory of the model you are using: object_detection
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Window 10
  • TensorFlow installed from (source or binary): binary, installed from pip: pip install tensorflow
  • TensorFlow version (use command below): 1.8
  • Bazel version (if compiling from source): None
  • CUDA/cuDNN version: None
  • GPU model and memory: None
  • Exact command to reproduce: None

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the problem

I used TensorFlow Android Camera Demo, which is TF Detect, at this link: (https://github.com/tensorflow/tensorflow/tree/r1.9/tensorflow/examples/android) I trained my own model using SSD w/Mobilenet detector using my own data, then I imported the frozen model (about 20MB) to Android project and it was working well on my phone: Samsung S7Edge, 4GB Ram. Now, I changed from SSD w/Mobilenet detector to Faster RCNN because Faster RCNN gives higher accuracy as many people stated. The frozen model is checked on Jupyter Notebook and the result is good. The frozen model is about 110MB and I imported to Android project. With 4GB Ram of Samsung S7Edge I believe it will be okies but there is no output result and the app crashed. So, my questions are:

Is Faster RCNN model not suitable for mobile? what should I do to make it work on Mobile?

Source code / logs

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem.

AliceDinh avatar Jul 20 '18 10:07 AliceDinh

@derekjchow - can you comment on device compatibility for Faster RCNN?

karmel avatar Jul 20 '18 20:07 karmel

Faster-RCNN models tend to be very compute intensive (compared to SSD models). Additionally, Faster-RCNN models contain a crop-and-resize step that is not supported in the TFLite run time. For these reasons, we would not recommend using them for mobile inference.

We highly recommend using SSD models for mobile. In particular, we've done a lot of work to support 8-bit quantized inference for SSD models in TFLite. In addition, if you use TF-Lite, certain phones will support hardware acceleration via NNAPI.

Could you describe which SSD models you're working with? It's quite likely that you can get a more accurate SSD model. For example, you can try changing the feature extractor or input resolution. See our paper Speed/accuracy trade-offs for modern convolutional object detectors for more details. In addition, we have also released FPN/PPN SSD networks which may also give additional performance.

derekjchow avatar Jul 30 '18 17:07 derekjchow

@derekjchow Thanks for your reply. I am using SSD (ssd_mobilenet_v1_coco.config) to train my own model: detect numbers on ATM card (like SamsungPay app). The ATM card has the standard size 660x416 and digits on cards can be considered medium/small objects that challenging SSD detector.

If I use default SSD configuration, inputs are 660x416 images, annotations are made based on those inputs, after 18K steps, the loss is about 1.2 and the accuracy is low. 1

I reckoned that due to the resizing step of SSD to 300x300, my inputs' size 660x416 (width:height !=1:1) made the training time longer and the accuracy lower, so I changed my inputs to 660x660, re-annotated, re-trained. After all, the accuracy is not improved. 2 So, please recommend me what should I do to improve the accuracy in my case!

AliceDinh avatar Jul 31 '18 07:07 AliceDinh

@AliceDinh du you has find some idea to improve?

justinshaohi avatar Aug 01 '18 02:08 justinshaohi

@justinshaohi I am trying different sizes of input, low resolution, then high resolution, that's all I can do at the moment.

AliceDinh avatar Aug 01 '18 03:08 AliceDinh

@AliceDinh i'm trying faster-rcnn-lowproposals that has high accuary now,it cost 30s in huawei mate10, what cost time you want be?

justinshaohi avatar Aug 01 '18 03:08 justinshaohi

@justinshaohi I think <10s is acceptible. Which one did you use?

faster_rcnn_nas_lowproposals_coco 
faster_rcnn_resnet50_lowproposals_coco
faster_rcnn_resnet101_lowproposals_coco
faster_rcnn_inception_resnet_v2_atrous_lowproposals_coco

AliceDinh avatar Aug 01 '18 03:08 AliceDinh

@AliceDinh <10s you can try ssd_resnet_fpn,about 8s. i use faster_rcnn_inception_resnet_v2_lowproposals

justinshaohi avatar Aug 01 '18 04:08 justinshaohi

@justinshaohi

  1. Which config file I need for ssd-resnet-fpn and faster-rcnn-inception-resnet-v2-lowproposals, from this: https://github.com/tensorflow/models/tree/master/research/object_detection/samples/configs
  2. What's about the accuracy? my model cannot detect all 16 digits in cards

AliceDinh avatar Aug 01 '18 06:08 AliceDinh

@AliceDinh ssd_fpn ,faster_rcnn,you should modify proposal

justinshaohi avatar Aug 01 '18 09:08 justinshaohi

@justinshaohi thanks, I'll let you know the result

AliceDinh avatar Aug 01 '18 09:08 AliceDinh

@AliceDinh hi,Are you making some progress?

justinshaohi avatar Aug 03 '18 06:08 justinshaohi

@justinshaohi not yet, I'll let you know soon

AliceDinh avatar Aug 03 '18 09:08 AliceDinh

Could you try a different SSD model? Resnet50 with FPN is likely a better choice if you want more accuracy.

derekjchow avatar Aug 03 '18 21:08 derekjchow

@derekjchow hi,what about your suggestion?Resnet50 with fpn in coco the ap is hightest。

justinshaohi avatar Aug 04 '18 05:08 justinshaohi

@justinshaohi training SSD Resnet50 v1 FPN shared box predictor 640x640 coco14 sync took me whole day to fix errors. It is running now but very slow and the training process is very strange to me (model_main.py), look so different from previous API version that trainned with train.py.

AliceDinh avatar Aug 07 '18 07:08 AliceDinh

@derekjchow and @justinshaohi I trained SSD Resnet50 v1 FPN shared box predictor 640x640 using my data successfully. At the step 90, the loss = 2.38, I exported the model to frozen version and test on Jupyter Notebook but there is no object detected at all. I understood that because of the loss (2.38) is high but how many step did you guy experiment to get the loss < 1.0? In addition, I got following warnings very often:

WARNING:tensorflow:Ignoring ground truth with image id 71228663 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 71228663 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 2079479980 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 2079479980 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 1957142769 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 1957142769 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 1588859256 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 1588859256 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 92837305 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 92837305 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 430125779 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 430125779 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 2079045287 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 2079045287 since it was previously added
WARNING:tensorflow:Ignoring ground truth with image id 1901661324 since it was previously added
WARNING:tensorflow:Ignoring detection with image id 1901661324 since it was previously added

Were these warnings affect the training loss? Finally, in the log file:

Line 362591: INFO:tensorflow:Saving dict for global step 300: DetectionBoxes_Precision/mAP = 0.5842264, DetectionBoxes_Precision/mAP (large) = -1.0, DetectionBoxes_Precision/mAP (medium) = 0.70651263, DetectionBoxes_Precision/mAP (small) = 0.611413, DetectionBoxes_Precision/[email protected] = 0.9775049, DetectionBoxes_Precision/[email protected] = 0.60967016, DetectionBoxes_Recall/AR@1 = 0.39410138, DetectionBoxes_Recall/AR@10 = 0.63885885, DetectionBoxes_Recall/AR@100 = 0.63885885, DetectionBoxes_Recall/AR@100 (large) = -1.0, DetectionBoxes_Recall/AR@100 (medium) = 0.74444443, DetectionBoxes_Recall/AR@100 (small) = 0.6387502, Loss/classification_loss = 1.0245702, Loss/localization_loss = 0.30647928, Loss/regularization_loss = 0.68715733, Loss/total_loss = 2.0182207, global_step = 300, learning_rate = 0.01733305, loss = 2.0182207 Line 362893: INFO:tensorflow:loss = 0.76684856, step = 301 Line 362895: INFO:tensorflow:Loss for final step: 0.7582265.

So I wonder the loss = 2.0182207 of step 300, how it dropped quickly to 0.76684856 at step 301? I really confused about this.

AliceDinh avatar Aug 08 '18 03:08 AliceDinh

@AliceDinh do you set fine_tune_checkpoint and from_detection_checkpoint is true,it can help you training faster. and below is my loss ,about 2k step to 0.7 _20180809144901

justinshaohi avatar Aug 09 '18 06:08 justinshaohi

@justinshaohi yes I did set this: fine_tune_checkpoint and from_detection_checkpoint is true. Maybe I need to wait for more steps to get the loss<1.0

AliceDinh avatar Aug 09 '18 07:08 AliceDinh

@lxyyang you don't need to freaze,just put the frozen_inference_graph.pb to asset,and modify here

justinshaohi avatar Aug 09 '18 07:08 justinshaohi