Comments (5)
Adding some more details, I am working on react native app.
I would like to load the model from local storage, I see that bundleResourceIO only works for assets that are bundled when compiling the application, and tensorflow js react native also has an alternative to use asyncStorageIO.
Is it possible to load the model from local storage without getting into AsyncStorage? How could I use AsyncStorage to copy both files weights.bin and model.json from local storage/document directory to AsyncStorage in order to use asyncStorageIO. Can you throw some insights on this problem ?
from tfjs.
Hi, @skadambala
I apologize for the delayed response and could you please give it try with below workaround and see is it working as expected or not ?
import React from 'react';
import {Button, View} from 'react-native';
import * as tf from '@tensorflow/tfjs';
import {bundleResourceIO} from '@tensorflow/tfjs-react-native';
import RNFS from 'react-native-fs';
const modelJson1 = await RNFS.readFile(
`${RNFS.DocumentDirectoryPath}/model/model.json`,
);
const modelLoad = await tf.loadGraphModel(modelJson, {
weightUrlConverter : async (weightFileName) => {
return `file://${RNFS.DocumentDirectoryPath}/model/group1-shard1of1.bin`;
}});
If you're looking to use asyncStorageIO then you'll have do something like below :
- Import required Libraries ( if it is not installed please install all the required libraries using NPM or yarn
import * as tf from '@tensorflow/tfjs';
import AsyncStorage from '@react-native-async-storage/async-storage';
import RNFS from 'react-native-fs'; // Assuming you have react-native-fs installed
- Define AsyncStorage Keys:
const MODEL_JSON_KEY = 'modelJson';
const MODEL_WEIGHTS_KEY = 'modelWeights';
async function loadModel() {
try {
// Check for model in AsyncStorage
const modelJsonString = await AsyncStorage.getItem(MODEL_JSON_KEY);
const modelWeightsBytes = await AsyncStorage.getItem(MODEL_WEIGHTS_KEY);
if (modelJsonString && modelWeightsBytes) {
// Model found in AsyncStorage, load directly
const modelJson = JSON.parse(modelJsonString);
const modelWeights = tf.util.decodeBase64(modelWeightsBytes);
return await tf.loadLayersModel({ modelConfig: modelJson, weights: modelWeights }, asyncStorageIO);
} else {
console.error('Model not found in AsyncStorage!!!');
}
} catch (error) {
console.error('Error loading model:', error);
return null; // Or handle error appropriately
}
}
To further investigate this issue, I'd appreciate it if you could try the workaround described above and confirm if it resolves the problem. If the issue persists, could you please share your GitHub repository? This would allow us to replicate the behavior and conduct a more thorough investigation.
Thank you for your cooperation and patience.
from tfjs.
This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.
from tfjs.
This issue was closed due to lack of activity after being marked stale for past 7 days.
from tfjs.
Are you satisfied with the resolution of your issue?
Yes
No
from tfjs.
Related Issues (20)
- Error: Kernel 'Draw' not registered for backend 'custom-webgl2' at Engine.runKernel at Module.draw HOT 5
- Face Detection not defined HOT 4
- GPU setup guide HOT 4
- @tensorflow/tfjs-react-native can't be installed successfully expo 51 HOT 9
- T5 Text-to-Text Transformer
- React Native Tensorflow with own models not working HOT 3
- webgpu gpu-pipeline example crashes tab HOT 2
- Converting Model Saved by tfjs-react-native to Keras or Saved Model
- Error during training HOT 5
- tf.data.array() cannot consume a Tensor, despite the documentation claiming so HOT 3
- Tensorflowjs for python not working (conflicting libraries) HOT 5
- Getting started example not resilient to growing the training data beyond x=25 HOT 5
- BlazePose doesn't work in Firefox for Android HOT 2
- Problem Converting tensorflow garden model in format of Tensorflow Saved Model to a Web Model with tensorflowjs HOT 4
- Node js doenst recognize the module with node version 20.14 HOT 5
- memory leak (core dumped) problem in tfjs-node HOT 3
- WebGPU Compute shader execution?
- Accuracy issue HOT 1
- TypeError: Cannot read property 'NativeModule' of undefined, js engine: hermes HOT 2
- DQN not learning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tfjs.