根据custom layers TensorFlow Keras 指南部分有一个可选的 get_config
方法实现:
def get_config(self):
base_config = super(MyLayer, self).get_config()
base_config['output_dim'] = self.output_dim
使用一些虚拟数据运行完整代码,然后查看在 model.fit(...
之后调用 model.get_config()
生成的配置,结果如下输出:
[{'class_name': 'MyLayer', 'config': None},
{'class_name': 'Activation',
'config': {'name': 'activation_38',
'trainable': True,
'dtype': 'float32',
'activation': 'softmax'}}]
我的问题是:作为 get_config
方法中最终分配的结果,自定义图层“MyLayer”的配置是否应该不包含 output_dim
字段?非常感谢。
最佳答案
没有 return
语句的 get
方法?
这就是无
的原因。
def get_config(self):
base_config = super(MyLayer, self).get_config()
base_config['output_dim'] = self.output_dim
return base_config
关于python - TensorFlow Keras 指南 : custom layer get_config method not updating the layer's configuration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51562286/