tensorflow / flutter-tflite

Apache License 2.0
541 stars 126 forks source link

Issue with TensorflowLite Interpreter in IOS release build #96

Open shaheer20 opened 1 year ago

shaheer20 commented 1 year ago

I am passing the tflite file to the interpreter but it returns nothing. This is only happening when I download the IOS build from a test flight. Running an app with IDE works fine.

tfl.Interpreter? interpreter = await tfl.Interpreter.fromAsset('assets/config/mobilefacenet.tflite');

I have also tried

tfl.Interpreter.fromFile(File(path));

But this also doesn't return anything.

How I am testing: I have added a stack view with a Text widget on that and added logs into a string and print the text to check which line is executed. I am not getting any error even if I add this interpreter into try-catch. I have added a text before assigning the value to the interpreter and after the value is assigned to the interpreter only the before-added text shows not after one. This is why I am assuming it got stuck while assigning and didn't return anything.

gregorscholz commented 1 year ago

can you maybe show more code? it is hard to tell whats wrong from this snippet

shaheer20 commented 1 year ago

@gregorscholz This where I am getting the issue.

Screenshot 2023-06-21 at 1 05 00 PM

Now i am getting this Error in catch: 'error while loading invalid arguments(s): Failed to lookup symbol 'TfLiteModelCreate': dlsym(RTLD_DEFAULT, TfLiteModelCreate): symbol not found'

gregorscholz commented 1 year ago

Did you double check if the model is correct? Maybe there is some error with the model?

shaheer20 commented 1 year ago

It is working fine on Android and IOS (debug) . The issue only occurs in the build i download from test flight for IOS.

gregorscholz commented 1 year ago

Oh sorry, yea, mb. I think i've read some time back someone had also problems with ios release build while it worked in debug. I will try to find it

Edit: Maybe one of those can help https://github.com/shaqian/flutter_tflite/issues/171#issuecomment-929597880 https://github.com/tensorflow/tensorflow/issues/49897#issuecomment-850914325

shaheer20 commented 1 year ago

Thanks for the links.

https://github.com/shaqian/flutter_tflite/issues/171#issuecomment-929597880: This is showing how can i load the model. I don't have any issue with loading the model it just happens when I pass model to Interpreter. I have tried to get the model into a file and check the size that shows I am getting the right file and there is no issue in getting the file.

https://github.com/tensorflow/tensorflow/issues/49897#issuecomment-850914325: This example shows an error while compiling I only get an error when I run the app on an IOS device in release (From test flight).

peazz commented 1 year ago

Was a solution found to this? I’m facing the same issues. Works fine in debug but release doesn’t on TestFlight

shaheer20 commented 1 year ago

Not yet. Did you try the below solution is any one of this works for you? https://github.com/shaqian/flutter_tflite/issues/171#issuecomment-929597880 https://github.com/tensorflow/tensorflow/issues/49897#issuecomment-850914325

kvanry commented 1 year ago

@shaheer20 Did you follow this step: https://github.com/tensorflow/flutter-tflite#android--ios

Specifically:

When creating a release archive (IPA), the symbols are stripped by Xcode, so the command flutter build ipa may throw a Failed to lookup symbol ... symbol not found error. To work around this:

In Xcode, go to Target Runner > Build Settings > Strip Style Change from All Symbols to Non-Global Symbols

I had a similar issue recently and that was the solution.

shaheer20 commented 1 year ago

@kvanry Thanks it works fine by changing All Symbols to Non-Global Symbols. But It's not working on iPhone 7.

sarthakydv commented 1 year ago

@PaulTR FireStore recommends statically linked libraries, is there a plan to make a more robust fix for this for better integration with other google products?

denis-kolkov commented 7 months ago

Hello. I have a similar problem in 2024. Everything works in the debug version, but the release version does't work. Xcode does't add the framework to the ipa file.

I'm using the latest version of tflite_flutter: ^0.10.4 Options: Strip Style = Non-Global Symbols Strip Linked Product = No

MacBook Pro Apple M1 Pro Sonoma 14.3 (23D56) Xcode Version 15.2 (15C500b)

I also tried adding frameworks manually. They are added to the ipa package, but the package cannot be installed or uploaded to TestFly.

Asset validation failed Invalid Bundle. The bundle Runner.app/Frameworks/TensorFlowLite.framework does not support the minimum OS Version specified in the Info.plist. (ID: 8c2faa9d-72b6-4024-b1b2-4849a7aa2afe)

What am I doing wrong in my life? :) Thanks in advance for your help.

cs-milan-sadariya commented 5 months ago

@gregorscholz This where I am getting the issue. Screenshot 2023-06-21 at 1 05 00 PM

Now i am getting this Error in catch: 'error while loading invalid arguments(s): Failed to lookup symbol 'TfLiteModelCreate': dlsym(RTLD_DEFAULT, TfLiteModelCreate): symbol not found'

For this issue issue you need to change XCode settings under the Target Runner. Follow the below 2 simple steps and your app will start to working in released mode also.

Step 1: In Xcode, go to Target Runner > Build Settings > Strip Style Step 2: Change from All Symbols to Non-Global Symbols

SantroTechneAi commented 4 months ago

Hi @shaheer20 , Have you find our solution for your issue? I am facing same issue.Hello @cs-milan-sadariya, You provided solution not working.I am still facing "Failed to lookup symbol 'TfLiteModelCreate': dlsym(RTLD_DEFAULT, TfLiteModelCreate): symbol not found" for IOS

cs-milan-sadariya commented 4 months ago

@gregorscholz This where I am getting the issue. Screenshot 2023-06-21 at 1 05 00 PM Now i am getting this Error in catch: 'error while loading invalid arguments(s): Failed to lookup symbol 'TfLiteModelCreate': dlsym(RTLD_DEFAULT, TfLiteModelCreate): symbol not found'

For this issue issue you need to change XCode settings under the Target Runner. Follow the below 2 simple steps and your app will start to working in released mode also.

Step 1: In Xcode, go to Target Runner > Build Settings > Strip Style Step 2: Change from All Symbols to Non-Global Symbols

@SantroTechneAi try this solution it has worked for me and this solution is also available on flutter package code. Follow the below link: tflite_flutter

phobosbag commented 3 months ago

same problem in release from TestFlight Invalid argument(s): Failed to lookup symbol 'TfLiteModelCreate': dlsym(RTLD_DEFAULT, TfLiteModelCreate): symbol not found

0 DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33)

1 TensorFlowLiteBindings._TfLiteModelCreatePtr (package:tflite_flutter/src/bindings/tensorflow_lite_bindings_generated.dart:63)

2 TensorFlowLiteBindings._TfLiteModelCreate (package:tflite_flutter/src/bindings/tensorflow_lite_bindings_generated.dart)

3 TensorFlowLiteBindings.TfLiteModelCreate (package:tflite_flutter/src/bindings/tensorflow_lite_bindings_generated.dart)

4 new Model.fromBuffer (package:tflite_flutter/src/model.dart:51)

5 new Interpreter.fromBuffer (package:tflite_flutter/src/interpreter.dart:108)

6 Interpreter.fromAsset (package:tflite_flutter/src/interpreter.dart:126)

I will try Non-Global Symbols solution
phobosbag commented 3 months ago

it is working

In Xcode, go to Target Runner > Build Settings > Strip Style
Change from All Symbols to Non-Global Symbols