java.lang.ArrayIndexOutOfBoundsException
Closed this issue · 14 comments
Hi I made my own pb file. However, I got an error that I do not know.
The pb file seems to load well
10/15 10:23:57: Launching android-yolo-v2-master
$ adb install-multiple -r -t -p org.tensorflow.yolo C:\Users\pine\Desktop\Tensorflow Object Dection\Yolo\android-yolo-v2-master\gradleBuild\intermediates\split-apk\debug\dep\dependencies.apk C:\Users\pine\Desktop\Tensorflow Object Dection\Yolo\android-yolo-v2-master\gradleBuild\intermediates\split-apk\debug\slices\slice_5.apk C:\Users\pine\Desktop\Tensorflow Object Dection\Yolo\android-yolo-v2-master\gradleBuild\intermediates\split-apk\debug\slices\slice_8.apk C:\Users\pine\Desktop\Tensorflow Object Dection\Yolo\android-yolo-v2-master\gradleBuild\outputs\apk\debug\android-yolo-v2-master-debug.apk
Split APKs installed
$ adb shell am start -n "org.tensorflow.yolo/org.tensorflow.yolo.view.ClassifierActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 29722 on device samsung-sm_g950n-ce02171295db6c2501
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
E/Zygote: isWhitelistProcess - Process is Whitelisted
W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SM-G950N_8.0.0_0016, [-1 -1 -1 -1 0 1]
I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=org.tensorflow.yolo
I/zygote64: Late-enabling -Xcheck:jni
D/ActivityThread: Added TimaKeyStore provider
I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/egl/libGLES_mali.so from the current namespace instead.
D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
I/InstantRun: starting instant run server: is main process
I/zygote64: Do partial code cache collection, code=30KB, data=17KB
After code cache collection, code=30KB, data=17KB
Increasing code cache capacity to 128KB
I/TextToSpeech: Sucessfully bound to com.samsung.SMT
D/OpenGLRenderer: HWUI GL Pipeline
D/ViewRootImpl@334c0e0[ClassifierActivity]: setView = DecorView@d7a8f99[ClassifierActivity] TM=true MM=false
I/TextToSpeech: Connected to ComponentInfo{com.samsung.SMT/com.samsung.SMT.SamsungTTSService}
D/ViewRootImpl@334c0e0[ClassifierActivity]: dispatchAttachedToWindow
I/TextToSpeech: Set up connection to ComponentInfo{com.samsung.SMT/com.samsung.SMT.SamsungTTSService}
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl@334c0e0[ClassifierActivity]: Relayout returned: old=[0,0][0,0] new=[0,0][1080,2220] result=0x7 surface={valid=true 544431398912} changed=true
D/ViewRootImpl@334c0e0[ClassifierActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 0 - 0, 144) vi=Rect(0, 0 - 0, 144) or=1
D/ViewRootImpl@334c0e0[ClassifierActivity]: MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@45b8c55 nm : org.tensorflow.yolo ic=null
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
D/libGLESv1: STS_GLApi : DTS, ODTC are not allowed for Package : org.tensorflow.yolo
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000, [1080x2220]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0x7ed0a0fd10
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
I/CameraManagerGlobal: Connecting to camera service
D/VendorTagDescriptor: addVendorDescriptor: vendor tag id 3854507339 added
I/TensorFlowInferenceInterface: Checking to see if TensorFlow native methods are already loaded
E/zygote64: No implementation found for long org.tensorflow.contrib.android.RunStats.allocate() (tried Java_org_tensorflow_contrib_android_RunStats_allocate and Java_org_tensorflow_contrib_android_RunStats_allocate__)
I/TensorFlowInferenceInterface: TensorFlow native methods not found, attempting to load via tensorflow_inference
I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
I/TensorFlowInferenceInterface: Model load took 13ms, TensorFlow version: 1.6.0-rc1
Successfully loaded model from 'file:///android_asset/five_fist_20000_yoloGraph.pb'
I/YOLO: Sensor orientation: 90, Screen orientation: 0
I/YOLO: Initializing at size 640x480
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
I/YOLO: Opening camera preview: 640x480
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@c89f10d nm : org.tensorflow.yolo ic=null
I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
I/zygote64: Deoptimizing org.tensorflow.yolo.model.BoundingBox org.tensorflow.yolo.YOLOClassifier.getModel(float[], int, int, int, int, int) due to block bounds check elimination
E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.yolo, PID: 29722
java.lang.ArrayIndexOutOfBoundsException: length=3549; index=3549
at org.tensorflow.yolo.YOLOClassifier.getModel(YOLOClassifier.java:88)
at org.tensorflow.yolo.YOLOClassifier.classifyImage(YOLOClassifier.java:71)
at org.tensorflow.yolo.TensorFlowImageRecognizer.recognizeImage(TensorFlowImageRecognizer.java:50)
at org.tensorflow.yolo.view.ClassifierActivity.lambda$onImageAvailable$1$ClassifierActivity(ClassifierActivity.java:107)
at org.tensorflow.yolo.view.ClassifierActivity$$Lambda$1.run(Unknown Source:0)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Application terminated.
It seems the tensorFlowOutput array doesn't have the element which you want to access. Could you please put a brakepoint in the line 82 of the YOLOClassifier and check the size of the tensorFlowOutput array?
Does your retrained modell recognize your classes with darkFlow or darkNet?
Hi @szaza
Of course, when I tested in darknet and darkflow, the re-trained pb file was successful.
The size of the tensorFlowOutput array is 3549
Do you have any problems ?
No, I did not have similar problems so far.
How many classes do you have?
Is there a problem with my pb file?
Unfortunately, I did not have time to check your file, I'm just thinking what could be the problem.
I don't think so that you have problems with your protobuff file.
Did you use the tiny-yolo model from the https://pjreddie.com/darknet/yolov2/, which requires a 416X416x3 long input?
Ok, then the INPUT_SIZE should be modified in the Config.java. The size of the standard tiny-yolo-v2 is 416x416x3, so please create an INPUT_WIDTH and INPUT_HEIGHT constant in the Config.java and change every places in the code where the INPUT_SIZE is used: e.g. here;
I received your opinion, but the result was the same error.
Could you check the size of the tensorFlowOutput after these changes?
You can also try to decrease the number of the cells, by modifying the SIZE in the YOLOClassifier.java.
By default the tiny-yolo-v2 uses 13x13 cells and the size of the tensorflow output should be 13x13x5x(NR_OF_CLASSES + 5);
The length of tensorFlowOutput was still 3549.
I created the weight file by referring to the site below.
https://github.com/unsky/yolo-for-windows-v2
I also created a pb file by referring to the following site
https://github.com/thtrieu/darkflow
Is there a problem with my pb file?
When testing with the webcam, the results were successful.
But I do not know why it does not work on Android phones.
And when I create a pb file using darkflow, does the Tensorflow version work?
Here is the error that appears after changing INPUT_SIZE
I would be so grateful if you give me some advice
E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.yolo, PID: 7539
java.lang.ArrayIndexOutOfBoundsException: length=3549; index=3549
at org.tensorflow.yolo.YOLOClassifier.getModel(YOLOClassifier.java:88)
at org.tensorflow.yolo.YOLOClassifier.classifyImage(YOLOClassifier.java:71)
at org.tensorflow.yolo.TensorFlowImageRecognizer.recognizeImage(TensorFlowImageRecognizer.java:52)
at org.tensorflow.yolo.view.ClassifierActivity.lambda$onImageAvailable$1$ClassifierActivity(ClassifierActivity.java:109)
at org.tensorflow.yolo.view.ClassifierActivity$$Lambda$1.run(Unknown Source:0)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
This implementation works with the standard parameters of the YoloV2, so in case if you change it's parameters, you have to change the parameters inside the implementation as well.
Here you can find a description about how I trained my models: https://sites.google.com/view/tensorflow-example-java-api/complete-guide-to-train-yolo;
I'm glad to hear from you that you managed to solve the problem. I wish all the best for your project!