-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#import "metal_delegate.h" file not found #184
Comments
I have the same problem using iOS Simulator |
Check the TensorFlowLiteC version in your Podfile.lock, you probably need to downgrade to 2.2.0.
|
Is there a way to get past this without downgrading? |
I think this solution should be written on the readme, no? |
there are so many errors when we downgrade to 2.2.0. This is what finally I got after all ( Only occurred on IOS)
|
Any update on when this issue will be addressed? |
Any update on this? |
I can confirm that this is working. tflite:
git:
url: https://github.com/swarmidentity/flutter_tflite.git
ref: 6ed08242a0d4d34432bf18790846b8a3033a7057 |
How did you implement the confirmed fix? |
i have same problem like this after downgrade to 2.2.0,how solve this? |
The interim fix isn't viable anymore, so i switched from this package to google_mlkit_object_detection: ^0.5.0 for now. Will revert back to this once the package is updated. This is my new code: Initialise the detector in the cubit initialiseDetector({double confidenceThreshold = 0.5, int maximumLabelsPerObject = 10}) async {
emit(ShoddyLoading(state.mainShoddyState.copyWith(message: 'Loading object detector')));
try {
ObjectDetector objectDetector = await ShoddyHelper.initialiseDetector(
processingFromDownloadedFile: true,
modelFile: state.mainShoddyState.modelFile,
confidenceThreshold: confidenceThreshold,
maximumLabelsPerObject: maximumLabelsPerObject,
);
emit(ShoddyModelLoaded(state.mainShoddyState.copyWith(objectDetector: objectDetector, message: 'Ready to start processing images')));
} catch (error) {
emit(ShoddyError(state.mainShoddyState.copyWith(message: error.toString())));
}
} A helper / utilities file to download or use a model file static Future<ObjectDetector> initialiseDetector({File? modelFile, bool processingFromDownloadedFile = true, required double confidenceThreshold, required int maximumLabelsPerObject}) async {
if (processingFromDownloadedFile) {
if (modelFile != null) {
return await initializeLocalDetector(modelFile, confidenceThreshold, maximumLabelsPerObject);
} else {
File modelFile = await loadModelFileFromFirebase();
return await initializeLocalDetector(modelFile, confidenceThreshold, maximumLabelsPerObject);
}
} else {
return await initializeFirebaseDetector(confidenceThreshold, maximumLabelsPerObject);
}
}
// Download the model file from firebase first
static Future<File> loadModelFileFromFirebase(String modelName) async {
try {
FirebaseModelDownloader downloader = FirebaseModelDownloader.instance;
List<FirebaseCustomModel> models = await downloader.listDownloadedModels();
for (FirebaseCustomModel model in models) {
print('Name: ${model.name}');
}
FirebaseModelDownloadConditions conditions = FirebaseModelDownloadConditions(
iosAllowsCellularAccess: true,
iosAllowsBackgroundDownloading: false,
androidChargingRequired: false,
androidWifiRequired: false,
androidDeviceIdleRequired: false,
);
FirebaseCustomModel model = await downloader.getModel(
modelName,
FirebaseModelDownloadType.latestModel,
conditions,
);
File modelFile = model.file;
return modelFile;
} catch (exception) {
print('Failed on loading your model from Firebase: $exception');
print('The program will not be resumed');
rethrow;
}
}
// Use a file downloaded from firebase
static Future<ObjectDetector> initializeLocalDetector(File modelFile, double confidenceThreshold, int maximumLabelsPerObject) async {
try {
final options = LocalObjectDetectorOptions(
mode: DetectionMode.single,
modelPath: modelFile.path,
classifyObjects: true,
multipleObjects: true,
confidenceThreshold: confidenceThreshold,
maximumLabelsPerObject: maximumLabelsPerObject,
);
return ObjectDetector(options: options);
} catch (exception) {
print('Failed on loading your model to the TFLite interpreter: $exception');
print('The program will not be resumed');
rethrow;
}
}
// Use the model file directly from firebase
static Future<ObjectDetector> initializeFirebaseDetector(String modelName, double confidenceThreshold, int maximumLabelsPerObject) async {
try {
final options = FirebaseObjectDetectorOptions(
mode: DetectionMode.single,
modelName: modelName,
classifyObjects: true,
multipleObjects: true,
confidenceThreshold: confidenceThreshold,
maximumLabelsPerObject: maximumLabelsPerObject,
);
return ObjectDetector(options: options);
} catch (exception) {
print('Failed on loading your model to the TFLite interpreter: $exception');
print('The program will not be resumed');
rethrow;
}
} The function to process an image processImage(File file) async {
emit(ShoddyModelProcessing(state.mainShoddyState.copyWith(message: 'Looking for objects on the selected image')));
try {
List<dynamic>? results = [];
if (state.mainShoddyState.objectDetector != null) {
InputImage inputImage = InputImage.fromFilePath(file.path);
List<DetectedObject> objects = await state.mainShoddyState.objectDetector!.processImage(inputImage);
if (objects.isNotEmpty) {
List<ObjectModel> objects = results.map((result) => ObjectModel(result)).toList();
emit(ShoddyModelProcessed(state.mainShoddyState.copyWith(objects: objects, filteredObjects: objects, message: 'Image processed with results')));
changeMatchPercentage(0.35);
} else {
emit(ShoddyModelProcessed(state.mainShoddyState.copyWith(objects: [], filteredObjects: [], message: 'Image processed with no results')));
}
}
} catch (error) {
emit(ShoddyError(state.mainShoddyState.copyWith(message: error.toString())));
}
} |
Xcode's output:
↳
/Users/trendlab/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/ios/Classes/ImagePickerPlugin.m:113:20: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
[[[UIAlertView alloc] initWithTitle:@"Error"
^
In module 'UIKit' imported from /Users/trendlab/AndroidStudioProjects/flutter_my_tflite/ios/Pods/Target Support Files/image_picker/image_picker-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
^
1 warning generated.
/Users/trendlab/.pub-cache/hosted/pub.dartlang.org/tflite-1.1.1/ios/Classes/TflitePlugin.mm:21:9: fatal error: 'metal_delegate.h' file not found
#import "metal_delegate.h"
^~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the precompiled application for the device.
Error launching application on iPhoneX.
The text was updated successfully, but these errors were encountered: