【发布时间】:2021-05-05 01:20:05
【问题描述】:
我是 tensorflow.js 的新手,我之前使用过 Python 版本,现在我正在将我之前训练的模型转换为 web。
我关注了这个codelabs tutorial。
代码很简单,我有index.html:
<!DOCTYPE html>
<html>
<head>
<title>Testing the JS Model</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.6.0/dist/tf.min.js"></script>
<script src="scripttest.js"></script>
</head>
<body>
</body>
</html>
在 scripttest.js 我有:
const MODEL_URL = "../model/model.json"
async function run() {
// Load the model from the CDN.
const model = await tf.loadLayersModel(MODEL_URL, strict=false);
// Print out the architecture of the loaded model.
// This is useful to see that it matches what we built in Python.
console.log(model.summary());
// Create a 1 dimensional tensor with our test value.
const input = tf.tensor1d([TEST_VALUE]);
// Actually make the prediction.
const result = model.predict(input);
}
run();
但是当我运行它时,我得到了这个错误:
Uncaught (in promise) TypeError: e.forEach is not a function
at bg (util_base.js:681)
at Mw (tensor_ops_util.js:44)
at Lw (tensor.js:56)
at Ww (io_utils.js:225)
at RM (models.js:334)
at models.js:316
at c (runtime.js:63)
at Generator._invoke (runtime.js:293)
at Generator.next (runtime.js:118)
at bv (runtime.js:747)
如果您想看它自己运行,我已将其放入我的website。
你能告诉我这里有什么问题吗?是我转换后的模型有问题还是可能是一些错误?
由于它在console.log(model.summary()) 中没有输出任何内容,我怀疑它是由await tf.loadLayersModel(MODEL_URL, strict=false); 行引起的
【问题讨论】:
标签: javascript tensorflow tensorflow.js