Code Monkey home page Code Monkey logo

Comments (20)

shaqian avatar shaqian commented on August 21, 2024 1

Thank you for the reply.
When you go back from the other screen, do you reload the model? I suspect loadLabels() is called again so label size is multiplied.
Can you please try clearing labels array? Add labels = new Vector<>(); before

while ((line = br.readLine()) != null) {
labels.add(line);
}
labelProb = new float[1][labels.size()];

from flutter_tflite.

emailsubjekt avatar emailsubjekt commented on August 21, 2024 1

Thank you for the reply.
When you go back from the other screen, do you reload the model? I suspect loadLabels() is called again so label size is multiplied.
Can you please try clearing labels array? Add labels = new Vector<>(); before
flutter_tflite/android/src/main/java/sq/flutter/tflite/TflitePlugin.java

Lines 107 to 110 in 624c46d

while ((line = br.readLine()) != null) {
labels.add(line);
}
labelProb = new float[1][labels.size()];

Thanks! This works. =)
For ios in TflitePlugin.mm there's labels.clear(); in the close() method so I'm guessing that one should be ok then for the ios side?

Just one more thing irrelevant to this discussion, when running the project I keep getting this notification

Note: C:\flutter.pub-cache\hosted\pub.dartlang.org\tflite-0.0.5\android\src\main\java\sq\flutter\tflite\TflitePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

I was also getting it before applying your solution. Everything works great and it compiles and runs on the phone, just thought I'd mention it so you know.

Awesome project by the way, and thanks for making it! You've got a beer from me.

from flutter_tflite.

SergioBernal8 avatar SergioBernal8 commented on August 21, 2024 1

I had a similar bug!
After searching and searching I realized that the ".txt" files that I dowloaded from the Git for the assets folder was incorrect. Then I fixed that and everything its working fine now!
By the way I'm using detectObjectOnImage with the model "SSDMobileNet"
tflite version: 1.0.2

Hope it helps!!

from flutter_tflite.

shaqian avatar shaqian commented on August 21, 2024

Thank you for the feedback.
Would it be convenient for you to provide a sample project that reproduces the issue?

from flutter_tflite.

emailsubjekt avatar emailsubjekt commented on August 21, 2024

Hi, I used your example with no modifications, then modified it with the files I have and the above mentioned modifications I did made no difference to how the app reacted. It works when I first use it even with no modifications to your example code, but when I leave the screen to another screen in the app and come back and try to use it I get the error I wrote out. What I don't understand is how can it work if I have a .lite with 2 possible answers and the example has in one class a definition of numResults = 6 and in another numResults = 5, yet it still provides me a correct answer when using the app.

I could remake the .lite for the project but you could remake it really easy too. I can't unfortunately send you the original as it's proprietary and from a client I'm making this for, but it's a .lite with 2 possible answers as is the accompanying txt file which has the names of the options written out. As I said the example works great, I get a result meaning the file I'm using works and has worked on an Android version perfectly. However, here I keep getting this error after using it going to another screen in the app and then coming back.

Contact me if you need help with making a .lite file, I'll be happy to help you solve this...

from flutter_tflite.

shaqian avatar shaqian commented on August 21, 2024

Glad to know it works. šŸ˜ƒI will add the fix in the next version.

from flutter_tflite.

emailsubjekt avatar emailsubjekt commented on August 21, 2024

I've tried version 1.0.1 What did you do, the import is red, I'm using import 'package:tflite/tflite.dart'; like your instructions say and it says 'Target of URI doesn't exist: 'package:tflite/tflite.dart'.' after fliding over it with the mouse to see why it's red.
Also, why isn't there an example what to write into pubspec, you write "Add tflite as a dependency in your pubspec.yaml file." and then it takes me to the general info about adding dependencies. I know that, how do I add yours? Like this -> tflite: ^1.0.1 ?

Also, I had a calculation of the final output and showed the result on the screen, I updated to that 1.0.1 (also tried 1.0.0) and now no screen result is showing. I'm working on another app now and don't have time to look into this but why would you change the output, now I have to do this again.

from flutter_tflite.

shaqian avatar shaqian commented on August 21, 2024

There are some breaking changes since 1.0.0
https://github.com/shaqian/flutter_tflite#breaking-changes-since-100

I think you were using 0.0.2 or 0.0.3. The latest version that doesn't break your code might be 0.0.5.
https://pub.dartlang.org/packages/tflite#-changelog-tab-

You can try fixing the version like tflite: 0.0.5, then run flutter packages get. If you still get red squiggly lines, go to ios folder and run pod install.

Thanks,
Qian

from flutter_tflite.

emailsubjekt avatar emailsubjekt commented on August 21, 2024

Ok, thanks for the answer I will look into it in a couple of days, keep up the great work! =)

from flutter_tflite.

brunokitaka avatar brunokitaka commented on August 21, 2024

I'm trying to use a tflite file that I trained myself and I'm getting this error:

E/flutter (24486): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 9, 9, 30]., null)
E/flutter (24486): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (24486): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter (24486):
E/flutter (24486): #2 Tflite.detectObjectOnFrame (package:tflite/tflite.dart:152:27)
E/flutter (24486):
E/flutter (24486): #3 _CameraState.initState.. (package:flutter_realtime_detection/camera.dart:50:20)
E/flutter (24486): #4 CameraController.startImageStream. (package:camera/camera.dart:353:20)
E/flutter (24486): #5 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (24486): #6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (24486): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (24486): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (24486): #9 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (24486): #10 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (24486): #11 _PendingEvents.schedule. (dart:async/stream_impl.dart:667:7)
E/flutter (24486): #12 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (24486): #13 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #14 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #15 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #16 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (24486): #17 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #18 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #19 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (24486): #21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

