Commit e1f2bb38 authored by Davis King's avatar Davis King

Added visit_layers_until_tag()

parent 44387e39
......@@ -3475,6 +3475,71 @@ namespace dlib
impl::vl_loop_backwards<begin,end>::visit(net, v);
}
// ----------------------------------------------------------------------------------------
namespace impl
{
template <size_t i, unsigned long tag_id>
struct vl_until_tag
{
template <
typename net_type,
typename next_net_type,
typename visitor
>
static void visit(
net_type& net,
next_net_type& next_net,
visitor&& v
)
{
v(next_net);
vl_until_tag<i+1,tag_id>::visit(net,layer<i+1>(net),v);
}
template <
typename net_type,
typename SUBNET,
typename visitor
>
static void visit(
net_type& net,
const add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v
)
{
v(next_net);
}
template <
typename net_type,
typename SUBNET,
typename visitor
>
static void visit(
net_type& net,
add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v
)
{
v(next_net);
}
};
}
template <
unsigned long tag_id,
typename net_type,
typename visitor
>
void visit_layers_until_tag(
net_type& net,
visitor v
)
{
impl::vl_until_tag<0,tag_id>::visit(net, net, v);
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -1578,6 +1578,38 @@ namespace dlib
v(i-1, layer<i-1>(net));
!*/
// ----------------------------------------------------------------------------------------
template <
unsigned long tag_id,
typename net_type,
typename visitor
>
void visit_layers_until_tag(
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(any_net_type& t)
That is, it must take any of the network types such as add_layer,
add_loss_layer, etc.
ensures
- Loops over all the layers in net beginning with layer<0>(net) and going until
a tag layer with an ID of tag_id is encountered. To be specific, this
function essentially performs the following:
size_t i = 0;
while(layer<i>(net) isn't an add_tag_layer with ID == tag_id) {
v(layer<i>(net));
++i;
}
v(layer<i>(net)); // also visits the tag layer itself at the very end.
!*/
// ----------------------------------------------------------------------------------------
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