javascript - TensorFlow JS - 加载使用 Python 生成的模型

标签 javascript python json tensorflow tensorflow.js

我遵循了 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 or batchInputShape argument

需要在Python定义的模型中加入batchInputShape或InputShape

关于javascript - TensorFlow JS - 加载使用 Python 生成的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57021397/

相关文章:

javascript - Angular $interval 在超过 'count' 参数后是否会自行取消?

javascript - Firebase 身份验证检测用户是否来自重定向登录

javascript - sha3输出可以用作文件名吗?

python - 使用 PyCurl 从文件对象上传文件

javascript - 未捕获的语法错误 : Unexpected token < on line 1

c# - Windows Phone 8 中的 JObject.Parse 动态类型问题

php - 如何在 silverstripe 3 模板中按日期对外部 API json 数据进行分组?

javascript - 缓存服务器页面 (CSP) 中的缓存变量作用域

python - 如何使用 numpy 将数组中的任意两个元素相加并生成矩阵?

python - 如何让 AppEngine map reduce 横向扩展?