Commit 60d474a8 authored by Davis King's avatar Davis King

merged

parents 0bb3d9f1 972bf3c4
......@@ -2916,6 +2916,12 @@ namespace dlib
template <typename SUBNET>
void forward(const SUBNET& sub, resizable_tensor& output)
{
if (aout.num_samples() != sub.get_output().num_samples())
{
aout = alias_tensor(sub.get_output().num_samples(), _k*_nr*_nc);
ain = alias_tensor(sub.get_output().num_samples(), sub.get_output().size()/sub.get_output().num_samples());
}
output.set_size(sub.get_output().num_samples(), _k, _nr, _nc);
auto out = aout(output,0);
auto in = ain(sub.get_output(),0);
......
......@@ -428,6 +428,13 @@ namespace dlib
defined above. In particular, it defines a fully connected layer that
takes an input tensor and multiplies it by a weight matrix and outputs the
results.
The dimensions of the tensors output by this layer are as follows (letting
IN be the input tensor and OUT the output tensor):
- OUT.num_samples() == IN.num_samples()
- OUT.k() == get_num_outputs()
- OUT.nr() == 1
- OUT.nc() == 1
!*/
public:
......
......@@ -617,7 +617,10 @@ namespace dlib
size_t offset
) const
{
DLIB_CASSERT(offset+size() <= t.size());
DLIB_CASSERT(offset+size() <= t.size(),
"offset: "<<offset <<"\n"<<
"size(): "<<size() <<"\n"<<
"t.size(): "<<t.size() <<"\n");
#ifdef DLIB_USE_CUDA
if (!inst.cudnn_descriptor)
......
......@@ -6277,10 +6277,14 @@ namespace dlib
for (unsigned long i = 0; i < overlay_rects.size(); ++i)
{
const rectangle orect = get_rect_on_screen(i);
rgb_alpha_pixel color = overlay_rects[i].color;
// draw crossed out boxes slightly faded
if (overlay_rects[i].crossed_out)
color.alpha = 150;
if (rect_is_selected && selected_rect == i)
{
draw_rectangle(c, orect, invert_pixel(overlay_rects[i].color), area);
draw_rectangle(c, orect, invert_pixel(color), area);
}
else if (highlighted_rect < overlay_rects.size() && highlighted_rect == i)
{
......@@ -6308,14 +6312,14 @@ namespace dlib
}
else
{
draw_rectangle(c, orect, overlay_rects[i].color, area);
draw_rectangle(c, orect, color, area);
}
if (overlay_rects[i].label.size() != 0)
{
// make a rectangle that is at the spot we want to draw our string
rectangle r(orect.br_corner(), c.br_corner());
mfont->draw_string(c, r, overlay_rects[i].label, overlay_rects[i].color, 0,
mfont->draw_string(c, r, overlay_rects[i].label, color, 0,
std::string::npos, area);
}
......@@ -6332,17 +6336,17 @@ namespace dlib
if (rect_is_selected && selected_rect == i &&
selected_part_name.size() != 0 && selected_part_name == itr->first)
{
draw_circle(c, center(temp), temp.width()/2, invert_pixel(overlay_rects[i].color), area);
draw_circle(c, center(temp), temp.width()/2, invert_pixel(color), area);
}
else
{
draw_circle(c, center(temp), temp.width()/2, overlay_rects[i].color, area);
draw_circle(c, center(temp), temp.width()/2, color, area);
}
// make a rectangle that is at the spot we want to draw our string
rectangle r((temp.br_corner() + temp.bl_corner())/2,
c.br_corner());
mfont->draw_string(c, r, itr->first, overlay_rects[i].color, 0,
mfont->draw_string(c, r, itr->first, color, 0,
std::string::npos, area);
}
......@@ -6350,13 +6354,13 @@ namespace dlib
{
if (rect_is_selected && selected_rect == i)
{
draw_line(c, orect.tl_corner(), orect.br_corner(),invert_pixel(overlay_rects[i].color), area);
draw_line(c, orect.bl_corner(), orect.tr_corner(),invert_pixel(overlay_rects[i].color), area);
draw_line(c, orect.tl_corner(), orect.br_corner(),invert_pixel(color), area);
draw_line(c, orect.bl_corner(), orect.tr_corner(),invert_pixel(color), area);
}
else
{
draw_line(c, orect.tl_corner(), orect.br_corner(),overlay_rects[i].color, area);
draw_line(c, orect.bl_corner(), orect.tr_corner(),overlay_rects[i].color, area);
draw_line(c, orect.tl_corner(), orect.br_corner(),color, area);
draw_line(c, orect.bl_corner(), orect.tr_corner(),color, area);
}
}
}
......
......@@ -2801,7 +2801,7 @@ namespace dlib
>
void set_image_clicked_handler (
T& object,
void (T::*event_handler)(const point& p, bool is_double_click)
void (T::*event_handler)(const point& p, bool is_double_click, unsigned long btn)
);
/*
requires
......@@ -2811,6 +2811,7 @@ namespace dlib
anywhere on the image. When they do so this callback is called with the
location of the image pixel which was clicked. The is_double_click bool
will also tell you if it was a double click or single click.
- btn == the button that was released. (either base_window::LEFT, base_window::MIDDLE, or base_window::RIGHT)
- any previous calls to this function are overridden by this new call.
(i.e. you can only have one event handler associated with this
event at a time)
......@@ -2819,7 +2820,7 @@ namespace dlib
*/
void set_image_clicked_handler (
const any_function<void(const point& p, bool is_double_click)>& event_handler
const any_function<void(const point& p, bool is_double_click, unsigned long btn)>& event_handler
);
/*
ensures
......@@ -2827,6 +2828,7 @@ namespace dlib
on the image. When they do so this callback is called with the location
of the image pixel which was clicked. The is_double_click bool will also
tell you if it was a double click or single click.
- btn == the button that was released. (either base_window::LEFT, base_window::MIDDLE, or base_window::RIGHT)
- Any previous calls to this function are overridden by this new call.
(i.e. you can only have one event handler associated with this event at a
time)
......
......@@ -20,7 +20,7 @@
#include <dlib/dir_nav.h>
const char* VERSION = "1.11";
const char* VERSION = "1.12";
const int JPEG_QUALITY = 90;
......
......@@ -19,27 +19,6 @@ using namespace dlib;
extern const char* VERSION;
rgb_alpha_pixel string_to_color(
const std::string& str
)
{
if (str.size() == 0)
{
return rgb_alpha_pixel(255,0,0,255);
}
else
{
// make up a random color based on the string label.
hsi_pixel pix;
pix.h = static_cast<unsigned char>(dlib::hash(str)&0xFF);
pix.s = 255;
pix.i = 150;
rgb_alpha_pixel result;
assign_pixel(result, pix);
return result;
}
}
// ----------------------------------------------------------------------------------------
metadata_editor::
......@@ -78,6 +57,7 @@ metadata_editor(
overlay_label_name.set_text("Next Label: ");
overlay_label.set_width(200);
display.set_image_clicked_handler(*this, &metadata_editor::on_image_clicked);
display.set_overlay_rects_changed_handler(*this, &metadata_editor::on_overlay_rects_changed);
display.set_overlay_rect_selected_handler(*this, &metadata_editor::on_overlay_rect_selected);
overlay_label.set_text_modified_handler(*this, &metadata_editor::on_overlay_label_changed);
......@@ -479,7 +459,8 @@ on_lb_images_clicked(
// ----------------------------------------------------------------------------------------
std::vector<dlib::image_display::overlay_rect> get_overlays (
const dlib::image_dataset_metadata::image& data
const dlib::image_dataset_metadata::image& data,
color_mapper& string_to_color
)
{
std::vector<dlib::image_display::overlay_rect> temp(data.boxes.size());
......@@ -521,7 +502,7 @@ load_image(
if (display_equialized_image)
equalize_histogram(img);
display.set_image(img);
display.add_overlay(get_overlays(metadata.images[idx]));
display.add_overlay(get_overlays(metadata.images[idx], string_to_color));
}
// ----------------------------------------------------------------------------------------
......@@ -569,7 +550,7 @@ load_image_and_set_size(
if (display_equialized_image)
equalize_histogram(img);
display.set_image(img);
display.add_overlay(get_overlays(metadata.images[idx]));
display.add_overlay(get_overlays(metadata.images[idx], string_to_color));
}
// ----------------------------------------------------------------------------------------
......@@ -600,12 +581,21 @@ on_overlay_rects_changed(
// ----------------------------------------------------------------------------------------
void metadata_editor::
on_image_clicked(
const point& /*p*/, bool /*is_double_click*/, unsigned long /*btn*/
)
{
display.set_default_overlay_rect_color(string_to_color(trim(overlay_label.text())));
}
// ----------------------------------------------------------------------------------------
void metadata_editor::
on_overlay_label_changed(
)
{
display.set_default_overlay_rect_label(trim(overlay_label.text()));
display.set_default_overlay_rect_color(string_to_color(trim(overlay_label.text())));
}
// ----------------------------------------------------------------------------------------
......
......@@ -4,7 +4,54 @@
#define DLIB_METADATA_EdITOR_H__
#include <dlib/gui_widgets.h>
#include "dlib/data_io.h"
#include <dlib/data_io.h>
#include <dlib/pixel.h>
#include <map>
// ----------------------------------------------------------------------------------------
class color_mapper
{
public:
dlib::rgb_alpha_pixel operator() (
const std::string& str
)
{
auto i = colors.find(str);
if (i != colors.end())
{
return i->second;
}
else
{
using namespace dlib;
hsi_pixel pix;
pix.h = reverse(colors.size());
std::cout << "new h: "<< (unsigned int)pix.h << std::endl;
pix.s = 255;
pix.i = 150;
rgb_alpha_pixel result;
assign_pixel(result, pix);
colors[str] = result;
return result;
}
}
private:
// We use a bit reverse here because it causes us to evenly spread the colors as we
// allocated them. First the colors are maximally different, then become interleaved
// and progressively more similar as they are allocated.
unsigned char reverse(unsigned char b)
{
// reverse the order of the bits in b.
b = ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
return b;
}
std::map<std::string, dlib::rgb_alpha_pixel> colors;
};
// ----------------------------------------------------------------------------------------
......@@ -39,6 +86,7 @@ private:
void save_metadata_to_file (const std::string& file);
void load_image(unsigned long idx);
void load_image_and_set_size(unsigned long idx);
void on_image_clicked(const dlib::point& p, bool is_double_click, unsigned long btn);
void on_overlay_rects_changed();
void on_overlay_label_changed();
void on_overlay_rect_selected(const dlib::image_display::overlay_rect& orect);
......@@ -59,6 +107,7 @@ private:
unsigned long keyboard_jump_pos;
time_t last_keyboard_jump_pos_update;
bool display_equialized_image = false;
color_mapper string_to_color;
};
// ----------------------------------------------------------------------------------------
......
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