无法加载@tensorflow模型/语音命令



我正试图在我的react原生应用程序中加载tensorflow.js模型语音命令。但是在尝试了很多之后,我无法加载该模型。我收到这个错误

Error: Unable to resolve module `fs` from `node_modules@tensorflow-modelsspeech-commandsdistbrowser_fft_utils.js`: fs could not be found within the project.

我尝试在主react原生应用程序中添加"fs"模块,但出现了此错误-:

Error: While trying to resolve module `fs` from file `...node_modules@tensorflow-modelsspeech-commandsdistbrowser_fft_utils.js`, the package `...node_modulesfspackage.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (...node_modulesfsindex.js`.

我的包.json依赖

"dependencies": {
"@react-native-community/async-storage": "^1.12.0",
"@tensorflow-models/speech-commands": "^0.4.2",
"@tensorflow/tfjs": "^2.3.0",
"@tensorflow/tfjs-react-native": "^0.3.0",
"expo-camera": "^8.3.1",
"expo-gl": "^8.4.0",
"expo-gl-cpp": "^8.4.0",
"fs": "0.0.1-security",
"jpeg-js": "^0.4.2",
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-fs": "^2.16.6",
"react-native-unimodules": "^0.10.1",
"util": "^0.12.3"
},

我的app.js

import React from 'react'
import {Text} from'react-naitve'
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-react-native';
import * as speechCommands from '@tensorflow-models/speech-commands';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isTfReady: false,
isModelReady: false
};
}
async componentDidMount() {
// Wait for tf to be ready.
await tf.ready();
// Signal to the app that tensorflow.js can now be used.
this.setState({
isTfReady: true,
});
this.model = await speechCommands.load()
this.setState({ isModelReady: true })
}
render() {
return(
<Text>
{this.state.isTfReady?<Text>ready</Text>:<Text>no loading///...</Text>}
Model ready?{' '}
{this.state.isModelReady ? <Text>Yes</Text> : <Text>Loading Model...</Text>}
</Text>
)
}
}

我试图找出我为什么会出现这个错误,在GITHUB上发现了类似的问题,但无法解决该问题。

谁能告诉我怎样才能摆脱这个错误吗?谢谢

我的解决方法是在package.json中的node_modules/@tensorflow models/speech命令下添加以下内容

"浏览器":{"fs〃:false,"节点获取":false,"字符串解码器":false,"crypto":虚假的},

理想情况下https://github.com/tensorflow/tfjs/issues/1274应该应用。

最新更新