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

Javascript 无法加载@tensorflow模型/语音命令,javascript,react-native,tensorflow,tensorflow.js,Javascript,React Native,Tensorflow,Tensorflow.js,我正在尝试在我的react本机应用程序中加载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本机应用程序中

我正在尝试在我的react本机应用程序中加载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本机应用程序中添加“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`.
My 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>
    )
  }
}
从“React”导入React
从'react-naitve'导入{Text}
从“@tensorflow/tfjs”导入*作为tf;
导入“@tensorflow/tfjs react native”;
从“@tensorflow models/speechCommands”导入*作为speechCommands;
导出默认类App扩展React.Component{
建造师(道具){
超级(道具);
此.state={
伊斯特弗雷迪:错,
isModelReady:错误
};
}
异步组件didmount(){
//等待tf准备好。
等待tf.ready();
//向应用程序发出tensorflow.js现在可以使用的信号。
这是我的国家({
伊斯特弗雷迪:是的,
});
this.model=await speechCommands.load()
this.setState({isModelReady:true})
}
render(){
返回(
{this.state.istfrady?就绪:无加载//…}
模型就绪?{'}
{this.state.isModelReady?是:正在加载模型…}
)
}
}
我试图找出我为什么会犯这个错误, 在上发现类似问题,但无法解决该问题


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

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

“浏览器”:{ “fs”:错误, “节点获取”:false, “字符串解码器”:false, “加密”:错误 },

理想情况下,应采用相同的溶液