hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 10647, 4]. #301

Closed yangmh66 closed 3 years ago

yangmh66 commented 3 years ago

When I tried to build project and Install on my android phone, I have encountered problem, the log as below:

2021-01-22 18:58:26.093 18112-18343/org.tensorflow.lite.examples.detection E/AndroidRuntime: FATAL EXCEPTION: Thread-2 Process: org.tensorflow.lite.examples.detection, PID: 18112 java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 10647, 4]. at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:412) at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:369) at org.tensorflow.lite.Tensor.copyTo(Tensor.java:247) at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:166) at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:314) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.getDetectionsForFull(YoloV4Classifier.java:392) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:544) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:61) at org.tensorflow.lite.examples.detection.MainActivity.lambda$null$1$MainActivity(MainActivity.java:52) at org.tensorflow.lite.examples.detection.-$$Lambda$MainActivity$OxNL7NrV0ct8jl4zEsUXaD27RnY.run(Unknown Source:4) at java.lang.Thread.run(Thread.java:923)

Any idea?

AndrzejKRK commented 3 years ago

When I tried to build project and Install on my android phone, I have encountered problem, the log as below:

2021-01-22 18:58:26.093 18112-18343/org.tensorflow.lite.examples.detection E/AndroidRuntime: FATAL EXCEPTION: Thread-2 Process: org.tensorflow.lite.examples.detection, PID: 18112 java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 10647, 4]. at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:412) at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:369) at org.tensorflow.lite.Tensor.copyTo(Tensor.java:247) at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:166) at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:314) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.getDetectionsForFull(YoloV4Classifier.java:392) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:544) at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:61) at org.tensorflow.lite.examples.detection.MainActivity.lambda$null$1$MainActivity(MainActivity.java:52) at org.tensorflow.lite.examples.detection.-$$Lambda$MainActivity$OxNL7NrV0ct8jl4zEsUXaD27RnY.run(Unknown Source:4) at java.lang.Thread.run(Thread.java:923)

Any idea?

change variable OUTPUT_WIDTH_FULL from private static final int[] OUTPUT_WIDTH_FULL = new int[]{10647, 10647}; to private static final int[] OUTPUT_WIDTH_FULL = new int[]{2535, 2535};

yangmh66 commented 3 years ago

Thanks for your reply!! When I modified the variable: isTiny from false to true, this error was gone!! The yolo-model file in assets directory was tiny model, but current configure in source code was full yolo!! If anyone wants to run this android project, he needs to take care of that by himself! (or download source code with the commit_id: 087052f, which's android project was workable)