【发布时间】:2018-10-29 22:43:43
【问题描述】:
我想制作一个用户界面来创建、保存和训练 tensorflow.js 模型。但是创建模型后我无法保存模型。我什至从 tensorflow.js 文档中复制了这段代码,但它不起作用:
const model = tf.sequential(
{layers: [tf.layers.dense({units: 1, inputShape: [3]})]});
console.log('Prediction from original model:');
model.predict(tf.ones([1, 3])).print();
const saveResults = await model.save('localstorage://my-model-1');
const loadedModel = await tf.loadModel('localstorage://my-model-1');
console.log('Prediction from loaded model:');
loadedModel.predict(tf.ones([1, 3])).print();
我总是收到错误消息“Uncaught SyntaxError: await is only valid in async function”。我该如何解决这个问题?谢谢!
【问题讨论】:
-
如果你在这里运行自己的代码 sn-p 你可以看到@Sebastian Speitel 的回答
标签: javascript tensorflow tensorflow.js