pass
来源:3-6 使子类与lambda分别实战自定义层次
战战的坚果
2020-04-27
pass
写回答
1回答
-
正十七
2020-04-28
对啊,默认是None,如果你设置了就不是None了啊,你可以设置成relu或者其他的。
# customized dense layer. class CustomizedDenseLayer(keras.layers.Layer): def __init__(self, units, activation=None, **kwargs): self.units = units self.activation = keras.layers.Activation(activation) super(CustomizedDenseLayer, self).__init__(**kwargs) def build(self, input_shape): """构建所需要的参数""" # x * w + b. input_shape:[None, a] w:[a,b]output_shape: [None, b] self.kernel = self.add_weight(name = 'kernel', shape = (input_shape[1], self.units), initializer = 'uniform', trainable = True) self.bias = self.add_weight(name = 'bias', shape = (self.units, ), initializer = 'zeros', trainable = True) super(CustomizedDenseLayer, self).build(input_shape) def call(self, x): """完成正向计算""" return self.activation(x @ self.kernel + self.bias)
在构造函数中被赋值,在call函数中被使用啊。
00