首页 > 解决方案 > 资源调用 close -flutter/tflite 错误失败

问题描述

我想在颤振中进行图像处理。我在颤动中加载了 ml 模型(tflite)。在这里,我成功地从画廊/相机中获取了图像。我一直在处理图像的一部分。我没有得到所需的输出。请帮我

    import 'dart:io';
    import 'package:flutter/material.dart';
    import 'package:image_picker/image_picker.dart';
    import 'package:tflite/tflite.dart';


    void main() {
      runApp(new MaterialApp(
          title: "corona",
          home: LandingScreen(),
      ));
    }

    class LandingScreen extends StatefulWidget {
      @override
      _LandingScreenState createState() => _LandingScreenState();
    }

    class _LandingScreenState extends State<LandingScreen> {
      File imageFile;
      String result;
      String path;
    
      _openGallery(BuildContext context) async {
        var picture = await ImagePicker.pickImage(source: ImageSource.gallery);
        this.setState(() {
          imageFile = picture;
          path = picture.path;
        });
        Navigator.of(context).pop();
      }
    
      _openCamera(BuildContext context) async {
        var picture = await ImagePicker.pickImage(source: ImageSource.camera);
        this.setState(() {
          imageFile = picture;
          path = picture.path;
        });
        Navigator.of(context).pop();
      }
    
    
      // **classifyimage function to process the image from tflite**
    
      Future classifyImage() async {
        await Tflite.loadModel(
          model: "assets/covid19_densenet.tflite",
          labels: "assets/x.txt",
        );
        var output = await Tflite.runModelOnImage(path: path);
    
        setState(() {
          result = output.toString();
        });
      }
    
      // Other functions
    
      Future<void> _showChoiceDialog(BuildContext context) {
        return showDialog(context: context, builder: (BuildContext context) {
          return AlertDialog(
            title: Text("Make a Choose!"),
            content: SingleChildScrollView(
              child: ListBody(
                children: <Widget>[
                  GestureDetector(
                    child: Text("Gallery"),
                    onTap: () {
                      _openGallery(context);
                    },
                  ),
                  Padding(padding: EdgeInsets.all(8.0)),
                  GestureDetector(
                    child: Text("Camera"),
                    onTap: () {
                      _openCamera(context);
                    },
                  )
                ],
              ),
            ),
          );
        });
      }
    
      Widget _decideImageView() {
        if (imageFile == null) {
          return Text("No Image Selected!");
        } else {
          return Image.file(imageFile, width: 400, height: 400);
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("CORONA DETECTION"),
          ),
          body: Container(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  _decideImageView(),
                  RaisedButton(
                    onPressed: () {
                      _showChoiceDialog(context);
                    },
                    child: Text("select image!"),
                  ),
    
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    child: RaisedButton(
                      onPressed: () => classifyImage(),
                      child: Text('Classify Image'),
                      textColor: Colors.white,
                      color: Colors.blue,
                      padding: EdgeInsets.fromLTRB(12, 12, 12, 12),
                    ),
                  ),
    
                  result == null ? Text('Result') : Text(result)
                ],
              ),
            ),
          ),
        );
      }
    }

这是应用程序的 UI。当我点击分类图像按钮时

图片

在这里,我尝试通过此按钮将图像上传到模型,然后处理并返回输出

这是一个错误

标签: tensorflowflutterdartflutter-layouttensorflow-lite

解决方案


推荐阅读