• Register a class with the serialization map of TensorFlow.js.

    This is often used for registering custom Layers, so they can be serialized and deserialized.

    Example 1. Register the class without package name and specified name.

    class MyCustomLayer extends tf.layers.Layer {
    static className = 'MyCustomLayer';

    constructor(config) {
    super(config);
    }
    }
    tf.serialization.registerClass(MyCustomLayer);
    console.log(tf.serialization.GLOBALCUSTOMOBJECT.get("Custom>MyCustomLayer"));
    console.log(tf.serialization.GLOBALCUSTOMNAMES.get(MyCustomLayer));

    Example 2. Register the class with package name: "Package" and specified name: "MyLayer".

    class MyCustomLayer extends tf.layers.Layer {
    static className = 'MyCustomLayer';

    constructor(config) {
    super(config);
    }
    }
    tf.serialization.registerClass(MyCustomLayer, "Package", "MyLayer");
    console.log(tf.serialization.GLOBALCUSTOMOBJECT.get("Package>MyLayer"));
    console.log(tf.serialization.GLOBALCUSTOMNAMES.get(MyCustomLayer));

    Example 3. Register the class with specified name: "MyLayer".

    class MyCustomLayer extends tf.layers.Layer {
    static className = 'MyCustomLayer';

    constructor(config) {
    super(config);
    }
    }
    tf.serialization.registerClass(MyCustomLayer, undefined, "MyLayer");
    console.log(tf.serialization.GLOBALCUSTOMOBJECT.get("Custom>MyLayer"));
    console.log(tf.serialization.GLOBALCUSTOMNAMES.get(MyCustomLayer));

    Example 4. Register the class with specified package name: "Package".

    class MyCustomLayer extends tf.layers.Layer {
    static className = 'MyCustomLayer';

    constructor(config) {
    super(config);
    }
    }
    tf.serialization.registerClass(MyCustomLayer, "Package");
    console.log(tf.serialization.GLOBALCUSTOMOBJECT
    .get("Package>MyCustomLayer"));
    console.log(tf.serialization.GLOBALCUSTOMNAMES
    .get(MyCustomLayer));

    Type Parameters

    Parameters

    • cls: SerializableConstructor<T>

      The class to be registered. It must have a public static member called className defined and the value must be a non-empty string.

    • Optional pkg: string

      The pakcage name that this class belongs to. This used to define the key in GlobalCustomObject. If not defined, it defaults to Custom.

    • Optional name: string

      The name that user specified. It defaults to the actual name of the class as specified by its static className property.

    Returns SerializableConstructor<T>

    Doc

Generated using TypeDoc