Skip to content

Layer Time2Vec has arguments ['self', 'kernel_size', 'periodic_activation'] in __init__ and therefore must override get_config(). #2

@davidwincent

Description

@davidwincent

Config in Time2Vec layer is not serializable.

Test code:

model = time2vec_lstm(SEQ_LEN, 16)

model.compile(
    loss=tf.keras.losses.mean_squared_error,
    optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3)
)

# Retrieve the config
config = model.get_config()

Gives the following error:

NotImplementedError: 
Layer Time2Vec has arguments ['self', 'kernel_size', 'periodic_activation']
in `__init__` and therefore must override `get_config()`.

Example:

class CustomLayer(keras.layers.Layer):
    def __init__(self, arg1, arg2):
        super().__init__()
        self.arg1 = arg1
        self.arg2 = arg2

    def get_config(self):
        config = super().get_config()
        config.update({
            "arg1": self.arg1,
            "arg2": self.arg2,
        })
        return config

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions