【问题标题】:"Unknown layer: Lambda" in tensorflowjs on browser浏览器上 tensorflowjs 中的“未知层:Lambda”
【发布时间】:2018-11-25 11:52:01
【问题描述】:

我是机器学习领域的新手。我正在尝试通过在 tensorflow js 中转换经过训练的模型来在浏览器上运行 python 程序。

this attention_ocr与用python编写的OCR有关。我已经生成了 HD​​F5/H5 文件,并使用 tensorflowjs_converter[ref] 将其转换为 Web 特定格式。

我遵循this 文档中给出的所有说明,但在浏览器中运行时它会抛出错误(参考屏幕截图)

我正在寻找解决方案来消除此错误...!

参考:

tensorflow.org

How to import a TensorFlow SavedModel into TensorFlow.js

Importing a Keras model into TensorFlow.js

【问题讨论】:

  • 尝试升级到最新的 tf.js 版本 (0.11.6)。如果它仍然不起作用,则您保存的模型正在使用 Lamba 层,该层尚未在 tfjs 中实现。
  • @SebastianSpeitel ,与 tf.js 版本(0.11.6)有同样的错误......!

标签: python tensorflow.js


【解决方案1】:

TensorFlow.js 不支持 Lambda(本机代码)层。您需要将其替换为自定义图层。这很棘手。这是一个示例自定义层:https://github.com/tensorflow/tfjs-examples/tree/master/custom-layer

【讨论】:

    【解决方案2】:

    您必须创建一个自定义层类,如上述@BlessedKey (https://github.com/tensorflow/tfjs-examples/tree/master/custom-layer)。

    您还必须编辑 model.json 文件。模型定义必须更新为指向您为自定义层创建的新类,而不是 Lambda 类。在您的 model.json 中找到 lambda 层并将“class_name”:“Lambda”属性更改为“class_name”:“YourCustomLayer”。你可以在这里找到一个例子:https://github.com/tensorflow/tfjs/issues/283

    还要确保从 computeOutputShape(inputShape) 返回正确的张量形状,否则你会被这个讨厌的家伙打扰:

    TypeError: Cannot read property 'dtype' of undefined
    at executor.js:29
    at t.e.add (executor.js:96)
    at SA (executor.js:341)
    at training.js:1063
    at engine.js:425
    at t.e.scopedRun (engine.js:436)
    at t.e.tidy (engine.js:423)
    at Nb (globals.js:182)
    at s (training.js:1046)
    at training.js:1045
    

    【讨论】:

      猜你喜欢
      • 2021-01-11
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2020-12-16
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多