flutter-ml / google_ml_kit_flutter

A flutter plugin that implements Google's standalone ML Kit
MIT License
952 stars 727 forks source link

Error using google_mlkit_object_detection 0.13.0 ==> "Unable to get file size" #644

Closed basicFlutter closed 2 months ago

basicFlutter commented 3 months ago

Problem: When using google_mlkit_object_detection 0.13.0, I receive the following error: `E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 ... PlatformException(ObjectDetectionError, com.google.mlkit.common.MlKitException: Failed to initialize detector. Unable to get file size, errno=0, null, null)

Settings Applied: I have applied the following settings in my build.gradle file:

android { // ... aaptOptions { noCompress "tflite" // or noCompress "lite" } }

Code : `class CheckDriversLicence { ObjectDetector? objectDetector; List? objects;

Future<List<DetectedObject>> processImage({required InputImage inputImage, required DetectionMode modeProcess}) async {
    objects = [];
    try {
        objectDetector = await init(modeProcess);
        objects = await objectDetector!.processImage(inputImage);
        return objects!;
    } catch (e) {
        logger.e(e);
        await closeDetector();
        throw Exception("error is : $e");
    }
}

Future<void> closeDetector() async {
    if (objectDetector != null) {
        logger.i("close detector");
        await objectDetector?.close();
        objectDetector = null;
    }
}

Future<ObjectDetector?> init(DetectionMode mode) async {
    final modelPathAssets = await getAssetPath('assets/ml/object_labeler.tflite');
    final options = LocalObjectDetectorOptions(
        mode: mode,
        modelPath: modelPathAssets,
        classifyObjects: true,
        multipleObjects: false,
        maximumLabelsPerObject: 20,
        confidenceThreshold: 0.05,
    );
    objectDetector = new ObjectDetector(options: options);
    return objectDetector;
}

Future<String> getAssetPath(String asset) async {
    final path = await getLocalPath(asset);
    await Directory(dirname(path)).create(recursive: true);
    final file = File(path);
    if (!await file.exists()) {
        final byteData = await rootBundle.load(asset);
        await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
    }
    return file.path;
}

Future<String> getLocalPath(String path) async {
    return '${(await getApplicationSupportDirectory()).path}/$path';
}

}`

Full Error Log:

I/OpenGLRenderer( 9026): Davey! duration=1035642ms; Flags=1, FrameTimelineVsyncId=37038496, IntendedVsync=1427329626595866, Vsync=1427329626595866, InputEventId=438491341, HandleInputStart=1427329628028728, AnimationStart=1427329628035708, PerformTraversalsStart=1427329628039822, DrawStart=1427329667374926, FrameDeadline=1427329659929198, FrameInterval=1427329627752166, FrameStartTime=16666666, SyncQueued=1427329669067166, SyncStart=1427329669151645, IssueDrawCommandsStart=1427329669272583, SwapBuffers=1427329682096228, FrameCompleted=1428365269556146, DequeueBufferDuration=12219635, QueueBufferDuration=682396, GpuCompleted=1428365269556146, SwapBuffersCompleted=1427329683094249, DisplayPresentTime=0, I/native ( 9026): I0608 11:45:11.592024 13268 mobile_ssd_tflite_client.cc:203] Model initialized: input_size: 110592, output_locations_size: 30600, preprocessing mean value: 127.5, preprocessing std value: 127.5, inference type: 2 I/native ( 9026): I0608 11:45:11.592206 13268 mobile_ssd_calculator.cc:70] Succeeded in initializing SSD MobileObjectLocalizerV3_1TfLiteClient I/native ( 9026): I0608 11:45:11.592319 13268 box_classifier_calculator.cc:125] Initializing classifier E/native ( 9026): E0608 11:45:11.592592 13267 calculator_graph.cc:809] UNKNOWN: CalculatorGraph::Run() failed in Run: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): E/native ( 9026): E0608 11:45:11.592646 13267 pipeline_jni.cc:96] UNKNOWN: CalculatorGraph::Run() failed in Run: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:126 E/native ( 9026): E/native ( 9026): E0608 11:45:11.593500 13267 pipeline_jni.cc:262] UNKNOWN: Graph has errors: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/scheduler.cc:1162 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:118 E/native ( 9026): E/native ( 9026): E0608 11:45:11.594114 13267 pipeline_jni.cc:262] UNKNOWN: Graph has errors: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/scheduler.cc:1162 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:118 E/native ( 9026): E/MobileVisionBase( 9026): Error preloading model resource E/MobileVisionBase( 9026): com.google.mlkit.common.MlKitException: Failed to initialize detector. Unable to get file size, errno=0 E/MobileVisionBase( 9026): at com.google.mlkit.vision.vkp.PipelineManager.start(com.google.mlkit:vision-internal-vkp@@18.2.2:73) E/MobileVisionBase( 9026): at com.google.mlkit.vision.objects.custom.internal.zze.tryLoad(com.google.mlkit:object-detection-custom@@17.0.1:3) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.model.CustomModelLoader.load(com.google.mlkit:common@@18.10.0:3) E/MobileVisionBase( 9026): at com.google.mlkit.vision.objects.custom.internal.zzf.load(com.google.mlkit:object-detection-custom@@17.0.1:2) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2) E/MobileVisionBase( 9026): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) E/MobileVisionBase( 9026): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2) E/MobileVisionBase( 9026): at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2) E/MobileVisionBase( 9026): at java.lang.Thread.run(Thread.java:1012) I/native ( 9026): I0608 11:45:11.609058 13270 mobile_ssd_tflite_client.cc:203] Model initialized: input_size: 110592, output_locations_size: 30600, preprocessing mean value: 127.5, preprocessing std value: 127.5, inference type: 2 I/native ( 9026): I0608 11:45:11.609148 13270 mobile_ssd_calculator.cc:70] Succeeded in initializing SSD MobileObjectLocalizerV3_1TfLiteClient I/native ( 9026): I0608 11:45:11.609226 13270 box_classifier_calculator.cc:125] Initializing classifier E/native ( 9026): E0608 11:45:11.609662 13267 calculator_graph.cc:809] UNKNOWN: CalculatorGraph::Run() failed in Run: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): E/native ( 9026): E0608 11:45:11.609714 13267 pipeline_jni.cc:96] UNKNOWN: CalculatorGraph::Run() failed in Run: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:126 E/native ( 9026): E/native ( 9026): E0608 11:45:11.610063 13267 pipeline_jni.cc:262] UNKNOWN: Graph has errors: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/scheduler.cc:1162 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:118 E/native ( 9026): E/native ( 9026): E0608 11:45:11.610424 13267 pipeline_jni.cc:262] UNKNOWN: Graph has errors: E/native ( 9026): Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unable to get file size, errno=0 [type.googleapis.com/mediapipe.StatusList='\n\x93\x01\x08\x02\x12\x62\x43\x61lculator::Open() for node \"BoxClassifierCalculator\" failed: #vk Unable to get file size, errno=0\x1a+\n$tflite::support::TfLiteSupportStatus\x12\x03\x31\x30\x32'] E/native ( 9026): === Source Location Trace: === E/native ( 9026): third_party/mediapipe/framework/tool/status_util.cc:139 E/native ( 9026): photos/vision/visionkit/pipeline/scheduler.cc:1162 E/native ( 9026): photos/vision/visionkit/pipeline/pipeline.cc:118 E/native ( 9026): W/System.err( 9026): com.google.mlkit.common.MlKitException: Failed to initialize detector. Unable to get file size, errno=0 W/System.err( 9026): at com.google.mlkit.vision.vkp.PipelineManager.start(com.google.mlkit:vision-internal-vkp@@18.2.2:73) W/System.err( 9026): at com.google.mlkit.vision.objects.custom.internal.zze.tryLoad(com.google.mlkit:object-detection-custom@@17.0.1:3) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.model.CustomModelLoader.load(com.google.mlkit:common@@18.10.0:3) W/System.err( 9026): at com.google.mlkit.vision.objects.custom.internal.zzf.load(com.google.mlkit:object-detection-custom@@17.0.1:2) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2) W/System.err( 9026): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) W/System.err( 9026): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2) W/System.err( 9026): at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2) W/System.err( 9026): at java.lang.Thread.run(Thread.java:1012)

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.