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.
Related Issues (20)
- tensorflowjs_converter on .keras file messes up weights HOT 6
- Safari webworker `Error when getting WebGL Context` HOT 4
- tfjs-node-gpu warnings (not running in GPU mode) HOT 2
- Model with softmax output layer not outputing probabilities but just 1 and 0 HOT 4
- Model Face Detection Confidence Score Output or Minimum Confidence Score Threshold
- model.executeAsync fails when loading multiple converted TF-DF models HOT 4
- TensorFlowJS fails reliably on Intel GPU running Windows, otherwise succeeds HOT 1
- Error when a module try to install tensorflow HOT 4
- I can't install @tensorflow/tfjs-node in my project HOT 5
- Finish placeholder features: einsum gradients, conv1d causal padding HOT 3
- Tfjs pose detection not working with newer Android devices (12, 13, 14) HOT 11
- npm install @tensorflow/tfjs-node error HOT 5
- Cannot import TFJS-Node HOT 5
- memory leak (core dumped) problem in tfjs-node HOT 4
- 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 5
- T5 Text-to-Text Transformer
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.