Dense 实现了这个操作:output = activation(dot(input, kernel) + bias)activation 是作为激活参数传递的元素激活函数,kernel 是层创建的权重矩阵,bias 是层创建的偏置向量(仅在 use_bias 为 True 时适用)。
注意:如果层的输入具有大于 2 的秩,则它在与内核的初始点积之前被展平。
例子:
# as first layer in a sequential model:
model = Sequential()
model.add(Dense(32, input_shape=(16,)))
# now the model will take as input arrays of shape (*, 16)
# and output arrays of shape (*, 32)
# after the first layer, you don't need to specify
# the size of the input anymore:
model.add(Dense(32))
论据:
> units: Positive integer, dimensionality of the output space.
> activation: Activation function to use. If you don't specify anything,
> no activation is applied (ie. "linear" activation: a(x) = x).
> use_bias: Boolean, whether the layer uses a bias vector.
> kernel_initializer: Initializer for the kernel weights matrix.
> bias_initializer: Initializer for the bias vector.
>kernel_regularizer:Regularizer function applied to the kernel weights matrix.
> bias_regularizer: Regularizer function applied to the bias vector.
> activity_regularizer: Regularizer function applied to the output of the layer (its "activation")..
>kernel_constraint: Constraint function applied to the kernel weights matrix.
>bias_constraint: Constraint function applied to the bias vector.
输入形状:
具有形状的 ND 张量:(batch_size, ..., input_dim)。最常见的情况是具有形状 (batch_size, input_dim) 的 2D 输入。
输出形状:
具有形状的 ND 张量:(batch_size, ..., units)。例如,对于形状为 (batch_size, input_dim) 的 2D 输入,输出将具有形状 (batch_size, units)。