tensorflow - 资源调用 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。当我点击分类图像按钮时
在这里,我尝试通过此按钮将图像上传到模型,然后处理并返回输出
解决方案
推荐阅读
- python - Django 渲染和重定向 URL
- reactjs - 改为部署在子目录下/
- database - 分离 TFS 数据库时的后果和对用户的影响
- hibernate - 如何使用 JPARepository 仅返回目标实体
- c++ - 如何在右键单击时删除表格行
- ruby-on-rails - 将 paypal payflow 与 rails 集成
- javascript - 在移动设备上的图像之间滑动(左右)的最佳/最简单方法是什么?
- scala - 列表未在“foreach”语句中更新,返回空列表
- c# - 有没有办法通过脚本改变画布内元素的层顺序?
- xamarin - 在 Visual Studio 2019 for Mac 版本 8.2 之后无法构建