【发布时间】:2020-12-24 22:18:33
【问题描述】:
我正在尝试在我的 react-native-app 中加载 tensorflow.js 模型语音命令。 但是在尝试了很多之后,我无法加载模型。我收到此错误
Error: Unable to resolve module `fs` from `node_modules\@tensorflow-models\speech-commands\dist\browser_fft_utils.js`: fs could not be found within the project.
我尝试在主 react-native-app 中添加“fs”模块,但出现此错误-:
Error: While trying to resolve module `fs` from file `...\node_modules\@tensorflow-models\speech-commands\dist\browser_fft_utils.js`, the package `...\node_modules\fs\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (...\node_modules\fs\index.js`.
我的 package.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 上发现了类似的问题,但无法解决问题。
谁能告诉我如何摆脱这个错误?谢谢
【问题讨论】:
标签: javascript react-native tensorflow tensorflow.js