Hi I am building an application to identify type of flower using Flutter and Tflite for machine learning. I have some problem after testing the app. The apps was able to identify types of flower which I trained on Google Teachable Machine, but I need it to show some kind of popup message or notification such as " This is not a flower" if other object was capture using camera.
Here is my code for your reference. How I can achieve this? I have take a look beside trained mode with label Unknown_Object on Google Teachable Machine, is there any other option I have?
class _DetailsState extends State<Details> {
final _screenshotController = ScreenshotController();
void _takeScreenshot() async {
final imageFile = await _screenshotController.capture();
Share.shareFiles([imageFile.path], text: "share from this app");
}
bool loading = false;
bool detecting = false;
var output;
List snapshotsFlower;
@override
void initState() {
super.initState();
loadModel();
}
//Load the Tflite model
loadModel() async {
setState(() {
loading = true;
});
await Tflite.loadModel(
model: "assets/model_unquant.tflite",
labels: "assets/labels.txt",
);
setState(() {
loading = false;
});
classifyImage(widget.imageFile);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
children: <Widget>[
Image.file(
widget.imageFile,
//height: MediaQuery.of(context).size.height / 2.5,
height: MediaQuery.of(context).size.height / 1.8,
width: double.maxFinite,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Text(DemoLocalization.of(context).getTranslatedValue('result'),
style: TextStyle(fontSize: 20),
textAlign: TextAlign.center,
),
),
),
SizedBox(height: 22.0,),
GestureDetector(
onTap: () {
if (output != null) {
for (var v in snapshotsOfPlants) {
// print(v.data['name'].toString().toLowerCase());
// print(output[0]['label'].toString().split(' ')[1].toLowerCase());
if (v.data['name'].toString().toLowerCase() ==
output[0]['label']
.toString()
.split(' ')[1]
.toLowerCase()) {
/* Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) => Profile(
post: v,
),
),
);*/
break;
}
}
}
},
child: ListTile(
leading: Icon(output != null
? output.isEmpty ? Icons.close : Icons.info
: FontAwesomeIcons.arrowAltCircleUp,
color: Colors.green,
size: 30.0,),
trailing: loading
? CircularProgressIndicator()
: detecting
? CircularProgressIndicator()
: Text(output != null
? output.isEmpty
? ''
: '${(output[0]['confidence'] * 100).floor()}' +
'%'
: '',
style: TextStyle(
fontSize: 1.0,
color: Colors.transparent,
),
),
title: Center(
child: Text(
loading
? 'Wait'
: detecting
? 'Scanning'
: output != null
? output.isEmpty
? 'Unidentified image'
//: 'Scanning show flower: ${output[0]['label'].toString().split(' ')[1]}'
: ' ${output[0]['label'].toString().split(' ')[1]}'
: '',
style: TextStyle(
fontSize: 25.0,
),
),
),
),
),
SizedBox(height: 60.0,),
Center(
child: Container(
width: 100,
height: 100,
child: FlatButton(
textColor: Colors.black87,
color: Colors.white,
//onPressed: _takeScreenshot,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.share,
color: Colors.black87,
),
),
Text(DemoLocalization.of(context).getTranslatedValue('share'), style: TextStyle(
color: Colors.black87,
),)
],
),
),
),
)