Save! I'm trying to implement the TensorFlow library in my React Native application, based on ese e in this tutorials.
But I can not even run the project, getting the following error:
Unable to resolve module
../assets/graph.pb
fromC:\aplicativos\myApp\components\Index.js
: The module../assets/graph.pb
could not be found.
The error only occurs because of file extension ( .pb
), because testing with image files in the same directory all happens well.
I then tried the approach made by this StackOverflow response ,
also with no result and the error persists.
Finally, I tried to read the file .pb
with the react-native-fs , resulting in a memory allocation error, since the file in question weighs more than 80Mb.
My code looks like this:
import { TfImageRecognition, TensorFlow } from 'react-native-tensorflow';
clickHandle = () => {
const graph = require('../assets/graph.pb'); //gera erro
const text = require('../assets/a.txt'); //gera erro
try {
const tfImageRecognition = new TfImageRecognition({
model: graph,
labels: text
});
const results = await tfImageRecognition.recognize({
image: this.image
});
const resultText = 'Name: ${results[0].name} - Confidence: ${results[0].confidence}';
this.setState({texto: resultText});
await tfImageRecognition.close();
} catch(err) {
alert(err);
}
}
Folder structure:
root
|--assets
| |_ a.txt
| |_ graph.pb
|
|--components
| |_ Index.js
EDIT:
I made a copy of the files to the android/app/src/main/assets
folder and modified the code as follows:
clickHandle = async () => {
const text = {uri: 'asset:/a.txt'};
const graph = {uri: 'asset:/graph.pb'};
try {
const tfImageRecognition = new TfImageRecognition({
model: graph,
labels: text
});
const results = await tfImageRecognition.recognize({
image: require('../assets/YodaWhiteHouse.jpg')
});
const resultText = 'Name: ${results[0].name} - Confidence: ${results[0].confidence}';
this.setState({texto: resultText});
await tfImageRecognition.close();
} catch(err) {
alert(err);
}
Resulting in error: