tensorflow / models

Models and examples built with TensorFlow
Other
77.01k stars 45.78k forks source link

Object Detection on Android is abnormally slow #4069

Closed giorigor closed 6 years ago

giorigor commented 6 years ago

System information

Describe the problem

After following these great tutorials, I was able to train my own Object Detection models. For the training, I've used around 1600 images (1300 train + 300 test) in 6 categories and trained the models until the loss stabilized below the 0.05 mark on TensorBoard.

The first model I used was the faster_rcnn_inception_v2_coco model, and it works like a charm on my computer, but not so great on my phone: after exporting it to the TF Detect demo app, I`ve noticed that it was only running the object detection every 30~60 seconds, or more. I would show imy phone an object, then only after a minute its boundaries were drawn.

Things I tried:

I don't need "real-time butter smooth 144 detections per second" performance, but it would be great if I could get something faster than a detection every minute. Is there another step for optimizing object detection models for mobile that I couldn't find anywhere else? Or is something wrong with the demo and I should make my own detection app from scratch?

Source code / logs

Android Studio debugger output (Amazon Fire 7 + ssd_inception_v2_coco)


I/tensorflow: CameraConnectionFragment: Valid preview sizes: [480x480, 640x480, 720x480, 720x720, 800x480, 800x600, 800x800, 864x480, 960x540, 1280x720, 1600x912, 1600x1200]
              CameraConnectionFragment: Rejected preview sizes: [176x144, 320x240, 352x288, 480x320, 480x368]
              CameraConnectionFragment: Exact size match found.
I/art: Background partial concurrent mark sweep GC freed 4116(240KB) AllocSpace objects, 2(84MB) LOS objects, 36% free, 7MB/11MB, paused 935us total 127.001ms
W/tensorflow: TensorFlowObjectDetectionAPIModel: ???
W/tensorflow: TensorFlowObjectDetectionAPIModel: label1
W/tensorflow: TensorFlowObjectDetectionAPIModel: label2
              TensorFlowObjectDetectionAPIModel: label3
              TensorFlowObjectDetectionAPIModel: label4
              TensorFlowObjectDetectionAPIModel: label5
W/tensorflow: TensorFlowObjectDetectionAPIModel: label6
I/TensorFlowInferenceInterface: Checking to see if TensorFlow native methods are already loaded
I/TensorFlowInferenceInterface: TensorFlow native methods already loaded
I/TensorFlowInferenceInterface: Model load took 1438ms, TensorFlow version: 1.8.0-rc1
I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/ssd_inference_graph.pb'
I/tensorflow: DetectorActivity: Camera orientation relative to screen canvas: 90
              DetectorActivity: Initializing at size 640x480
E/tensorflow: ObjectTracker: libtensorflow_demo.so not found, tracking unavailable
I/tensorflow: MultiBoxTracker: Initializing ObjectTracker: 640x480
E/tensorflow: ObjectTracker: Native object tracking support not found. See tensorflow/examples/android/README.md for details.
W/ResourceType: Attempt to retrieve bag 0x0103003e which is invalid or in a cycle.
E/tensorflow: MultiBoxTracker: Object tracking support not found. See tensorflow/examples/android/README.md for details.
I/tensorflow: DetectorActivity: Preparing image 1 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 1
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
           [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
           [Mali]max_allowed_dequeued_buffers=3
I/Kernel: [ 5675.354224].(3)[19526:tensorflow.demo]lowmemorykiller: Killing '.amazon.venezia' (19801), adj 12, score_adj 705,
          [ 5675.354224]   to free 51316kB on behalf of 'tensorflow.demo' (19526) because
          [ 5675.354224]   cache 146736kB is below limit 147456kB for oom_score_adj 529
          [ 5675.354224]   Free memory is 0kB above reserved
I/Kernel: [ 5675.472659].(3)[19527:tensorflow.demo]lowmemorykiller: Killing 'azon.kindle.cms' (18630), adj 12, score_adj 705,
          [ 5675.472659]   to free 44224kB on behalf of 'tensorflow.demo' (19527) because
          [ 5675.472659]   cache 145512kB is below limit 147456kB for oom_score_adj 529
          [ 5675.472659]   Free memory is 0kB above reserved
I/Kernel: [ 5675.653276].(2)[19529:tensorflow.demo]lowmemorykiller: Killing 'om.amazon.tahoe' (19754), adj 12, score_adj 705,
I/Kernel: [ 5675.653276]   cache 138356kB is below limit 147456kB for oom_score_adj 529
          [ 5675.653276]   Free memory is 0kB above reserved
I/Kernel: [ 5675.751049].(0)[19526:tensorflow.demo]lowmemorykiller: Killing 'evice.messaging' (19734), adj 12, score_adj 705,
          [ 5675.751049]   to free 34896kB on behalf of 'tensorflow.demo' (19526) because
          [ 5675.751049]   cache 137348kB is below limit 147456kB for oom_score_adj 529
          [ 5675.751049]   Free memory is 0kB above reserved
I/Kernel: [ 5675.777268].(3)[19527:tensorflow.demo]lowmemorykiller: Killing 'on.sync.service' (19448), adj 12, score_adj 705,
          [ 5675.777268]   to free 29884kB on behalf of 'tensorflow.demo' (19527) because
          [ 5675.777268]   cache 137012kB is below limit 147456kB for oom_score_adj 529
          [ 5675.777268]   Free memory is 0kB above reserved
I/Kernel: [ 5675.895443].(2)[19528:tensorflow.demo]lowmemorykiller: Killing 'h2clientservice' (19482), adj 12, score_adj 705,
          [ 5675.895443]   to free 33808kB on behalf of 'tensorflow.demo' (19528) because
          [ 5675.895443]   cache 135308kB is below limit 147456kB for oom_score_adj 529
          [ 5675.895443]   Free memory is 0kB above reserved
I/Kernel: [ 5675.976866].(1)[19528:tensorflow.demo]lowmemorykiller: Killing 'VMetricsProcess' (18717), adj 12, score_adj 705,
          [ 5675.976866]   to free 21516kB on behalf of 'tensorflow.demo' (19528) because
          [ 5675.976866]   cache 132396kB is below limit 147456kB for oom_score_adj 529
          [ 5675.976866]   Free memory is 0kB above reserved
I/art: Explicit concurrent mark sweep GC freed 1683(130KB) AllocSpace objects, 1(49MB) LOS objects, 39% free, 5MB/8MB, paused 793us total 108.477ms
I/tensorflow: MultiBoxTracker: Processing 0 results from 1
I/tensorflow: DetectorActivity: Preparing image 418 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 418
I/Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.
I/tensorflow: MultiBoxTracker: Processing 1 results from 418
I/tensorflow: DetectorActivity: Preparing image 751 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 751
I/Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.
I/tensorflow: MultiBoxTracker: Processing 0 results from 751
I/tensorflow: DetectorActivity: Preparing image 1096 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 1096
I/Choreographer: Skipped 47 frames!  The application may be doing too much work on its main thread.
I/Kernel: [ 5804.275921].(0)[19526:tensorflow.demo][STP-PSM] [I]_stp_psm_stp_is_idle: **IDLE is over 5000 msec, go to sleep!!!**
I/tensorflow: MultiBoxTracker: Processing 0 results from 1096
I/tensorflow: DetectorActivity: Preparing image 1386 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 1386
I/tensorflow: MultiBoxTracker: Processing 0 results from 1386
I/tensorflow: DetectorActivity: Preparing image 2029 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 2029
I/art: Explicit concurrent mark sweep GC freed 34323(1262KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 5MB/8MB, paused 907us total 68.107ms
I/tensorflow: MultiBoxTracker: Processing 0 results from 2029
I/tensorflow: DetectorActivity: Preparing image 2351 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 2351
I/tensorflow: MultiBoxTracker: Processing 1 results from 2351
I/tensorflow: DetectorActivity: Preparing image 2673 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 2673
I/tensorflow: MultiBoxTracker: Processing 2 results from 2673
I/tensorflow: DetectorActivity: Preparing image 2996 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 2996
I/art: Explicit concurrent mark sweep GC freed 24655(897KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 5MB/8MB, paused 793us total 61.978ms

[... it keeps going on like that ...]```

_(Yeah the poor tablet keeps running out of memory, but even the mighty Galaxy S8 with double the ammount of RAM also took the same time to detect the objects.)_
achowdhery commented 6 years ago

We have updated the instructions on this. It should be fast now. https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193