java.lang.IllegalArgumentException:无法从具有形状[1,2535,4]的Tensorflowlite张量复制到具有形状的Java对象[1,10,4]
我想使用openCV使用openCV进行手机摄像机的应用程序,并使用tensorflow lite来检测对象。因此,我从github https://github.com/bendahouwael/bendahouwael/vehicle-detection中找到了不错的代码。 -App-android 使用OpenCV进行相机和Tensorflow Lite。要测试我自己的TensorFlow Lite文件,我更改了ObjectDetectorClass = new ObjectDetectorClass(getAssets(),“ SSD_MobiLenet.tflite”,“ labelmap.txt”,300),300);
getAssets(),“ tiny-416.tflite”,“ car.txt”,416); 位于cameraactivity.java
中。
另外,在objectDetectorClass.java
我更改了
if(quant==0){
byteBuffer=ByteBuffer.allocateDirect(4*1*416*416*3);
}
else {
byteBuffer=ByteBuffer.allocateDirect(1*1*416*416*3);
}
我在github https://github.com/dohnutseo/my-own-tensorflow-lite-lite-file/tree/tree/main 带有readme中的标签txt。
我在Android Studio中搜索了整个错误消息
E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: com.example.Detection, PID: 19290
java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (Identity) with shape [1, 2535, 4] to a Java object with shape [1, 10, 4].
at org.tensorflow.lite.Tensor.throwIfDstShapeIsIncompatible(Tensor.java:482)
at org.tensorflow.lite.Tensor.copyTo(Tensor.java:252)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:175)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:360)
at com.example.imagepro.objectDetectorClass.recognizeImage(objectDetectorClass.java:92)
at com.example.imagepro.CameraActivity.onCameraFrame(CameraActivity.java:125)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
at java.lang.Thread.run(Thread.java:923)
,并发现了许多问题,这些问题与原始TFLITE文件不同。因此,我试图更改此代码中的大小,但找不到如何更改它。帮助我解决这个问题。
我还使用了此站点 https://netron.app/ 看到我自己的Tensorflow Lite Lite文件的形状输入
name: input_1
type: float32[1,416,416,3]
location: 0
感谢所有答复!
edit1) 要回答@farmaker,您是说来自ObjectDetectorClass.java的代码吗?
float[][][]boxes =new float[1][10][4];
float[][] scores=new float[1][10];
float[][] classes=new float[1][10];
我将其更改为
float[][][]boxes =new float[1][2535][4];
float[][] scores=new float[1][10];
float[][] classes=new float[1][10];
,但仍然有错误。
I want to make application using opencv for phone camera using and tensorflow lite to detect objects. So I found nice code from github https://github.com/bendahouwael/Vehicle-Detection-App-Android that uses opencv for camera and tensorflow lite. To test my own tensorflow lite files, I changed objectDetectorClass=new objectDetectorClass(getAssets(),"ssd_mobilenet.tflite","labelmap.txt",300);
to objectDetectorClass=new objectDetectorClass(getAssets(),"tiny-416.tflite","car.txt",416);
which is located in CameraActivity.java
.
Also, in objectDetectorClass.java
I changed
if(quant==0){
byteBuffer=ByteBuffer.allocateDirect(4*1*416*416*3);
}
else {
byteBuffer=ByteBuffer.allocateDirect(1*1*416*416*3);
}
I uploaded my tflite file in my github https://github.com/dohnutSeo/my-own-tensorflow-lite-file/tree/main with label txt in readme.
And the whole error message in Android Studio is
E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: com.example.Detection, PID: 19290
java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (Identity) with shape [1, 2535, 4] to a Java object with shape [1, 10, 4].
at org.tensorflow.lite.Tensor.throwIfDstShapeIsIncompatible(Tensor.java:482)
at org.tensorflow.lite.Tensor.copyTo(Tensor.java:252)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:175)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:360)
at com.example.imagepro.objectDetectorClass.recognizeImage(objectDetectorClass.java:92)
at com.example.imagepro.CameraActivity.onCameraFrame(CameraActivity.java:125)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
at java.lang.Thread.run(Thread.java:923)
I searched for this issue and found many question that said input tensor size is different with original tflite file. So I tried to change the size in this code but could not find how to change it. Help me to solve this issue.
Also I used this site https://netron.app/ to see the shaped of my own tensorflow lite file which says input is
name: input_1
type: float32[1,416,416,3]
location: 0
Thanks for all replies!
Edit1)
To answer @Farmaker, do you mean the code from objectDetectorClass.java?
float[][][]boxes =new float[1][10][4];
float[][] scores=new float[1][10];
float[][] classes=new float[1][10];
I changed it to
float[][][]boxes =new float[1][2535][4];
float[][] scores=new float[1][10];
float[][] classes=new float[1][10];
but still I had errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论