Code Monkey home page Code Monkey logo

Comments (5)

gaikwadrahul8 avatar gaikwadrahul8 commented on June 15, 2024

Hi, @Infiniteskys

Thank you for bringing this issue to our attention and please give it try with below code snippet and see is it working as expected or not ? Please refer official documentation of asyncStorageIO to save and load the model to/from async storage

import * as tf from "@tensorflow/tfjs";
import { asyncStorageIO } from "@tensorflow/tfjs-react-native";

export const loadModel = async () => {
  try {
    await tf.ready();
    const model = await tf.loadGraphModel("https://test_model/model.json");
    console.log("Model loaded.");
    model.summary();

    // Save the model to AsyncStorage
    const savedModel = await model.save(asyncStorageIO('customs'));
    console.log("Model saved to AsyncStorage");

    // Load the model from AsyncStorage
    const loadedModel = await tf.loadLayersModel(asyncStorageIO('customs'));
    console.log(loadedModel == model); // This might not be true due to model serialization

    return loadedModel;

  } catch (e) {
    console.error("Error:", e);
    return null;
  }
};

If issue still persists please let us know and if possible please help us with your Github repo along with model and complete steps to run code to replicate the same behaviour from our end.

Thank you for your cooperation and patience.

from tfjs.

Infiniteskys avatar Infiniteskys commented on June 15, 2024

Hi @gaikwadrahul8 ,
I had tried it but it still not working and show the error that layer improper config format.
I believe the json file we convert is a graph model, I had tried to use Loadgraphmodel function, but I can only load from the Website URL but not the asynstrongIO.

from tfjs.

Infiniteskys avatar Infiniteskys commented on June 15, 2024

If I have the function as below, it will show the error: Based on the provided shape, [4.2],the tensor should have 8 values but has 1.

import * as tf from "@tensorflow/tfjs";
import { asyncStorageIO } from "@tensorflow/tfjs-react-native";

export const loadModel = async () => {
try {
await tf.ready();
const model = await tf.loadGraphModel("https://test_model/model.json");
console.log("Model loaded.");

// Save the model to AsyncStorage
const savedModel = await model.save(asyncStorageIO('customs'));
console.log("Model saved to AsyncStorage");

// Load the model from AsyncStorage
const loadedModel = await tf.loadGraphModel(asyncStorageIO('customs'));

return loadedModel;

} catch (e) {
console.error("Error:", e);
return null;
}
};

from tfjs.

gaikwadrahul8 avatar gaikwadrahul8 commented on June 15, 2024

Hi, @Infiniteskys

If possible could you please help us with your model file in zip format along with complete steps to replicate the same behavior from our end to investigate this issue further ?

Thank you for your cooperation and patience.

from tfjs.

Infiniteskys avatar Infiniteskys commented on June 15, 2024

Hi @gaikwadrahul8 ,
Here is the test model other friend train at the service side and convert it at the service.
test_model.zip

I had also test to use the location directly.

const loadedModel = await tf.loadLayersModel('/moblientclient/assest/model/test_model/model.json');

But it will show error the network request fail. But in this case, I dont have any idea how to save the model if there is a update version at the service.

Thank you.

from tfjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.