question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tf.loadModel not working in ionic

See original GitHub issue

TensorFlow.js version

0.10.0

Browser version

cli packages: (C:\Users\Administrator\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 25.2.5
Node              : v8.9.1
npm               : 5.6.0
OS                : Windows 10

Describe the problem or feature request

tf.loadModel not working, it fails to load model from local folder ( ie. assets/model ) however, web version is working, when it runs on http://localhost:8100/ionic-lab

Code to reproduce the bug / link to feature request

import {Component} from '@angular/core';
import {IonicPage, AlertController} from 'ionic-angular';
import * as tf from "@tensorflow/tfjs";

@IonicPage()
@Component({
  selector: 'page-tfpretrainedversion',
  templateUrl: 'tfpretrainedversion.html',
})
export class TfpretrainedversionPage {

  kerasTraindedModel: tf.Model;
  KERAS_MODEL_JSON = 'assets/model/model.json';

  constructor(private httpClient: HttpClient,
              private alertCtrl: AlertController,
              private loadingService: LoadingServiceProvider) {
    this.loadPretrainedModel();
  }

  loadPretrainedModel() {

    tf.loadModel(this.KERAS_MODEL_JSON)
      .then((result) => {
        this.kerasTraindedModel = result;
      })
      .catch((error)=>{
        let prompt = this.alertCtrl.create({
          title: 'Error',
          subTitle: error,
          buttons: ['OK']
        });
        prompt.present();
      });
  }
}

here is a error message screenshot_2018-05-08-05-43-54

and here is a data structure pretrainedmodel

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
b-lackcommented, Mar 22, 2019

TensorflowJs loads the models via fetch(). fetch() does not support loading local-files. https://fetch.spec.whatwg.org/

To make this happen, I used this workaround in a Cordova-Projekt:

Import a polyfill (https://github.com/github/fetch) and replace the global-fetch.

window.fetch = fetchPolyfill;

Now, it’s possible to load local files (file:///) like:

const modelUrl = './model.json'

const model = await tf.loadGraphModel(modelUrl);
1reaction
lxieyangcommented, Jun 5, 2019

Any follow up on this issue? @gabrielglbh Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

hybrid mobile app - Tensorflowjs in ionic - Stack Overflow
However, when i build the project for android tf.loadModel method not working, it fails to load model from local folder ( ie. assets/model...
Read more >
Tf.Loadmodel Is Not A Function - ADocLib
Describe the problem or feature request. tf.loadModel not working it fails to load model from AlertController} from 'ionicangular'; import as tf from ...
Read more >
@tensorflow/tfjs - npm
TensorFlow.js Data, a simple API to load and prepare data analogous to tf.data. TensorFlow.js Converter, tools to import a TensorFlow SavedModel ...
Read more >
tf.keras.models.load_model | TensorFlow v2.11.0
LoadOptions object that specifies options for loading from SavedModel. Returns. A Keras model instance. If the original ...
Read more >
[Resolved]-I need my Ionic app to get a specific xlsx file to run
But now I want to use real data I got, but get stuck on two major problems: first of all, the file that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found