Skip to content

Android Camera Demo sometimes doesn't works #7464

Closed

Description

@davideb91

I have built Tensorflow Android Camera Demo with a custom model.
Sometimes the app works correctly on my phone, but at other times it gives error and is terminated.
These are my adb logcat:

02-13 14:53:44.751 22219 22234 F libc    : Fatal signal 11 (SIGSEGV), code 2, fault addr 0xee9c2000 in tid 22234 (ImageListener)
02-13 14:53:44.801  3038  3038 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-13 14:53:44.801  3038  3038 F DEBUG   : Build fingerprint: 'samsung/zeroltexx/zerolte:6.0.1/MMB29K/G925FXXU4DPGW:user/release-keys'
02-13 14:53:44.801  3038  3038 F DEBUG   : Revision: '10'
02-13 14:53:44.801  3038  3038 F DEBUG   : ABI: 'arm'
02-13 14:53:44.811  3038  3038 F DEBUG   : pid: 22219, tid: 22234, name: ImageListener  >>> org.tensorflow.demo <<<
02-13 14:53:44.811  3038  3038 F DEBUG   : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xee9c2000
02-13 14:53:44.811  3038  3038 F DEBUG   :     r0 000004a8  r1 eec1000c  r2 ee9b800c  r3 00009ff4
02-13 14:53:44.811  3038  3038 F DEBUG   :     r4 00000000  r5 ffffff80  r6 00000662  r7 00000c80
02-13 14:53:44.811  3038  3038 F DEBUG   :     r8 fffffcbf  r9 de0605d8  sl 00009ec0  fp 000001e0
02-13 14:53:44.811  3038  3038 F DEBUG   :     ip 0003ffff  sp f3722408  lr 00000135  pc decf5ee6  cpsr 800e0030
02-13 14:53:44.821  3038  3038 F DEBUG   :
02-13 14:53:44.821  3038  3038 F DEBUG   : backtrace:
02-13 14:53:44.821  3038  3038 F DEBUG   :     #00 pc 00090ee6  /data/app/org.tensorflow.demo-1/lib/arm/libtensorflow_demo.so
02-13 14:53:44.821  3038  3038 F DEBUG   :     #01 pc 00086767  /data/app/org.tensorflow.demo-1/lib/arm/libtensorflow_demo.so (Java_org_tensorflow_demo_env_ImageUtils_convertYUV420ToARGB8888+142)
02-13 14:53:44.821  3038  3038 F DEBUG   :     #02 pc 000523e7  /data/app/org.tensorflow.demo-1/oat/arm/base.odex (offset 0x2b000) (void org.tensorflow.demo.env.ImageUtils.convertYUV420ToARGB8888(byte[], byte[], byte[], int[], int, int, int, int, int, boolean)+218)
02-13 14:53:44.821  3038  3038 F DEBUG   :     #03 pc 0003fdad  /data/app/org.tensorflow.demo-1/oat/arm/base.odex (offset 0x2b000) (void org.tensorflow.demo.ClassifierActivity.onImageAvailable(android.media.ImageReader)+1064)
02-13 14:53:44.821  3038  3038 F DEBUG   :     #04 pc 03c37c61  /system/framework/arm/boot.oat (offset 0x2f37000)
02-13 14:53:45.011  3038  3038 F DEBUG   :
02-13 14:53:45.011  3038  3038 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_07

How can I solve this problem?

