flutter_tflite icon indicating copy to clipboard operation
flutter_tflite copied to clipboard

any way that I can download tflite model from web to use ?

Open kotran88 opened this issue 3 years ago • 2 comments

I tried to use download with below plugin. https://github.com/edjostenes/download_assets

with above plugin, asset folder looks /data/user/0/com.onofflab.traffic/app_flutter/assets.

I checked that file is downloaded well,

bool? filedownloaded = await dc?.assetsFileExists("quantized.tflite");
print("render... ddownload asset comeeeeee"+filedownloaded.toString());

file downloaded is true.

but with loading model,


case ModelType.SSDMobileNet:
          print("render... come!!!!");
          try {
             res = await Tflite.loadModel(
              model: '${dc?.assetsDir}/quantized.tflite',
              labels: 'assets/models/newmobnet.txt'); 
          } catch ( e) {
            print("render... error:"+e.toString());
          }
        
          print("render... load done final"+res.toString());
          break;

it cause file not found error. I look into log and found out that model path is flutter_assets/data/user/0/com.onofflab.traffic/app_flutter/assets/models/quantized.tflite so, flutter_assets is prefix.... that is why it cause file not found error.

any example that I can download model from web to use ?

kotran88 avatar Jan 02 '22 18:01 kotran88

I don't how to do it but if need to acess the external storage of the device you can use:

import 'dart:io';
import 'package:path_provider/path_provider.dart';

 Directory directory = await getApplicationDocumentsDirectory();

path_provider: ^2.0.6

I tried to use download with below plugin. https://github.com/edjostenes/download_assets

with above plugin, asset folder looks /data/user/0/com.onofflab.traffic/app_flutter/assets.

I checked that file is downloaded well,

bool? filedownloaded = await dc?.assetsFileExists("quantized.tflite");
print("render... ddownload asset comeeeeee"+filedownloaded.toString());

file downloaded is true.

but with loading model,


case ModelType.SSDMobileNet:
          print("render... come!!!!");
          try {
             res = await Tflite.loadModel(
              model: '${dc?.assetsDir}/quantized.tflite',
              labels: 'assets/models/newmobnet.txt'); 
          } catch ( e) {
            print("render... error:"+e.toString());
          }
        
          print("render... load done final"+res.toString());
          break;

it cause file not found error. I look into log and found out that model path is flutter_assets/data/user/0/com.onofflab.traffic/app_flutter/assets/models/quantized.tflite so, flutter_assets is prefix.... that is why it cause file not found error.

any example that I can download model from web to use ?

How do you solve this pr ?

chaoyifei avatar Apr 15 '24 12:04 chaoyifei