tfjs
tfjs copied to clipboard
React Native Tensorflow with own models not working
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: iPhone 7
- TensorFlow.js installed from (npm or script link): 4.19.0
- React Native Version: latest
i'm trying to use my onw model, but when I try to run the app i'm getting this error: TypeError: undefined is not an object (evaluating 'globalThis.expo.NativeModule') and Error loading model: [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "expo-asset").Asset')] i'm using React Native CLI not expo
this is my code:
const loadModel = async () => {
try {
await tf.ready();
console.log("Tensorflow is ready");
const modelJson = require("./assets/model.json");
const modelWeights = require("./assets/group1-shard1of4.bin");
const modelWeights1 = require("./assets/group1-shard2of4.bin");
const modelWeights2 = require("./assets/group1-shard3of4.bin");
const modelWeights3 = require("./assets/group1-shard4of4.bin");
const model = await tf.loadGraphModel(bundleResourceIO(modelJson, [modelWeights, modelWeights1, modelWeights2, modelWeights3]));
console.log('Model loaded successfully:', model);
} catch (error) {
console.error('Error loading model:', error);
}
};
loadModel();
This is my metro.config.js:
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const config = {
resolver: {
// Modify assetExts to include 'bin'
assetExts: ['bin', ...getDefaultConfig(__dirname).resolver.assetExts],
}
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
Hi, @piroposantosdev
I apologize for the delayed response and thank you for bringing this issue to our attention, if possible could you please help us with your Github repo or codepen example along with converted TensorFlow.js models and complete steps to replicate the same behavior from our end to investigate this issue further from our end ?
Thank you from your cooperation and patience.
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.
Hey there, sorry my delay. Maybe i was not clear enough. What i was talking about is that the react native package is not working properly when using a downloaded/generated model. Even trying with yours it's not working, it's always saying TypeError: undefined is not an object (evaluating 'globalThis.expo.NativeModule') and Error loading model: [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "expo-asset").Asset')] i'm using React Native CLI not expo.
I'm using RN newest version, not expo, and when i try a simple code using camera api and tensorflow api and trynna read a local bin files this error occurs
same issue