Skip to content

Commit

Permalink
Fix: Replace float template parameter with int for C++17 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Cydral authored Aug 28, 2024
1 parent f21f6d7 commit 63e181c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
23 changes: 7 additions & 16 deletions dlib/dnn/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2136,30 +2136,21 @@ namespace dlib

// ----------------------------------------------------------------------------------------

template <float DROP_RATE>
template <int DROP_RATE_PERCENT>
class dropout_rate_ : public dropout_
{
public:
explicit dropout_rate_() : dropout_(DROP_RATE)
explicit dropout_rate_() : dropout_(static_cast<float>(DROP_RATE_PERCENT) / 100.0f)
{
DLIB_CASSERT(0 <= DROP_RATE && DROP_RATE <= 1,
"DROP_RATE must be between 0 and 1, inclusive.");
static_assert(DROP_RATE_PERCENT >= 0 && DROP_RATE_PERCENT <= 100,
"DROP_RATE_PERCENT must be between 0 and 100, inclusive.");
}
};

template <float DROP_RATE, typename SUBNET>
template <int DROP_RATE, typename SUBNET>
using dropout_rate = add_layer<dropout_rate_<DROP_RATE>, SUBNET>;

template <typename SUBNET>
using dropout_rate_5 = add_layer<dropout_rate_<0.05f>, SUBNET>;
template <typename SUBNET>
using dropout_rate_10 = add_layer<dropout_rate_<0.10f>, SUBNET>;
template <typename SUBNET>
using dropout_rate_15 = add_layer<dropout_rate_<0.15f>, SUBNET>;
template <typename SUBNET>
using dropout_rate_20 = add_layer<dropout_rate_<0.20f>, SUBNET>;
template <typename SUBNET>
using dropout_rate_25 = add_layer<dropout_rate_<0.25f>, SUBNET>;
using dropout_10 = add_layer<dropout_rate_<10>, SUBNET>;

// ----------------------------------------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions dlib/dnn/layers_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ namespace dlib

// ----------------------------------------------------------------------------------------

template <float DROP_RATE>
template <int DROP_RATE_PERCENT>
class dropout_rate_ : public dropout_
{
/*!
Expand All @@ -1451,7 +1451,7 @@ namespace dlib
flexibility and clarity in the network architecture definition.
TEMPLATE PARAMETERS
- DROP_RATE: A float value between 0 and 1 that specifies the dropout rate.
- 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.
!*/

Expand All @@ -1464,7 +1464,7 @@ namespace dlib
!*/
};

template <float DROP_RATE, typename SUBNET>
template <int DROP_RATE, typename SUBNET>
using dropout_rate = add_layer<dropout_rate_<DROP_RATE>, SUBNET>;

// ----------------------------------------------------------------------------------------
Expand Down

0 comments on commit 63e181c

Please sign in to comment.