Commit 25ab9396 authored by Davis King's avatar Davis King

Added tag_id and made skip and add_prev layers print their id numbers when

written to an output stream.
parent e4e58ee1
...@@ -414,7 +414,7 @@ namespace dlib ...@@ -414,7 +414,7 @@ namespace dlib
{ {
if (!have_same_dimensions(data_output, sub.get_output())) if (!have_same_dimensions(data_output, sub.get_output()))
data_output.copy_size(sub.get_output()); data_output.copy_size(sub.get_output());
layer.forward_inplace(sub.get_output(),data_output); layer.forward_inplace(sub.get_output(),static_cast<tensor&>(data_output));
} }
...@@ -1378,6 +1378,12 @@ namespace dlib ...@@ -1378,6 +1378,12 @@ namespace dlib
template <unsigned long ID, typename SUBNET, typename enabled=void> template <unsigned long ID, typename SUBNET, typename enabled=void>
class add_tag_layer; class add_tag_layer;
template <template<typename SUBNET> class tag>
struct tag_id
{
const static unsigned long id = tag<impl::repeat_input_layer>::id;
};
template <unsigned long ID, typename SUBNET> template <unsigned long ID, typename SUBNET>
class add_tag_layer<ID,SUBNET, class add_tag_layer<ID,SUBNET,
typename std::enable_if<is_nonloss_layer_type<SUBNET>::value>::type> typename std::enable_if<is_nonloss_layer_type<SUBNET>::value>::type>
...@@ -1388,6 +1394,7 @@ namespace dlib ...@@ -1388,6 +1394,7 @@ namespace dlib
const static size_t num_layers = subnet_type::num_layers + 1; const static size_t num_layers = subnet_type::num_layers + 1;
const static size_t num_computational_layers = subnet_type::num_computational_layers; const static size_t num_computational_layers = subnet_type::num_computational_layers;
const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor; const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor;
const static unsigned long id = ID;
static_assert(sample_expansion_factor >= 1, static_assert(sample_expansion_factor >= 1,
"The input layer can't produce fewer output tensors than there are inputs."); "The input layer can't produce fewer output tensors than there are inputs.");
...@@ -1854,6 +1861,7 @@ namespace dlib ...@@ -1854,6 +1861,7 @@ namespace dlib
const static size_t num_computational_layers = 0; const static size_t num_computational_layers = 0;
const static size_t num_layers = 2; const static size_t num_layers = 2;
const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor; const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor;
const static unsigned long id = ID;
static_assert(sample_expansion_factor >= 1, static_assert(sample_expansion_factor >= 1,
"The input layer can't produce fewer output tensors than there are inputs."); "The input layer can't produce fewer output tensors than there are inputs.");
...@@ -2526,6 +2534,7 @@ namespace dlib ...@@ -2526,6 +2534,7 @@ namespace dlib
const static size_t num_layers = subnet_type::num_layers + 1; const static size_t num_layers = subnet_type::num_layers + 1;
const static size_t num_computational_layers = subnet_type::num_computational_layers; const static size_t num_computational_layers = subnet_type::num_computational_layers;
const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor; const static unsigned int sample_expansion_factor = subnet_type::sample_expansion_factor;
const static unsigned long id = tag_id<TAG_TYPE>::id;
static_assert(sample_expansion_factor >= 1, static_assert(sample_expansion_factor >= 1,
"The input layer can't produce fewer output tensors than there are inputs."); "The input layer can't produce fewer output tensors than there are inputs.");
...@@ -2655,7 +2664,7 @@ namespace dlib ...@@ -2655,7 +2664,7 @@ namespace dlib
void print (std::ostream& out, unsigned long idx, int& min_length) const void print (std::ostream& out, unsigned long idx, int& min_length) const
{ {
out << "layer<" << idx << ">\t"<<impl::tensor_to_str(private_get_output(), min_length) <<"skip\n"; out << "layer<" << idx << ">\t"<<impl::tensor_to_str(private_get_output(), min_length) <<"skip"<<id<<"\n";
subnet().print(out, idx+1, min_length); subnet().print(out, idx+1, min_length);
} }
......
...@@ -1222,6 +1222,18 @@ namespace dlib ...@@ -1222,6 +1222,18 @@ namespace dlib
template <typename SUBNET> using tag9 = add_tag_layer< 9, SUBNET>; template <typename SUBNET> using tag9 = add_tag_layer< 9, SUBNET>;
template <typename SUBNET> using tag10 = add_tag_layer<10, SUBNET>; template <typename SUBNET> using tag10 = add_tag_layer<10, SUBNET>;
template <template<typename SUBNET> class tag>
struct tag_id
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a tool for finding the numeric ID of a tag layer. For example,
tag_id<tag3>::id == 3.
!*/
const static unsigned long id;
};
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
......
...@@ -1435,6 +1435,8 @@ namespace dlib ...@@ -1435,6 +1435,8 @@ namespace dlib
class add_prev_ class add_prev_
{ {
public: public:
const static unsigned long id = tag_id<tag>::id;
add_prev_() add_prev_()
{ {
} }
...@@ -1483,7 +1485,7 @@ namespace dlib ...@@ -1483,7 +1485,7 @@ namespace dlib
friend std::ostream& operator<<(std::ostream& out, const add_prev_& item) friend std::ostream& operator<<(std::ostream& out, const add_prev_& item)
{ {
out << "add_prev"; out << "add_prev"<<id;
return out; return out;
} }
......
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