Activity

  1. andrewharp commented on Feb 13, 2017

    @andrewharp
    Contributor

    It looks like the yuv>RGB conversion is breaking. What sort of device are you using? On some 5.0 devices only the Y plane gets returned, resulting in a greenish image.

  2. davideb91 commented on Feb 13, 2017

    @davideb91
    Author

    I'm using Android 6.0. The strange thing is that I have this error only sometimes

  3. andrewharp commented on Feb 13, 2017

    @andrewharp
    Contributor

    Thats odd then. When you turn on debug mode (volume button), does the thumbnail image appear normal?

  4. davideb91 commented on Feb 13, 2017

    @davideb91
    Author
  5. andrewharp commented on Feb 13, 2017

    @andrewharp
    Contributor

    That's definitely abnormal. The stride is wrong and the green noise at the bottom is uninitialized data. It's crashing when it tries to access data that it shouldn't be reading from, apparently because the image is a different res than it thinks it is. It's hard to tell just from this image, but does the preview seem stretched on screen as well?

    The question is why there's a mismatch. You might try forcing it to a preview resolution like 640x480 and see if that helps.

    Can you paste the full log please? And what is the exact model of your device? Sometimes camera drivers have odd behavior at particular resolutions.

  6. davideb91 commented on Feb 13, 2017

    @davideb91
    Author

    Here you can find the full log, with all error and warning:
    https://storage.googleapis.com/tensorflow_android_demo/log.txt
    and here the log, with all error, warning and info:
    https://storage.googleapis.com/tensorflow_android_demo/log_info.txt

    My device is a Samsung Galaxy S6.

    Maybe these errors are a problem of my phone. If I use others devices the app seems to work correctly and the thumbnail image appears normal.

  7. andrewharp commented on Feb 13, 2017

    @andrewharp
    Contributor

    Does the preview appear to be rotated? If so, it's probably treating it as a 320x480 image rather than a 480x320 image.

    Can you try hardcoding sensorOrientation in ClassifierActivity.java to be 0? My guess is that this device is returning incorrect info about the rotation of the preview frames.

  8. added
    type:support
    stat:awaiting response
    on Feb 15, 2017
  9. andrewharp commented on Feb 23, 2017

    @andrewharp
    Contributor

    @davideb91 Any luck on this? Also, is there any chance you've made changes to the activity orientation settings in AndroidManifest.xml?

  10. bazinac commented on Feb 27, 2017

    @bazinac

    @andrewharp Hi Andrew, long time no see :). Sorry to bug you in another thread, but we also have come up to this issue. When testing our little app on my friends phone (which is also Galaxy S6) we are also getting this error (SIGSEV 11 when ImageUtils.convertYUV420ToARGB8888 is executed) and this is happening only sometimes.

    Apart of this, twisted bitmap is obtained when we are showing to user what was examined by TF. See in attachement. This only happens on S6. Regarding sensor orientation, we are getting same rotation value as on another phones, so this probably is not the root cause. Maybe some issue with armeabi-v7a and arm64 compatibility of .so libraries? I only compiled armeabi-v7a version assuming that they will work properly on arm64 (on S6) as well.

    s6

    On the other devices which are available to us for testing: Galaxy S5, Xiaomi Mi4, Galaxy J5 and Galaxy Tab S2 9.7, it works fine and displays correct snapshot.

  11. andrewharp commented on Mar 3, 2017

    @andrewharp
    Contributor

    @bazinac Yeah, seems to be some issue with the Samsung Galaxy S6. Would you mind stepping through higher preview resolutions to see if any of them work?

    I doubt it's actually a TF issue, as the preview image shown on the screen is pasted there directly by the camera. Though if the S6 is consistently bad we might want to update the demo to accommodate it anyway. My assumption is that the sigsegv happens because a bug in the camera code is causing it to provide a preview frame that is not the resolution it claimed.

  12. prb12 commented on Mar 10, 2017

    @prb12
    Member

    Closing due to lack of activity.

  13. 1 remaining item

  14. vi7us commented on Mar 13, 2017

    @vi7us

    @andrewharp i tried higher resolution (720) on Galaxy S6 however output still does not look good. So it seems that issue is not related to preview size.
    screenshot_20170303-194946

  15. andrewharp commented on Mar 13, 2017

    @andrewharp
    Contributor

    @vi7us @bazinac You're still using the same camera code and color conversion code as the demo, correct? Does a new build of the TF demo also show the same behavior on the S6 for you? (you can check by turning on debug mode with the volume key)

    @OverratedGman Are you seeing this in the same app as @vi7us and @bazinac ?

  16. vi7us commented on Mar 13, 2017

    @vi7us

    @andrewharp we are using code from tf demo however not the latest build. Right now have quite limited access on internet as we are on holidays and will be able to test using latest tf demo only after 21st March. Is that OK or do you need feedback from us earlier?

  17. andrewharp commented on Mar 22, 2017

    @andrewharp
    Contributor

    @davideb91 @bazinac @OverratedGman @vi7us
    Would you mind logging your device's android.info.supportedHardwareLevel? I'm wondering if this is a common factor in all of this.

  18. bazinac commented on Mar 22, 2017

    @bazinac

    Hi @andrewharp, my android.info.supportedHardwareLevel on Galaxy S5 (which work ok) is 2 (this is INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY probably), and on @vi7us's S6 it is 1 (which is INFO_SUPPORTED_HARDWARE_LEVEL_FULL). Then clearly there is difference. On Galaxy S5 it uses legacy camera HAL. It could be interesting, if someone like @OverratedGman who has Nexus 6p could check it too...

    We will try to run fresh clean TF android demo and check whether it works now. To explain: Our application just originally took some parts of the demo, but it is heavilly modified, so there is no debug mode. I have just discovered that captured bitmaps are not cropped properly on Galaxy S6, resulting into artifacts. I suspect method ImageUtils.convertYUV420ToARGB8888, that should manipulate rgbBytes variable (which is the part I took from the demo). This method also sometimes caused app to crash on Galaxy S6.

    @vi7us is currently building latest TF to see whether mint demo works properly.

    Sorry to have such a long reply latency, we were on the vacation and tried to avoid computers completely :)

  19. vi7us commented on Mar 22, 2017

    @vi7us

    @andrewharp, all,

    I tried using both latest tf demo and our application using latest tf however it seems that thumbnail(s) are still distorted with application crashing occasionally. Attached are screenshot from latest demo and screen
    screenshot_20170323-003440
    shot of android studio when application crashed (using our application), maybe it could help.

    applicationcrash

  20. andrewharp commented on Mar 23, 2017

    @andrewharp
    Contributor

    @vi7us This screenshot is like inception of the Inception model :)

    Ok, so it's failing on some devices with android.info.supportedHardwareLevel of 1, and some of 2 it seems. Unfortunate we can't use that as a discriminating factor.

    A couple more questions:

    • What Android API levels are these devices?
    • If you hardcode the res to something like 640x480, does that help?

    There is an older conversion of the demo from the Camera2 API to use the original android.hardware.Camera here: https://github.com/hamidb/tensorflow/blob/api20/tensorflow/examples/android/src/org/tensorflow/demo/CameraConnectionFragment.java

    I feel this may address your problems -- if it does, contributions welcome to patch the demo to use android.hardware.Camera on lower API levels.

  21. vi7us commented on Mar 23, 2017

    @vi7us

    @andrewharp, @bazinac, @OverratedGman I tried suggested and here is what i got
    First, when some of resolutions are hardcoded, thumbnails look good and application does not crash 🥇 from what i observed, more common res. like 320x240, 640x480, 1280x720, 1920x1080 work, less common like 480x320, 720x480 or 1088x1088 does not. So thanks for this suggestion! Unfortunately I'm not able to confirm if issue is only the resolution as none of "faulty" resolutions can be used on Galaxy S5 device.

    For the hardware level, actually it works on the device with 2 and fails on device with level 1 (however it could by caused by the thumbnail size again)

    Last thing, I was not able to make work the older version of camera class in current demo, however not sure if it is needed.

  22. andrewharp commented on Mar 24, 2017

    @andrewharp
    Contributor

    Great! Thanks for checking that out.

    Maybe it would make sense to set preferred sizes of 640x480 for classification/detection and 1920x1080 for stylization, and have it fall back to the current logic only if they're not available.

    Just to note, the only reason I have it pick the smallest sizes possible right now is to minimize CPU spent converting yuv->RGB and then rescaling. The actual frame size TF sees is always the same. The conversion is relatively fast, though, so doubling the number of pixels is not a huge cost.

  23. vi7us commented on Mar 24, 2017

    @vi7us

    Yes you're right, even when using higher resolutions, application is still smooth so we will probably just filter resolutions to ones that work and use non-supported only in case of none of supported resolutions are available. I do not expect that fall back will happen on many devices.

    Btw i do not think that issue is caused by small resolution as 320*240 works as well, maybe it could be ratio of screen width / height?

  24. andrewharp commented on Mar 24, 2017

    @andrewharp
    Contributor

    Possibly, who knows what black magic is going on inside the camera drivers :p

    I've fixed this internally; should show up in the next internal->external push.

  25. andrewharp commented on Mar 30, 2017

    @andrewharp
    Contributor

    The demo now uses 640x480 for detection/classification and 1280x720 for stylization, which should be more widely supported resolutions.

    If anybody has more issues, can you please replay with your device model/API level/supportedHardwareLevel?

    Remaining problem cases should be covered by #8736, so it would be good to know if there are any devices still experiencing problems with INFO_SUPPORTED_HARDWARE_LEVEL_FULL or greater.

  26. andrewharp commented on Apr 21, 2017

    @andrewharp
    Contributor

    Closing as fixed; please reply with your device model/Android version/supportedHardwareLevel if you continue to experience any similar issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stat:awaiting responsetype:support

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions