【问题标题】:Failure to load model in tensorflow.js无法在 tensorflow.js 中加载模型
【发布时间】:2021-06-10 16:11:12
【问题描述】:

我已经将不同的迁移训练模型(VGG16、InceptionV3、EfficientNetB0)从 python 中的 tensorflow 转换为 tensorflowjs。 并且实现到tensorflowjs后,加载模型失败。

其中一个错误是:

Uncaught Error: Unknown layer: Functional. This may be due to one of the following reasons:
1. The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at jN (generic_utils.js:242)
    at GI (serialization.js:31)
    at e.fromConfig (models.js:1026)
    at jN (generic_utils.js:277)
    at GI (serialization.js:31)
    at models.js:295
    at u (runtime.js:45)
    at Generator._invoke (runtime.js:274)
    at Generator.forEach.t.<computed> [as next] (runtime.js:97)
    at Wm (runtime.js:728)

还有

jquery-3.3.1.slim.min.js:2 Uncaught Error: Unknown layer: RandomFlip. This may be due to one of the following reasons:
1. The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at jN (generic_utils.js:242)
    at GI (serialization.js:31)
    at e.fromConfig (models.js:1026)
    at jN (generic_utils.js:277)
    at GI (serialization.js:31)
    at e.fromConfig (models.js:1026)
    at jN (generic_utils.js:277)
    at GI (serialization.js:31)
    at models.js:295
    at u (runtime.js:45)

还有,

Failed to load resource: the server responded with a status of 404 ()

有什么问题? 如果我使用从可教机器生成的 .json 文件,则可以加载模型。 (然而,由于未知原因,预测变得完全错误,问题似乎不仅仅是标签问题。) 但是如果我使用 .h5 或 SavedModel 通过 tensorflow 转换器生成的 model.json 文件,无论我使用哪种预训练模型,或者生成的文件格式(.h5 或 SavedModel),都无法将模型加载到 javascript 中。

请帮忙!!

【问题讨论】:

    标签: tensorflow tensorflow.js


    【解决方案1】:

    转到model.json 文件并搜索关键字Functional(您可以使用ctrl+f Functional)并将该单词替换为Model。

    【讨论】:

    • 未知层怎么样:RandomFlip?这似乎是由于 tensorflow.js 无法识别增强层。我按照 tensorflow 官网的教程,将数据增强层作为模型层之一。我应该如何处理这个问题?
    • @Maximus 您将不得不为此提出另一个问题。我也会尝试回答。您能否接受并支持我的问题,因为它解决了您的问题?
    • 谢谢!接受并赞成您的问题。我在以下链接中问了另一个问题:stackoverflow.com/questions/66616597/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2019-06-06
    相关资源
    最近更新 更多