Repository navigation
Description
I have compiled and installed the demo app according to the instruction in the README. The "TF Detect" and "TF Classify" apps are working as expected. However, starting the "TF Stylize" app, it always crashes in about 3 seconds. The prebuilt apk crashes in the same way. Here is the android logcat recorded:
$ adb -s b80360c7 logcat | grep Tensor
I/TensorFlowInferenceInterface( 6801): Checking to see if TensorFlow native methods are already loaded
I/TensorFlowInferenceInterface( 6801): TensorFlow native methods not found, attempting to load via tensorflow_inference
I/TensorFlowInferenceInterface( 6801): Successfully loaded TensorFlow native methods (RunStats error may be ignored)
I/TensorFlowInferenceInterface( 6801): Model load took 540ms, TensorFlow version: 1.0.1
I/TensorFlowInferenceInterface( 6801): Successfully loaded model from 'file:///android_asset/stylize_quantized.pb'
E/TensorFlowInferenceInterface( 6801): Failed to run TensorFlow inference with inputs:[input, style_num], outputs:[transformer/expand/conv3/conv/Sigmoid]
E/TensorFlowInferenceInterface( 6801): Inference exception: java.lang.IllegalArgumentException: input_max_range must be larger than input_min_range.
E/TensorFlowInferenceInterface( 6801): [[Node: transformer/contract/conv1/Relu_eightbit_quantize_transformer/contract/conv1/InstanceNorm/batchnorm/add_1 = QuantizeV2[T=DT_QUINT8, mode="MIN_FIRST", _device="/job:localhost/replica:0/task:0/cpu:0"](transformer/contract/conv1/InstanceNorm/batchnorm/add_1, transformer/contract/conv1/Relu_eightbit_min_transformer/contract/conv1/InstanceNorm/batchnorm/add_1, transformer/contract/conv1/Relu_eightbit_max_transformer/contract/conv1/InstanceNorm/batchnorm/add_1)]]
E/AndroidRuntime( 6801): at org.tensorflow.contrib.android.TensorFlowInferenceInterface.getTensor(TensorFlowInferenceInterface.java:486)
E/AndroidRuntime( 6801): at org.tensorflow.contrib.android.TensorFlowInferenceInterface.readNodeIntoFloatBuffer(TensorFlowInferenceInterface.java:332)
E/AndroidRuntime( 6801): at org.tensorflow.contrib.android.TensorFlowInferenceInterface.readNodeFloat(TensorFlowInferenceInterface.java:287)
As can be inferred from the logcat, the problem happens in tensorflow/core/kernels/quantize_op.cc line 71. The app is using a quantized model. I found that input_min_range is set to be inf, and input_max_range is -inf, which is obviously wrong.
What should be done to fix it?
The crash appears on Samsung Galaxy S4, but does not appears on emulator with Intel CPU.
[Edit]
With more experiment I found that sometimes the apps works without crashing, about 1 out of 10 trials.
Activity
BrianOn99 commentedon Mar 21, 2017
It is found that if
DEBUG_MODELis set totruein StylizeActivity.java, which replace the camera captured bitmap with a predefined one, the app will not crash.andrewharp commentedon Mar 21, 2017
Do the other demos work for you? If so, I'm guessing the preview frame size it's choosing is broken somehow (stylization uses a larger one than the other demos).
Can you paste a full log please?
BrianOn99 commentedon Mar 22, 2017
@andrewharp thanks for looking into this issue. Actually the other demo has some non-fatal problems (I thought they were unrelated).
TF classify
TF Detect
I can reproduce all of these problems, except "Failed" Toast, in another phone (LG G4c, also android 5). So could it be android 5 specific problem. I have no more phones on my hand for testing so could somebody here try it out?
Here is the full log from the LG phone captured from AndroidStudiio:
BrianOn99 commentedon Mar 22, 2017
I would like to emphasize that this issue does not always happen. Sometimes stylization works for several frames and then crash due to this issue.
andrewharp commentedon Mar 22, 2017
It's probably giving back an unexpected buffer format:
03-22 11:01:12.200 9698-9717/org.tensorflow.demo D/ImageReader_JNI: ImageReader_imageSetup: Overriding buffer format YUV_420_888 to 32315659.32315659 maps to NV12.What is the
android.info.supportedHardwareLevelon your device? Some devices don't fully support the camera2 api, unfortunately, and emulate it problematically internally.If you press the volume keys you'll turn on debug mode, which will render the image being processed. Might be helpful to see what that looks like in each of the demos.
BrianOn99 commentedon Mar 22, 2017
It is "2", which correspond to INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY. So does it mean the issue cannot be solved?
BrianOn99 commentedon Mar 22, 2017
If it cannot be solved I think it would be better to show a warning on the demo app for those phones.
BrianOn99 commentedon Mar 22, 2017
If it is suitable I can contribute code or just make a test.
andrewharp commentedon Mar 22, 2017
The best thing to do would probably be to interact with the camera via the original android.hardware.Camera if the supportedHardwareLevel or Android API level is too low.
If you or someone else would like to contribute that it would be very much appreciated. This might also resolve #7464.
andrewharp commentedon Mar 22, 2017
An easier workaround would be if INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY is detected, just use the Y (luminance) plane. It can be mapped directly into RGB grayscale values. Detection quality might suffer a small amount (so a toast/log message would be warranted), but at least it wouldn't crash.
andrewharp commentedon Mar 23, 2017
@BrianOn99 What is your device's API level? I'm wondering if maybe it might just be a good idea to use android.hardware.Camera on devices < API 23. There is an example of doing that here.
andrewharp commentedon Mar 24, 2017
@BrianOn99 Another idea from the other issue: can you try hardcoding the size to 1920x1080? It's a few more pixels to convert YUV->RGB than 1468x1200, but it may behave better because it's a more popular video size and so would have had more testing by Samsung.
BrianOn99 commentedon Mar 24, 2017
Thanks. I will try it later today.
BrianOn99 commentedon Mar 24, 2017
Do you mean changing the previewSize in CameraConnectionFragment?
21 remaining items
tensorflowbutler commentedon Feb 8, 2018
Nagging Assignee: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Feb 23, 2018
Nagging Assignee: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Mar 10, 2018
Nagging Assignee @andrewharp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Mar 25, 2018
Nagging Assignee @andrewharp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Apr 9, 2018
Nagging Assignee @andrewharp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Apr 24, 2018
Nagging Assignee @andrewharp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon May 10, 2018
Nagging Assignee @andrewharp: It has been 15 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
GL1920 commentedon May 22, 2018
@BrianOn99
I have the same problem as you.But when I replace the camera captured bitmap with a predefined one,I couldn't get a stylized picture , just a grey one.I wanted to ask you how you handled the designated bitmap.
tensorflowbutler commentedon Jun 5, 2018
Nagging Assignee @andrewharp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Jun 20, 2018
Nagging Assignee @andrewharp: It has been 29 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Jul 5, 2018
Nagging Assignee @andrewharp: It has been 44 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Jul 20, 2018
Nagging Assignee @andrewharp: It has been 59 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
tensorflowbutler commentedon Aug 4, 2018
Nagging Assignee @andrewharp: It has been 74 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.
BrianOn99 commentedon Aug 6, 2018
Closed because I don't care about it anymore and this issue has been inactive.