gpt4 book ai didi

tensorflow - 资源无法调用关闭 -flutter/tflite 错误

转载 作者:行者123 更新时间:2023-12-05 07:04:12 25 4
gpt4 key购买 nike

我想在 flutter 中做图像处理。我在 flutter 中加载了 ml 模型(tflite)。在这里,我成功地从 gallery/camera 中获取了图像。我一直在处理部分图像。我没有得到所需的输出。请帮助我

    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)
],
),
),
),
);
}
}

这是应用程序的用户界面。当我点击分类图像按钮

Image

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

This is an error

最佳答案

由于 onFrame 方法缺少灰度支持,tflite 似乎会抛出 BufferOverflowException。该问题应该已按照此 GitHub issue ticket 中所述得到解决.

关于tensorflow - 资源无法调用关闭 -flutter/tflite 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62994059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com