tensorflow保存模型时出现AttributeError: ‘NoneType‘ object has no attribute ‘replace‘ 错误

  • Post author:
  • Post category:其他


需要注意自定义层和自定义权重的命名,如果未命名保存权重时无法记录:

class convres(keras.layers.Layer):
    def __init__(self, units, name='convres'):
        super(convres, self).__init__()
        self.units = units
    
    def build(self, input_shape):
        self.convs = []
        for _ in range(self.units):
            self.convs.append(self.add_weight(shape=(1, self.units), initializer = 'glorot_uniform', name='w'))
        
        super().build(input_shape)
    
    def call(self, inputs):

分别添加 name=”即可成功保存



版权声明:本文为qq_34461205原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。