"未知层:Lambda"在浏览器上的tensorflowjs中

时间:2018-06-15 15:43:52

标签: python tensorflow.js

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

this attention_ocr与用python编写的OCR有关。我已生成HDF5 / H5文件,并使用tensorflowjs_converter [ref]以特定于网络的格式进行了转换。

我按照this文档中的所有说明进行操作,但在浏览器中运行时,它会引发错误(参见屏幕截图)

enter image description here

  

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

参与:

tensorflow.org

How to import a TensorFlow SavedModel into TensorFlow.js

Importing a Keras model into TensorFlow.js

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

您必须创建一个自定义图层类,如上面所述的@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