Commit 86bed7c1 authored by Davis King's avatar Davis King

Added visit_layers()

parent 2927671d
......@@ -3198,6 +3198,57 @@ namespace dlib
impl::vlpg_loop<0, net_type::num_layers>::visit(comp_i, net, v);
}
// ----------------------------------------------------------------------------------------
namespace impl
{
template <size_t i, size_t num>
struct vl_loop
{
template <
typename net_type,
typename visitor
>
static void visit(
net_type& net,
visitor&& v
)
{
v(i, layer<i>(net));
vl_loop<i+1, num>::visit(net,v);
}
};
template <size_t num>
struct vl_loop<num,num>
{
template <
typename net_type,
typename visitor
>
static void visit(
net_type&,
visitor&&
)
{
// Base case of recursion. Don't do anything.
}
};
}
template <
typename net_type,
typename visitor
>
void visit_layers(
net_type& net,
visitor v
)
{
impl::vl_loop<0, net_type::num_layers>::visit(net, v);
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -1425,6 +1425,32 @@ namespace dlib
- When v() is called, the first argument is always < net_type::num_computational_layers.
!*/
// ----------------------------------------------------------------------------------------
template <
typename net_type,
typename visitor
>
void visit_layers(
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. To be specific, this
function essentially performs the following:
for (size_t i = 0; i < net_type::num_layers; ++i)
v(i, layer<i>(net));
!*/
// ----------------------------------------------------------------------------------------
struct layer_test_results
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment