我遵循了 this tutorial 中的步骤转换使用 Python
生成的经过训练的 TensorFlow
模型。现在我想用它在 TensorFlow JS
中重新创建模型。我像这样传递了 model.js
的路径:
const model = tf.loadLayersModel(pathToModelsDotJSON).then(() => {
// Do stuff
})
我正在使用 Vue.js
,当我运行代码时它会抛出这个错误:
Uncaught (in promise) Error: The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.
at new t (tf-layers.esm.js?271e:17)
at t.add (tf-layers.esm.js?271e:17)
at t.fromConfig (tf-layers.esm.js?271e:17)
at deserializeKerasObject (tf-layers.esm.js?271e:17)
at deserialize (tf-layers.esm.js?271e:17)
at eval (tf-layers.esm.js?271e:17)
at eval (tf-layers.esm.js?271e:17)
at Object.eval [as next] (tf-layers.esm.js?271e:17)
at o (tf-layers.esm.js?271e:17)
我的问题是:为什么会这样?以及如何解决?
最佳答案
1 - 您使用了错误的函数 modelFromJSON
来导入模型。根据教程,这里是要使用的函数:loadLayersModel
。
2-
The first layer in a Sequential model must get an
inputShape
orbatchInputShape
argument
需要在Python定义的模型中加入batchInputShape或InputShape
关于javascript - TensorFlow JS - 加载使用 Python 生成的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57021397/