- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 117
Closed
Description
I have been facing the following exception when running the method yolo.predict.
E/flutter (18496): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: InferenceException: Error during image prediction: Inference failed: MissingPluginException(No implementation found for method predictSingleImage on channel yolo_single_image_channel_default)
E/flutter (18496): #0      YOLOInference.predict (package:ultralytics_yolo/core/yolo_inference.dart:69:7)
E/flutter (18496): <asynchronous suspension>
E/flutter (18496): #1      YOLO.predict (package:ultralytics_yolo/yolo.dart:211:12)
E/flutter (18496): <asynchronous suspension>
E/flutter (18496): #2      _MyHomePageState._takePicAndDetect (package:test_app/blurring.dart:53:19)
E/flutter (18496): <asynchronous suspension>
E/flutter (18496): 
This problem happens on both Android and iOS, and with a lib version >= 0.1.38. With version 0.1.37 is working correctly.
Sample code
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ultralytics_yolo/yolo.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'Flutter Demo', home: const MyHomePage());
  }
}
class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  String dectStr = "";
  bool isProcessing = false;
  XFile? selectedFile;
  Map<String, dynamic> objDetect = {};
  late YOLO yolo;
  Future<void> _initYolo() async {
    yolo = YOLO(
      modelPath: Platform.isIOS ? 'yolo11n' : 'yolo11n.tflite',
      task: YOLOTask.detect,
    );
    await yolo.loadModel();
  }
  Future<void> _takePicAndDetect() async {
    setState(() {
      dectStr = "";
      isProcessing = true;
    });
    selectedFile = (await ImagePicker().pickImage(source: ImageSource.gallery));
    if (selectedFile != null) {
      var byte = await selectedFile!.readAsBytes();
      objDetect = await yolo.predict(byte);
      List<Map<String, dynamic>> detections = objDetect["detections"];
      dectStr = "Found ${detections.length} detections\n\n";
      detections.forEach(
        (d) => dectStr += "${d["className"]} with conf ${d["confidence"]}\n",
      );
    }
    setState(() {
      isProcessing = false;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("TEST")),
      body: FutureBuilder(
        future: _initYolo(),
        builder: (context, snap) {
          if (snap.connectionState != ConnectionState.done) {
            return Center(child: CircularProgressIndicator());
          }
          return Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                ElevatedButton(
                  onPressed: _takePicAndDetect,
                  child: Text("Pick image and detect"),
                ),
                if (selectedFile != null)
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 16),
                    child: Image.file(File(selectedFile!.path)),
                  ),
                if (isProcessing) CircularProgressIndicator(),
                if (!isProcessing) Text(dectStr),
              ],
            ),
          );
        },
      ),
    );
  }
}
Metadata
Metadata
Assignees
Labels
No labels