注意 kwargs 和 custom_object_scope 的使用,以及 Dense 应该在 __init__ 中创建。
# define class CustomLayer(tf.keras.layers.Layer): def __init__(self, **kwargs): super(CustomLayer, self).__init__() Dense = tf.keras.layers.Dense self.dense1 = Dense(64) def call(self, x): x = self.dense1(x) return x # for from_config with tf.keras.utils.custom_object_scope({'CustomLayer': CustomLayer}): model = tf.keras.Model.from_config(model_config)
墨之科技,版权所有 © Copyright 2017-2027
湘ICP备14012786号 邮箱:ai@inksci.com