未知层:遮罩

时间:2020-02-25 15:22:47

标签: tensorflow tensorflow.js

使用tensorflow.js,尝试导入已从.h5移至JSON的模型。

这是我得到的错误。

    Uncaught (in promise) Error: Unknown layer: Masking. 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 new e (errors.ts:48)
    at Rp (generic_utils.ts:242)
    at cd (serialization.ts:31)
    at e.fromConfig (models.ts:942)
    at Rp (generic_utils.ts:277)
    at cd (serialization.ts:31)
    at models.ts:300
    at common.ts:14
    at Object.next (common.ts:14)
    at a (common.ts:14)

这是我的代码:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js">import * as tf from '@tensorflow/tfjs';</script>
<script type='text/javascript'>
    let data = {{ data| tojson | safe}};
    console.log(data);

    if (data.ops != []) {
        //docs say tf.loadLayersModel is an async function, console says it is not...
        //I believe the docs are written for Node.js, some pages specify a difference, others do not.
        const model = tf.loadLayersModel('{{url_for("static", filename = "js/model.json/model.json")}}');
        console.log(model);
    }
</script>

这是一个Jinja2模板,因此{{}}看起来很怪异,基本上是运行了一点点python代码并返回了相应的值。 {{url_for()}}返回我存储JSON的URL,看起来还可以。

1 个答案:

答案 0 :(得分:0)

任何有相同问题的人都在使用1.0.0版的tensorflowjs。

将导入更改为此有效:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>