Skip to content

Instantly share code, notes, and snippets.

@navarasu
Last active Mar 4, 2019
Embed
What would you like to do?
Main Dart for Loading TF Lite assets example
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:camera/camera.dart';
List<CameraDescription> cameras;
var labels, colors;
Future<void> main() async {
try {
cameras = await availableCameras();
} on CameraException catch (e) {
print('Error: $e.code\nError Message: $e.message');
}
await _loadModel();
runApp(ObjectDetectApp());
}
Future<Null> _loadModel() async {
try {
const platform = const MethodChannel('francium.tech/tensorflow');
var jsonString = await rootBundle.loadString('assets/yolov2-tiny.meta');
var metaData = json.decode(jsonString);
labels = metaData["labels"];
colors = metaData["colors"];
metaData["blockSize"] = 32;
metaData["threshold"] = 0.5;
metaData["overlap_threshold"] = 0.7;
metaData["max_result"] = 15;
final String result = await platform.invokeMethod('loadModel',
{"modal_path": "assets/yolov2_graph.lite", "meta_data": metaData});
print(result);
} on PlatformException catch (e) {
print('Error: $e.code\nError Message: $e.message');
}
}
class ObjectDetectApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Center(
child: Text('Object Detector'),
)),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment