Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
d7c003d1
Commit
d7c003d1
authored
Sep 03, 2016
by
Davis King
Browse files
Added visit_layers_backwards(), visit_layers_backwards_range(), and
visit_layers_range().
parent
9726ce1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
0 deletions
+160
-0
dlib/dnn/core.h
dlib/dnn/core.h
+77
-0
dlib/dnn/core_abstract.h
dlib/dnn/core_abstract.h
+83
-0
No files found.
dlib/dnn/core.h
View file @
d7c003d1
...
...
@@ -3337,6 +3337,39 @@ namespace dlib
}
};
template
<
size_t
i
,
size_t
num
>
struct
vl_loop_backwards
{
template
<
typename
net_type
,
typename
visitor
>
static
void
visit
(
net_type
&
net
,
visitor
&&
v
)
{
vl_loop
<
i
+
1
,
num
>::
visit
(
net
,
v
);
v
(
i
,
layer
<
i
>
(
net
));
}
};
template
<
size_t
num
>
struct
vl_loop_backwards
<
num
,
num
>
{
template
<
typename
net_type
,
typename
visitor
>
static
void
visit
(
net_type
&
,
visitor
&&
)
{
// Base case of recursion. Don't do anything.
}
};
}
template
<
...
...
@@ -3351,6 +3384,50 @@ namespace dlib
impl
::
vl_loop
<
0
,
net_type
::
num_layers
>::
visit
(
net
,
v
);
}
template
<
typename
net_type
,
typename
visitor
>
void
visit_layers_backwards
(
net_type
&
net
,
visitor
v
)
{
impl
::
vl_loop_backwards
<
0
,
net_type
::
num_layers
>::
visit
(
net
,
v
);
}
template
<
size_t
begin
,
size_t
end
,
typename
net_type
,
typename
visitor
>
void
visit_layers_range
(
net_type
&
net
,
visitor
v
)
{
static_assert
(
begin
<=
end
,
"Invalid range"
);
static_assert
(
end
<=
net_type
::
num_layers
,
"Invalid range"
);
impl
::
vl_loop
<
begin
,
end
>::
visit
(
net
,
v
);
}
template
<
size_t
begin
,
size_t
end
,
typename
net_type
,
typename
visitor
>
void
visit_layers_backwards_range
(
net_type
&
net
,
visitor
v
)
{
static_assert
(
begin
<=
end
,
"Invalid range"
);
static_assert
(
end
<=
net_type
::
num_layers
,
"Invalid range"
);
impl
::
vl_loop_backwards
<
begin
,
end
>::
visit
(
net
,
v
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/dnn/core_abstract.h
View file @
d7c003d1
...
...
@@ -1491,6 +1491,89 @@ namespace dlib
v(i, layer<i>(net));
!*/
template
<
typename
net_type
,
typename
visitor
>
void
visit_layers_backwards
(
net_type
&
net
,
visitor
v
);
/*!
requires
- net_type is an object of type add_layer, add_loss_layer, add_skip_layer, or
add_tag_layer.
- v is a function object with a signature equivalent to:
v(size_t idx, any_net_type& t)
That is, it must take a size_t and then any of the network types such as
add_layer, add_loss_layer, etc.
ensures
- Loops over all the layers in net and calls v() on them. The loop happens in
the reverse order of visit_layers(). To be specific, this function
essentially performs the following:
for (size_t i = net_type::num_layers; i != 0; --i)
v(i-1, layer<i-1>(net));
!*/
// ----------------------------------------------------------------------------------------
template
<
size_t
begin
,
size_t
end
,
typename
net_type
,
typename
visitor
>
void
visit_layers_range
(
net_type
&
net
,
visitor
v
);
/*!
requires
- net_type is an object of type add_layer, add_loss_layer, add_skip_layer, or
add_tag_layer.
- v is a function object with a signature equivalent to:
v(size_t idx, any_net_type& t)
That is, it must take a size_t and then any of the network types such as
add_layer, add_loss_layer, etc.
- begin <= end <= net_type::num_layers
ensures
- Loops over the layers in the range [begin,end) in net and calls v() on them.
The loop happens in the reverse order of visit_layers(). To be specific,
this function essentially performs the following:
for (size_t i = begin; i < end; ++i)
v(i, layer<i>(net));
!*/
template
<
size_t
begin
,
size_t
end
,
typename
net_type
,
typename
visitor
>
void
visit_layers_backwards_range
(
net_type
&
net
,
visitor
v
);
/*!
requires
- net_type is an object of type add_layer, add_loss_layer, add_skip_layer, or
add_tag_layer.
- v is a function object with a signature equivalent to:
v(size_t idx, any_net_type& t)
That is, it must take a size_t and then any of the network types such as
add_layer, add_loss_layer, etc.
- begin <= end <= net_type::num_layers
ensures
- Loops over the layers in the range [begin,end) in net and calls v() on them.
The loop happens in the reverse order of visit_layers_range(). To be specific,
this function essentially performs the following:
for (size_t i = end; i != begin; --i)
v(i-1, layer<i-1>(net));
!*/
// ----------------------------------------------------------------------------------------
struct
layer_test_results
...
...
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