保存模型时出现NotIplementedError: Layer XX has arguments in `__init__`

NotImplementedError: 
Layer Attention_layer has arguments ['self', 'W_regularizer', 'b_regularizer', 'W_constraint', 'b_constraint', 'bias']
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

你可能感兴趣的:(python,深度学习,servlet)