53 const Shape& output_shape = {},
54 const string& activation_name =
"Tanh",
55 bool batch_normalization =
false,
56 const string&
label =
"dense_layer");
115 const Shape& output_shape = {},
116 const string& activation_name =
"Tanh",
117 bool batch_normalization =
false,
118 const string&
label =
"dense_layer");
177 Index output_features = 0;
189 enum Forward {Input, CombinationView, BatchNormMean, BatchNormInverseVariance, ActivationView, Output};
191 enum Backward {OutputDelta, InputDelta};
194 void configure_operators();
void set_dropout_rate(float new_dropout_rate)
Sets the dropout rate applied at the layer output.
Definition dense_layer.h:148
void read_JSON_body(const Json *) override
Reads the layer-specific JSON body (activation name, BN flag, dropout rate, output features) from the...
void set_activation_function(const string &)
Sets the activation function by name.
void set_batch_normalization(bool enable)
Enables or disables BatchNorm between the linear projection and the activation.
void set_input_shape(const Shape &) override
Updates the input shape and re-shapes weight tensors accordingly.
void set_momentum(float new_momentum)
Sets the momentum used by BatchNorm to update running statistics.
void set(const Shape &input_shape={}, const Shape &output_shape={}, const string &activation_name="Tanh", bool batch_normalization=false, const string &label="dense_layer")
Re-initializes the layer; same arguments as the constructor.
float get_momentum() const
BatchNorm momentum used when updating running statistics.
Definition dense_layer.h:90
void on_compute_dtype_changed() override
Reconfigures inner operators when the compute dtype changes.
Definition dense_layer.h:127
Shape get_output_shape() const override
Returns the per-sample output shape.
bool get_batch_normalization() const
Whether batch normalization is enabled in the pipeline.
Definition dense_layer.h:87
void set_output_shape(const Shape &) override
Updates the output features and re-shapes weight tensors accordingly.
const Activation::Function & get_activation_function() const
Reference to the activation function applied at this layer's output.
Definition dense_layer.h:81
Index get_sequence_length() const
Sequence length when the input is 2D, 1 otherwise.
Definition dense_layer.h:78
Activation::Function get_output_activation() const override
Activation function fused at the end of this layer.
Definition dense_layer.h:84
vector< pair< Shape, Type > > get_forward_specs(Index batch_size) const override
Specifications of the forward intermediate buffers.
Dense(const Shape &input_shape={}, const Shape &output_shape={}, const string &activation_name="Tanh", bool batch_normalization=false, const string &label="dense_layer")
Constructs a Dense layer.
Index get_input_features() const
Number of input features (last dimension of the input shape).
Definition dense_layer.h:72
Shape get_input_shape() const override
Returns the per-sample input shape.
Definition dense_layer.h:59
vector< Operator * > get_operators() override
Returns the active operators in pipeline order.
void back_propagate(ForwardPropagation &fp, BackPropagation &bp, size_t layer) const noexcept override
Backward pass through the Dropout, Activation, BatchNorm and Combination operators in reverse order.
Layer()=default
Default constructor; only invoked by subclasses.
string label
User-visible label for this layer instance (default "my_layer").
Definition layer.h:469
Declares the Layer abstract base class and the LayerType enumeration.
Definition adaptive_moment_estimation.h:19
Definition operators.h:107
Function
Definition operators.h:108
Definition back_propagation.h:26
Definition operators.h:199
Definition operators.h:147
Definition operators.h:65
Definition forward_propagation.h:19
Definition tensor_utilities.h:46