This layer implements the operation:
outputs = activation(inputs * kernel + bias)
where activation is the activation function passed as the activation
argument (if not None), kernel is a weights matrix created by the layer,
and bias is a bias vector created by the layer
(only if use_bias is True).
Args
inputs
Tensor input.
units
Integer or Long, dimensionality of the output space.
activation
Activation function (callable). Set it to None to maintain a
linear activation.
use_bias
Boolean, whether the layer uses a bias.
kernel_initializer
Initializer function for the weight matrix.
If None (default), weights are initialized using the default
initializer used by tf.compat.v1.get_variable.
bias_initializer
Initializer function for the bias.
kernel_regularizer
Regularizer function for the weight matrix.
bias_regularizer
Regularizer function for the bias.
activity_regularizer
Regularizer function for the output.
kernel_constraint
An optional projection function to be applied to the
kernel after being updated by an Optimizer (e.g. used to implement
norm constraints or value constraints for layer weights). The function
must take as input the unprojected variable and must return the
projected variable (which must have the same shape). Constraints are
not safe to use when doing asynchronous distributed training.
bias_constraint
An optional projection function to be applied to the
bias after being updated by an Optimizer.
trainable
Boolean, if True also add variables to the graph collection
GraphKeys.TRAINABLE_VARIABLES (see tf.Variable).
name
String, the name of the layer.
reuse
Boolean, whether to reuse the weights of a previous layer
by the same name.
Returns
Output tensor the same shape as inputs except the last dimension is of
size units.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.compat.v1.layers.dense\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.9.0/keras/legacy_tf_layers/core.py#L147-L261) |\n\nFunctional interface for the densely-connected layer. \n\n tf.compat.v1.layers.dense(\n inputs,\n units,\n activation=None,\n use_bias=True,\n kernel_initializer=None,\n bias_initializer=tf.compat.v1.zeros_initializer(),\n kernel_regularizer=None,\n bias_regularizer=None,\n activity_regularizer=None,\n kernel_constraint=None,\n bias_constraint=None,\n trainable=True,\n name=None,\n reuse=None\n )\n\n\u003cbr /\u003e\n\nMigrate to TF2\n--------------\n\n\u003cbr /\u003e\n\n| **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.\n\nThis API is a legacy api that is only compatible with eager execution and\n[`tf.function`](../../../../tf/function) if you combine it with\n[`tf.compat.v1.keras.utils.track_tf1_style_variables`](../../../../tf/compat/v1/keras/utils/track_tf1_style_variables)\n\nPlease refer to [tf.layers model mapping section of the migration guide](https://www.tensorflow.org/guide/migrate/model_mapping)\nto learn how to use your TensorFlow v1 model in TF2 with Keras.\n\nThe corresponding TensorFlow v2 layer is [`tf.keras.layers.Dense`](../../../../tf/keras/layers/Dense).\n\n#### Structural Mapping to Native TF2\n\nNone of the supported arguments have changed name.\n\nBefore: \n\n y = tf.compat.v1.layers.dense(x, units=3)\n\nAfter:\n\nTo migrate code using TF1 functional layers use the [Keras Functional API](https://www.tensorflow.org/guide/keras/functional): \n\n x = tf.keras.Input((28,))\n y = tf.keras.layers.Dense(units=3)(x)\n model = tf.keras.Model(x, y)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nDescription\n-----------\n\nThis layer implements the operation:\n`outputs = activation(inputs * kernel + bias)`\nwhere `activation` is the activation function passed as the `activation`\nargument (if not `None`), `kernel` is a weights matrix created by the layer,\nand `bias` is a bias vector created by the layer\n(only if `use_bias` is `True`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `inputs` | Tensor input. |\n| `units` | Integer or Long, dimensionality of the output space. |\n| `activation` | Activation function (callable). Set it to None to maintain a linear activation. |\n| `use_bias` | Boolean, whether the layer uses a bias. |\n| `kernel_initializer` | Initializer function for the weight matrix. If `None` (default), weights are initialized using the default initializer used by [`tf.compat.v1.get_variable`](../../../../tf/compat/v1/get_variable). |\n| `bias_initializer` | Initializer function for the bias. |\n| `kernel_regularizer` | Regularizer function for the weight matrix. |\n| `bias_regularizer` | Regularizer function for the bias. |\n| `activity_regularizer` | Regularizer function for the output. |\n| `kernel_constraint` | An optional projection function to be applied to the kernel after being updated by an `Optimizer` (e.g. used to implement norm constraints or value constraints for layer weights). The function must take as input the unprojected variable and must return the projected variable (which must have the same shape). Constraints are not safe to use when doing asynchronous distributed training. |\n| `bias_constraint` | An optional projection function to be applied to the bias after being updated by an `Optimizer`. |\n| `trainable` | Boolean, if `True` also add variables to the graph collection `GraphKeys.TRAINABLE_VARIABLES` (see [`tf.Variable`](../../../../tf/Variable)). |\n| `name` | String, the name of the layer. |\n| `reuse` | Boolean, whether to reuse the weights of a previous layer by the same name. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Output tensor the same shape as `inputs` except the last dimension is of size `units`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------|\n| `ValueError` | if eager execution is enabled. |\n\n\u003cbr /\u003e"]]