我在我的Expo项目中尝试使用tensorflow.js
库构建一个简单的机器学习模型。当我在代码沙箱中运行相同的代码时没有报错,但在Visual Studio Code中运行时出现了info、history和日志未定义的错误。我的代码附在下面:
错误信息是:
无法找到变量info
回答:
可以将info添加到应用程序的状态中
.then(info => { this.state = {...this.state, info} console.log("Final accuracy", info.history.acc); });
通过条件渲染,在模型完成训练后显示info
render() { const {info} = this.state; return ( <View style={styles.buttonContainer}> {info && <Text>{'Final accuracy', info.history.acc}</Text>} </View> ) }