Tensorflow.js - TypeError: e.forEach is not a function
Tensorflow.js - TypeError: e.forEach is not a function
我是 tensorflow.js 的新手,我之前使用过 Python 版本,现在我正在将我之前训练的模型转换为网络。
我关注了这个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);
行
引起的
您忘记为 TEST_VALUE
输入任何值
const MODEL_URL = "../model/model.json"
async function run() {
// Load the model from the CDN.
const model = await tf.loadLayersModel(MODEL_URL);
const TEST_VALUE = 950.0
// 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();
我是 tensorflow.js 的新手,我之前使用过 Python 版本,现在我正在将我之前训练的模型转换为网络。
我关注了这个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);
行
您忘记为 TEST_VALUE
const MODEL_URL = "../model/model.json"
async function run() {
// Load the model from the CDN.
const model = await tf.loadLayersModel(MODEL_URL);
const TEST_VALUE = 950.0
// 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();