在TensorFlow Keras指南的custom layers部分下,有get_config
方法的可选实现:
def get_config(self):
base_config = super(MyLayer, self).get_config()
base_config['output_dim'] = self.output_dim
使用一些伪数据运行完整代码,然后查看在model.get_config()
之后调用model.fit(...
产生的配置,将产生以下输出:
[{'class_name': 'MyLayer', 'config': None},
{'class_name': 'Activation',
'config': {'name': 'activation_38',
'trainable': True,
'dtype': 'float32',
'activation': 'softmax'}}]
我的问题是:由于output_dim
方法中的最终赋值,自定义层“ MyLayer”的配置是否不包含get_config
字段?非常感谢。
答案 0 :(得分:0)
没有get
语句的return
方法吗?
这就是None
的原因。
def get_config(self):
base_config = super(MyLayer, self).get_config()
base_config['output_dim'] = self.output_dim
return base_config