Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
172647f8
Commit
172647f8
authored
Jun 12, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved log1pexp() and randomize_parameters() from core.h into utilities.h
parent
6578c1b5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
61 deletions
+66
-61
core.h
dlib/dnn/core.h
+0
-35
core_abstract.h
dlib/dnn/core_abstract.h
+0
-26
layers.h
dlib/dnn/layers.h
+1
-0
utilities.h
dlib/dnn/utilities.h
+35
-0
utilities_abstract.h
dlib/dnn/utilities_abstract.h
+30
-0
No files found.
dlib/dnn/core.h
View file @
172647f8
...
...
@@ -112,23 +112,6 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
inline
double
log1pexp
(
double
x
)
{
using
std
::
exp
;
using
namespace
std
;
// Do this instead of using std::log1p because some compilers
// error out otherwise (E.g. gcc 4.9 in cygwin)
if
(
x
<=
-
37
)
return
exp
(
x
);
else
if
(
-
37
<
x
&&
x
<=
18
)
return
log1p
(
exp
(
x
));
else
if
(
18
<
x
&&
x
<=
33
.
3
)
return
x
+
exp
(
-
x
);
else
return
x
;
}
// ----------------------------------------------------------------------------------------
// Tell us if T is one of the special layer types (i.e. add_layer, repeat, add_tag_layer, or
...
...
@@ -442,24 +425,6 @@ namespace dlib
{
return
item
;
}
// ----------------------------------------------------------------------------------------
inline
void
randomize_parameters
(
tensor
&
params
,
unsigned
long
num_inputs_and_outputs
,
dlib
::
rand
&
rnd
)
{
for
(
auto
&
val
:
params
)
{
// Draw a random number to initialize the layer according to formula (16)
// from Understanding the difficulty of training deep feedforward neural
// networks by Xavier Glorot and Yoshua Bengio.
val
=
2
*
rnd
.
get_random_float
()
-
1
;
val
*=
std
::
sqrt
(
6
.
0
/
(
num_inputs_and_outputs
));
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
...
...
dlib/dnn/core_abstract.h
View file @
172647f8
...
...
@@ -16,23 +16,6 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
randomize_parameters
(
tensor
&
params
,
unsigned
long
num_inputs_and_outputs
,
dlib
::
rand
&
rnd
);
/*!
ensures
- This function assigns random values into params based on the given random
number generator. In particular, it uses the parameter initialization method
of formula 16 from the paper "Understanding the difficulty of training deep
feedforward neural networks" by Xavier Glorot and Yoshua Bengio.
- It is assumed that the total number of inputs and outputs from the layer is
num_inputs_and_outputs. That is, you should set num_inputs_and_outputs to
the sum of the dimensionalities of the vectors going into and out of the
layer that uses params as its parameters.
!*/
template
<
typename
...
T
>
...
...
@@ -58,15 +41,6 @@ namespace dlib
a non-std::tuple object is found.
!*/
double
log1pexp
(
double
x
);
/*!
ensures
- returns log(1+exp(x))
(except computes it using a numerically accurate method)
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
...
...
dlib/dnn/layers.h
View file @
172647f8
...
...
@@ -12,6 +12,7 @@
#include "../string.h"
#include "tensor_tools.h"
#include "../vectorstream.h"
#include "utilities.h"
namespace
dlib
...
...
dlib/dnn/utilities.h
View file @
172647f8
...
...
@@ -9,6 +9,41 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
inline
double
log1pexp
(
double
x
)
{
using
std
::
exp
;
using
namespace
std
;
// Do this instead of using std::log1p because some compilers
// error out otherwise (E.g. gcc 4.9 in cygwin)
if
(
x
<=
-
37
)
return
exp
(
x
);
else
if
(
-
37
<
x
&&
x
<=
18
)
return
log1p
(
exp
(
x
));
else
if
(
18
<
x
&&
x
<=
33
.
3
)
return
x
+
exp
(
-
x
);
else
return
x
;
}
// ----------------------------------------------------------------------------------------
inline
void
randomize_parameters
(
tensor
&
params
,
unsigned
long
num_inputs_and_outputs
,
dlib
::
rand
&
rnd
)
{
for
(
auto
&
val
:
params
)
{
// Draw a random number to initialize the layer according to formula (16)
// from Understanding the difficulty of training deep feedforward neural
// networks by Xavier Glorot and Yoshua Bengio.
val
=
2
*
rnd
.
get_random_float
()
-
1
;
val
*=
std
::
sqrt
(
6
.
0
/
(
num_inputs_and_outputs
));
}
}
// ----------------------------------------------------------------------------------------
namespace
impl
...
...
dlib/dnn/utilities_abstract.h
View file @
172647f8
...
...
@@ -8,6 +8,36 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
double
log1pexp
(
double
x
);
/*!
ensures
- returns log(1+exp(x))
(except computes it using a numerically accurate method)
!*/
// ----------------------------------------------------------------------------------------
void
randomize_parameters
(
tensor
&
params
,
unsigned
long
num_inputs_and_outputs
,
dlib
::
rand
&
rnd
);
/*!
ensures
- This function assigns random values into params based on the given random
number generator. In particular, it uses the parameter initialization method
of formula 16 from the paper "Understanding the difficulty of training deep
feedforward neural networks" by Xavier Glorot and Yoshua Bengio.
- It is assumed that the total number of inputs and outputs from the layer is
num_inputs_and_outputs. That is, you should set num_inputs_and_outputs to
the sum of the dimensionalities of the vectors going into and out of the
layer that uses params as its parameters.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
net_type
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment