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
667b60db
Commit
667b60db
authored
Dec 24, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the add_prev_ layer
parent
fb2fa0f7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
0 deletions
+150
-0
layers.h
dlib/dnn/layers.h
+81
-0
layers_abstract.h
dlib/dnn/layers_abstract.h
+69
-0
No files found.
dlib/dnn/layers.h
View file @
667b60db
...
@@ -845,6 +845,87 @@ namespace dlib
...
@@ -845,6 +845,87 @@ namespace dlib
template
<
typename
SUBNET
>
template
<
typename
SUBNET
>
using
affine
=
add_layer
<
affine_
,
SUBNET
>
;
using
affine
=
add_layer
<
affine_
,
SUBNET
>
;
// ----------------------------------------------------------------------------------------
template
<
template
<
typename
>
class
tag
>
class
add_prev_
{
public
:
add_prev_
()
{
}
template
<
typename
SUBNET
>
void
setup
(
const
SUBNET
&
/*sub*/
)
{
}
template
<
typename
SUBNET
>
void
forward
(
const
SUBNET
&
sub
,
resizable_tensor
&
output
)
{
output
.
copy_size
(
sub
.
get_output
());
tt
::
add
(
output
,
sub
.
get_output
(),
layer
<
tag
>
(
sub
).
get_output
());
}
template
<
typename
SUBNET
>
void
backward
(
const
tensor
&
gradient_input
,
SUBNET
&
sub
,
tensor
&
/*params_grad*/
)
{
// The gradient just flows backwards to the two layers that forward() added
// together.
tt
::
add
(
sub
.
get_gradient_input
(),
sub
.
get_gradient_input
(),
gradient_input
);
tt
::
add
(
layer
<
tag
>
(
sub
).
get_gradient_input
(),
layer
<
tag
>
(
sub
).
get_gradient_input
(),
gradient_input
);
}
const
tensor
&
get_layer_params
()
const
{
return
params
;
}
tensor
&
get_layer_params
()
{
return
params
;
}
friend
void
serialize
(
const
add_prev_
&
,
std
::
ostream
&
out
)
{
serialize
(
"add_prev_"
,
out
);
}
friend
void
deserialize
(
add_prev_
&
,
std
::
istream
&
in
)
{
std
::
string
version
;
deserialize
(
version
,
in
);
if
(
version
!=
"add_prev_"
)
throw
serialization_error
(
"Unexpected version found while deserializing dlib::add_prev_."
);
}
private
:
resizable_tensor
params
;
};
template
<
template
<
typename
>
class
tag
,
typename
SUBNET
>
using
add_prev
=
add_layer
<
add_prev_
<
tag
>
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev1
=
add_prev
<
tag1
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev2
=
add_prev
<
tag2
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev3
=
add_prev
<
tag3
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev4
=
add_prev
<
tag4
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev5
=
add_prev
<
tag5
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev6
=
add_prev
<
tag6
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev7
=
add_prev
<
tag7
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev8
=
add_prev
<
tag8
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev9
=
add_prev
<
tag9
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev10
=
add_prev
<
tag10
,
SUBNET
>
;
using
add_prev1_
=
add_prev_
<
tag1
>
;
using
add_prev2_
=
add_prev_
<
tag2
>
;
using
add_prev3_
=
add_prev_
<
tag3
>
;
using
add_prev4_
=
add_prev_
<
tag4
>
;
using
add_prev5_
=
add_prev_
<
tag5
>
;
using
add_prev6_
=
add_prev_
<
tag6
>
;
using
add_prev7_
=
add_prev_
<
tag7
>
;
using
add_prev8_
=
add_prev_
<
tag8
>
;
using
add_prev9_
=
add_prev_
<
tag9
>
;
using
add_prev10_
=
add_prev_
<
tag10
>
;
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class
relu_
class
relu_
...
...
dlib/dnn/layers_abstract.h
View file @
667b60db
...
@@ -1039,6 +1039,75 @@ namespace dlib
...
@@ -1039,6 +1039,75 @@ namespace dlib
template
<
typename
SUBNET
>
template
<
typename
SUBNET
>
using
softmax
=
add_layer
<
softmax_
,
SUBNET
>
;
using
softmax
=
add_layer
<
softmax_
,
SUBNET
>
;
// ----------------------------------------------------------------------------------------
template
<
template
<
typename
>
class
tag
>
class
add_prev_
{
/*!
WHAT THIS OBJECT REPRESENTS
This is an implementation of the EXAMPLE_LAYER_ interface defined above.
This layer simply adds the output of two previous layers. In particular,
it adds the tensor from its immediate predecessor layer, sub.get_output(),
with the tensor from a deeper layer, layer<tag>(sub).get_output().
Therefore, you supply a tag via add_prev_'s template argument that tells it
what layer to add to the output of the previous layer. The result of this
addition is output by add_prev_. Finally, the addition happens pointwise
according to 4D tensor arithmetic. If the dimensions don't match then
missing elements are presumed to be equal to 0.
!*/
public
:
add_prev_
(
);
template
<
typename
SUBNET
>
void
setup
(
const
SUBNET
&
sub
);
template
<
typename
SUBNET
>
void
forward
(
const
SUBNET
&
sub
,
resizable_tensor
&
output
);
template
<
typename
SUBNET
>
void
backward
(
const
tensor
&
gradient_input
,
SUBNET
&
sub
,
tensor
&
params_grad
);
const
tensor
&
get_layer_params
()
const
;
tensor
&
get_layer_params
();
/*!
These functions are implemented as described in the EXAMPLE_LAYER_ interface.
!*/
};
void
serialize
(
const
add_prev_
&
item
,
std
::
ostream
&
out
);
void
deserialize
(
add_prev_
&
item
,
std
::
istream
&
in
);
/*!
provides serialization support
!*/
template
<
template
<
typename
>
class
tag
,
typename
SUBNET
>
using
add_prev
=
add_layer
<
add_prev_
<
tag
>
,
SUBNET
>
;
// Here we add some convenient aliases for using add_prev_ with the tag layers.
template
<
typename
SUBNET
>
using
add_prev1
=
add_prev
<
tag1
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev2
=
add_prev
<
tag2
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev3
=
add_prev
<
tag3
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev4
=
add_prev
<
tag4
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev5
=
add_prev
<
tag5
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev6
=
add_prev
<
tag6
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev7
=
add_prev
<
tag7
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev8
=
add_prev
<
tag8
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev9
=
add_prev
<
tag9
,
SUBNET
>
;
template
<
typename
SUBNET
>
using
add_prev10
=
add_prev
<
tag10
,
SUBNET
>
;
using
add_prev1_
=
add_prev_
<
tag1
>
;
using
add_prev2_
=
add_prev_
<
tag2
>
;
using
add_prev3_
=
add_prev_
<
tag3
>
;
using
add_prev4_
=
add_prev_
<
tag4
>
;
using
add_prev5_
=
add_prev_
<
tag5
>
;
using
add_prev6_
=
add_prev_
<
tag6
>
;
using
add_prev7_
=
add_prev_
<
tag7
>
;
using
add_prev8_
=
add_prev_
<
tag8
>
;
using
add_prev9_
=
add_prev_
<
tag9
>
;
using
add_prev10_
=
add_prev_
<
tag10
>
;
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
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