Commit bdd5016d authored by Davis King's avatar Davis King

Added options to input_rgb_image_pyramid that let the user set…

Added options to input_rgb_image_pyramid that let the user set create_tiled_pyramid()'s padding parameters.

Also changed the default outer border padding from 0 to 11. This effects even
previously trained models.  So any model that doesn't explicitly set the outer
patting to something else will have a padding of 11.  This should be a more
reasonable value for most networks.
parent cf77875d
...@@ -521,6 +521,12 @@ namespace dlib ...@@ -521,6 +521,12 @@ namespace dlib
float get_avg_green() const { return avg_green; } float get_avg_green() const { return avg_green; }
float get_avg_blue() const { return avg_blue; } float get_avg_blue() const { return avg_blue; }
unsigned long get_pyramid_padding () const { return pyramid_padding; }
void set_pyramid_padding (unsigned long value) { pyramid_padding = value; }
unsigned long get_pyramid_outer_padding () const { return pyramid_outer_padding; }
void set_pyramid_outer_padding (unsigned long value) { pyramid_outer_padding = value; }
bool image_contained_point ( bool image_contained_point (
const tensor& data, const tensor& data,
const point& p const point& p
...@@ -579,9 +585,9 @@ namespace dlib ...@@ -579,9 +585,9 @@ namespace dlib
parallel_for(0, imgs.size(), [&](long i){ parallel_for(0, imgs.size(), [&](long i){
std::vector<rectangle> rects; std::vector<rectangle> rects;
if (i == 0) if (i == 0)
create_tiled_pyramid<pyramid_type>(ibegin[i], imgs[i], data.annotation().get<std::vector<rectangle>>()); create_tiled_pyramid<pyramid_type>(ibegin[i], imgs[i], data.annotation().get<std::vector<rectangle>>(), pyramid_padding, pyramid_outer_padding);
else else
create_tiled_pyramid<pyramid_type>(ibegin[i], imgs[i], rects); create_tiled_pyramid<pyramid_type>(ibegin[i], imgs[i], rects, pyramid_padding, pyramid_outer_padding);
}); });
nr = imgs[0].nr(); nr = imgs[0].nr();
nc = imgs[0].nc(); nc = imgs[0].nc();
...@@ -611,38 +617,58 @@ namespace dlib ...@@ -611,38 +617,58 @@ namespace dlib
friend void serialize(const input_rgb_image_pyramid& item, std::ostream& out) friend void serialize(const input_rgb_image_pyramid& item, std::ostream& out)
{ {
serialize("input_rgb_image_pyramid", out); serialize("input_rgb_image_pyramid2", out);
serialize(item.avg_red, out); serialize(item.avg_red, out);
serialize(item.avg_green, out); serialize(item.avg_green, out);
serialize(item.avg_blue, out); serialize(item.avg_blue, out);
serialize(item.pyramid_padding, out);
serialize(item.pyramid_outer_padding, out);
} }
friend void deserialize(input_rgb_image_pyramid& item, std::istream& in) friend void deserialize(input_rgb_image_pyramid& item, std::istream& in)
{ {
std::string version; std::string version;
deserialize(version, in); deserialize(version, in);
if (version != "input_rgb_image_pyramid") if (version != "input_rgb_image_pyramid" && version != "input_rgb_image_pyramid2")
throw serialization_error("Unexpected version found while deserializing dlib::input_rgb_image_pyramid."); throw serialization_error("Unexpected version found while deserializing dlib::input_rgb_image_pyramid.");
deserialize(item.avg_red, in); deserialize(item.avg_red, in);
deserialize(item.avg_green, in); deserialize(item.avg_green, in);
deserialize(item.avg_blue, in); deserialize(item.avg_blue, in);
if (version == "input_rgb_image_pyramid2")
{
deserialize(item.pyramid_padding, in);
deserialize(item.pyramid_outer_padding, in);
}
else
{
item.pyramid_padding = 10;
item.pyramid_outer_padding = 11;
}
} }
friend std::ostream& operator<<(std::ostream& out, const input_rgb_image_pyramid& item) friend std::ostream& operator<<(std::ostream& out, const input_rgb_image_pyramid& item)
{ {
out << "input_rgb_image_pyramid("<<item.avg_red<<","<<item.avg_green<<","<<item.avg_blue<<")"; out << "input_rgb_image_pyramid("<<item.avg_red<<","<<item.avg_green<<","<<item.avg_blue<<")";
out << " pyramid_padding="<<item.pyramid_padding;
out << " pyramid_outer_padding="<<item.pyramid_outer_padding;
return out; return out;
} }
friend void to_xml(const input_rgb_image_pyramid& item, std::ostream& out) friend void to_xml(const input_rgb_image_pyramid& item, std::ostream& out)
{ {
out << "<input_rgb_image_pyramid r='"<<item.avg_red<<"' g='"<<item.avg_green<<"' b='"<<item.avg_blue<<"'/>"; out << "<input_rgb_image_pyramid r='"<<item.avg_red<<"' g='"<<item.avg_green
<<"' b='"<<item.avg_blue
<<"' pyramid_padding='"<<item.pyramid_padding
<<"' pyramid_outer_padding='"<<item.pyramid_outer_padding
<<"'/>";
} }
private: private:
float avg_red; float avg_red;
float avg_green; float avg_green;
float avg_blue; float avg_blue;
unsigned long pyramid_padding = 10;
unsigned long pyramid_outer_padding = 11;
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -294,6 +294,8 @@ namespace dlib ...@@ -294,6 +294,8 @@ namespace dlib
- #get_avg_red() == 122.782 - #get_avg_red() == 122.782
- #get_avg_green() == 117.001 - #get_avg_green() == 117.001
- #get_avg_blue() == 104.298 - #get_avg_blue() == 104.298
- #get_pyramid_padding() == 10
- #get_pyramid_outer_padding() == 11
!*/ !*/
input_rgb_image_pyramid ( input_rgb_image_pyramid (
...@@ -306,6 +308,8 @@ namespace dlib ...@@ -306,6 +308,8 @@ namespace dlib
- #get_avg_red() == avg_red - #get_avg_red() == avg_red
- #get_avg_green() == avg_green - #get_avg_green() == avg_green
- #get_avg_blue() == avg_blue - #get_avg_blue() == avg_blue
- #get_pyramid_padding() == 10
- #get_pyramid_outer_padding() == 11
!*/ !*/
float get_avg_red( float get_avg_red(
...@@ -329,6 +333,37 @@ namespace dlib ...@@ -329,6 +333,37 @@ namespace dlib
- returns the value subtracted from the blue color channel. - returns the value subtracted from the blue color channel.
!*/ !*/
unsigned long get_pyramid_padding (
) const;
/*!
ensures
- When this object creates a pyramid it will call create_tiled_pyramid() and
set create_tiled_pyramid's pyramid_padding parameter to get_pyramid_padding().
!*/
void set_pyramid_padding (
unsigned long value
);
/*!
ensures
- #get_pyramid_padding() == value
!*/
unsigned long get_pyramid_outer_padding (
) const;
/*!
ensures
- When this object creates a pyramid it will call create_tiled_pyramid()
and set create_tiled_pyramid's pyramid_outer_padding parameter to
get_pyramid_outer_padding().
!*/
void set_pyramid_outer_padding (
unsigned long value
);
/*!
ensures
- #get_pyramid_outer_padding() == value
!*/
template <typename forward_iterator> template <typename forward_iterator>
void to_tensor ( void to_tensor (
forward_iterator ibegin, forward_iterator ibegin,
......
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