diff --git a/dlib/dnn/layers.h b/dlib/dnn/layers.h index f92749d7b..77ff918a6 100644 --- a/dlib/dnn/layers.h +++ b/dlib/dnn/layers.h @@ -2134,6 +2134,24 @@ namespace dlib template using dropout = add_layer; +// ---------------------------------------------------------------------------------------- + + template + class dropout_rate_ : public dropout_ + { + public: + explicit dropout_rate_() : dropout_(static_cast(DROP_RATE_PERCENT) / 100.0f) + { + static_assert(DROP_RATE_PERCENT >= 0 && DROP_RATE_PERCENT <= 100, + "DROP_RATE_PERCENT must be between 0 and 100, inclusive."); + } + }; + + template + using dropout_rate = add_layer, SUBNET>; + template + using dropout_10 = add_layer, SUBNET>; + // ---------------------------------------------------------------------------------------- class multiply_ diff --git a/dlib/dnn/layers_abstract.h b/dlib/dnn/layers_abstract.h index 1ddecead0..7a29ab134 100644 --- a/dlib/dnn/layers_abstract.h +++ b/dlib/dnn/layers_abstract.h @@ -1433,6 +1433,41 @@ namespace dlib template using dropout = add_layer; +// ---------------------------------------------------------------------------------------- + + template + class dropout_rate_ : public dropout_ + { + /*! + WHAT THIS OBJECT REPRESENTS + This object represents a customizable dropout layer that inherits from + the dropout_ class. It allows specifying the dropout rate at compile-time, + which is particularly useful for deep networks with many layers where it + might be cumbersome to explicitly modify the dropout rate for each layer + individually. + + The main advantage of this layer is that it offers the possibility to specify + the dropout rate at the moment of network construction, providing more + flexibility and clarity in the network architecture definition. + + TEMPLATE PARAMETERS + - DROP_RATE_PERCENT: A int value between 0 and 100 that specifies the dropout rate. + This value is set at compile-time and cannot be changed during runtime. + !*/ + + public: + explicit dropout_rate_(); + /*! + ensures + - Constructs a dropout layer with a dropout rate of DROP_RATE. + - Calls the base class constructor dropout_(DROP_RATE). + !*/ + }; + + template + using dropout_rate = add_layer, SUBNET>; + template + using dropout_10 = add_layer, SUBNET>; // ---------------------------------------------------------------------------------------- class multiply_