Open akaanuzman opened 1 year ago
I am getting null as a result of runModelOnImage method. Do you have a solution? Can you help me?
// ignore_for_file: depend_on_referenced_packages import 'dart:io'; import 'dart:math' hide log;
import 'package:tflite/tflite.dart'; import 'package:flutter/material.dart'; import 'dart:developer'; import 'package:http/http.dart' as http; import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart';
class FoodReccomendationViewModel extends ChangeNotifier { late String? response; List results = [];
Future loadAIModelFromAsset() async { Tflite.close(); response = await Tflite.loadModel( model: "assets/ai/age_gender_estimation.tflite", labels: "assets/ai/age_gender_labels.txt", numThreads: 2, ); log("Model loaded: $response"); }
Future disposeModel() async { await Tflite.close(); }
Future imageClassification(String imageUrl) async { File file = await _fileFromImageUrl(imageUrl); log(file.path); try {
var recognitions = await Tflite.runModelOnImage( path: file.path, ); results = recognitions ?? []; notifyListeners(); log("Results is: $results"); log("Recognitions is: $recognitions"); } catch (e) { log(e.toString()); }
}
Future _fileFromImageUrl(String imageUrl) async { final response = await http.get(Uri.parse(imageUrl)); final documentDirectory = await getApplicationDocumentsDirectory(); String randomNumber = (Random().nextInt(899999) + 100000).toString(); final file = File(join(documentDirectory.path, '$randomNumber.jpg')); file.writeAsBytesSync(response.bodyBytes); return file; } }
DEBUG CONSOLE: D/EGL_emulation( 1990): app_time_stats: avg=88.81ms min=2.92ms max=3563.28ms count=46 I/tflite ( 1990): Replacing 16 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 1 partitions for the whole graph. [log] Model loaded: success D/EGL_emulation( 1990): app_time_stats: avg=20.34ms min=2.89ms max=760.86ms count=56 [log] /data/user/0/com.example.digital_order_system/app_flutter/391694.jpg V/time ( 1990): Inference took 29 [log] Results is: [] [log] Recognitions is: []
recheck your file path
I am getting null as a result of runModelOnImage method. Do you have a solution? Can you help me?
// ignore_for_file: depend_on_referenced_packages import 'dart:io'; import 'dart:math' hide log;
import 'package:tflite/tflite.dart'; import 'package:flutter/material.dart'; import 'dart:developer'; import 'package:http/http.dart' as http; import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart';
class FoodReccomendationViewModel extends ChangeNotifier { late String? response; List results = [];
Future loadAIModelFromAsset() async { Tflite.close(); response = await Tflite.loadModel( model: "assets/ai/age_gender_estimation.tflite", labels: "assets/ai/age_gender_labels.txt", numThreads: 2, ); log("Model loaded: $response"); }
Future disposeModel() async { await Tflite.close(); }
Future imageClassification(String imageUrl) async { File file = await _fileFromImageUrl(imageUrl); log(file.path); try {
}
Future _fileFromImageUrl(String imageUrl) async {
final response = await http.get(Uri.parse(imageUrl));
final documentDirectory = await getApplicationDocumentsDirectory();
String randomNumber = (Random().nextInt(899999) + 100000).toString();
final file = File(join(documentDirectory.path, '$randomNumber.jpg'));
file.writeAsBytesSync(response.bodyBytes);
return file;
}
}
DEBUG CONSOLE: D/EGL_emulation( 1990): app_time_stats: avg=88.81ms min=2.92ms max=3563.28ms count=46 I/tflite ( 1990): Replacing 16 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 1 partitions for the whole graph. [log] Model loaded: success D/EGL_emulation( 1990): app_time_stats: avg=20.34ms min=2.89ms max=760.86ms count=56 [log] /data/user/0/com.example.digital_order_system/app_flutter/391694.jpg V/time ( 1990): Inference took 29 [log] Results is: [] [log] Recognitions is: []