from flutter_tflite.

emailsubjekt avatar emailsubjekt commented on August 21, 2024

I'm trying to use a tflite file that I trained myself and I'm getting this error:

E/flutter (24486): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 9, 9, 30]., null)
E/flutter (24486): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (24486): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter (24486):
E/flutter (24486): #2 Tflite.detectObjectOnFrame (package:tflite/tflite.dart:152:27)
E/flutter (24486):
E/flutter (24486): #3 _CameraState.initState.. (package:flutter_realtime_detection/camera.dart:50:20)
E/flutter (24486): #4 CameraController.startImageStream. (package:camera/camera.dart:353:20)
E/flutter (24486): #5 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (24486): #6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (24486): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (24486): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (24486): #9 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (24486): #10 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (24486): #11 _PendingEvents.schedule. (dart:async/stream_impl.dart:667:7)
E/flutter (24486): #12 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (24486): #13 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #14 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #15 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #16 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (24486): #17 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #18 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #19 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (24486): #21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Well, this is your problem --> Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 9, 9, 30]., null) - You've trained it wrong.

from flutter_tflite.

shaqian avatar shaqian commented on August 21, 2024

Archiving the thread as the original issue is fixed in new version.

@brunokitaka Feel free to raise a new issue if you still get error with your model.

Thanks,
Qian

from flutter_tflite.

amit-dingare avatar amit-dingare commented on August 21, 2024

Hi I trained the Mobilenet model on certain domain specific images using transfer learning. But, when I try to run the model, I get "Cannot copy between a TensorFlowLite tensor with shape [1, 11] and a Java object with shape [1, 11, 4]". I have 11 classes in my dataset. How may I fix the issue?

from flutter_tflite.

amit-dingare avatar amit-dingare commented on August 21, 2024

After searching and searching I realized that the ".txt" files that I dowloaded from the Git for the assets folder was incorrect. Then I fixed that and everything its working fine now!

When you say the txt files were incorrect, what do you mean? Incorrect in what sense?

from flutter_tflite.

rash1994 avatar rash1994 commented on August 21, 2024

I'm trying to use a tflite file that I trained myself and I'm getting this error:
E/flutter (24486): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 9, 9, 30]., null)
E/flutter (24486): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (24486): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter (24486):
E/flutter (24486): #2 Tflite.detectObjectOnFrame (package:tflite/tflite.dart:152:27)
E/flutter (24486):
E/flutter (24486): #3 _CameraState.initState.. (package:flutter_realtime_detection/camera.dart:50:20)
E/flutter (24486): #4 CameraController.startImageStream. (package:camera/camera.dart:353:20)
E/flutter (24486): #5 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (24486): #6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (24486): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (24486): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (24486): #9 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (24486): #10 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (24486): #11 _PendingEvents.schedule. (dart:async/stream_impl.dart:667:7)
E/flutter (24486): #12 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (24486): #13 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #14 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #15 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #16 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (24486): #17 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (24486): #18 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (24486): #19 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter (24486): #20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (24486): #21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Well, this is your problem --> Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 9, 9, 30]., null) - You've trained it wrong.

Can you tell trained it wrong meaning ?
what is wrong is training?

from flutter_tflite.

EyeSlash1998 avatar EyeSlash1998 commented on August 21, 2024

Hi I trained the Mobilenet model on certain domain specific images using transfer learning. But, when I try to run the model, I get "Cannot copy between a TensorFlowLite tensor with shape [1, 11] and a Java object with shape [1, 11, 4]". I have 11 classes in my dataset. How may I fix the issue?

Were you able to solve this issue, because even I'am facing an issue were I get the error "Cannot copy between a TensorFlow Lite tensor with shape [1,2535,9] and a java object with shape [1,13,13,45]".

from flutter_tflite.

supermarille avatar supermarille commented on August 21, 2024

Same issue here :
java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 10, 4] and a Java object with shape [1, 1]
I have only one class, I followed this tutorial https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tensorflowlite.md using bazel to convert to tflite.
I understand that the second value of the shape should be the number of classes, but what are the other values ?

from flutter_tflite.

rxsh96 avatar rxsh96 commented on August 21, 2024

I have the same problem: Cannot copy between a TensorFlowLite tensor with shape [1, 1] and a Java object with shape [1, 2]
I have MobileNetV2 as input layer, 1 flatten and 3 dense layers and then converted to tflite. I have 2 classes in my dataset. Is there some kind of limitation for tflite-flutter package does not work with custom models?

from flutter_tflite.

shaharhn avatar shaharhn commented on August 21, 2024

Any solution ?

from flutter_tflite.

nikunj5022 avatar nikunj5022 commented on August 21, 2024

Hi I trained the Mobilenet model on certain domain specific images using transfer learning. But, when I try to run the model, I get "Cannot copy between a TensorFlowLite tensor with shape [1, 11] and a Java object with shape [1, 11, 4]". I have 11 classes in my dataset. How may I fix the issue?

Were you able to solve this issue, because even I'am facing an issue were I get the error "Cannot copy between a TensorFlow Lite tensor with shape [1,2535,9] and a java object with shape [1,13,13,45]".

Any solution?

from flutter_tflite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.