Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
d5dc371f
Commit
d5dc371f
authored
Sep 05, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added random_cropper and DNN MMOD example programs.
parent
9e42f86c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
0 deletions
+97
-0
CMakeLists.txt
examples/CMakeLists.txt
+2
-0
dnn_mmod_ex.cpp
examples/dnn_mmod_ex.cpp
+0
-0
random_cropper_ex.cpp
examples/random_cropper_ex.cpp
+95
-0
No files found.
examples/CMakeLists.txt
View file @
d5dc371f
...
...
@@ -36,6 +36,8 @@ if (COMPILER_CAN_DO_CPP_11)
add_example
(
dnn_inception_ex
)
add_example
(
dnn_imagenet_ex
)
add_example
(
dnn_imagenet_train_ex
)
add_example
(
dnn_mmod_ex
)
add_example
(
random_cropper_ex
)
endif
()
#here we apply our macros
...
...
examples/dnn_mmod_ex.cpp
0 → 100644
View file @
d5dc371f
This diff is collapsed.
Click to expand it.
examples/random_cropper_ex.cpp
0 → 100644
View file @
d5dc371f
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
When you are training a convolutional neural network using the loss_mmod loss
layer, you need to generate a bunch of identically sized training images. The
random_cropper is a convenient tool to help you crop out a bunch of
identically sized images from a training dataset.
This example shows you what it does exactly and talks about some of its options.
*/
#include <iostream>
#include <dlib/data_io.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
using
namespace
std
;
using
namespace
dlib
;
// ----------------------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
try
{
if
(
argc
!=
2
)
{
cout
<<
"Give an image dataset XML file to run this program."
<<
endl
;
cout
<<
"For example, if you are running from the examples folder then run this program by typing"
<<
endl
;
cout
<<
" ./random_cropper_ex faces/training.xml"
<<
endl
;
cout
<<
endl
;
return
0
;
}
// First lets load a dataset
std
::
vector
<
matrix
<
rgb_pixel
>>
images
;
std
::
vector
<
std
::
vector
<
mmod_rect
>>
boxes
;
load_image_dataset
(
images
,
boxes
,
argv
[
1
]);
// Here we make our random_cropper. It has a number of options.
random_cropper
cropper
;
// We can tell it how big we want the cropped images to be.
cropper
.
set_chip_dims
(
400
,
400
);
// Also, when doing cropping, it will map the object annotations from the
// dataset to the cropped image as well as perform random scale jittering.
// You can tell it how much scale jittering you would like by saying "please
// make the objects in the crops have a min and max size of such and such".
// You do that by calling these two functions. Here we are saying we want the
// objects in our crops to be between 0.2*400 and 0.8*400 pixels in height.
cropper
.
set_min_object_height
(
0.2
);
cropper
.
set_max_object_height
(
0.8
);
// The cropper can also randomly mirror and rotate crops, which we ask it to
// perform as well.
cropper
.
set_randomly_flip
(
true
);
cropper
.
set_max_rotation_degrees
(
50
);
// This fraction of crops are from random parts of images, rather than being centered
// on some object.
cropper
.
set_background_crops_fraction
(
0.2
);
// Now ask the cropper to generate a bunch of crops. The output is stored in
// crops and crop_boxes.
std
::
vector
<
matrix
<
rgb_pixel
>>
crops
;
std
::
vector
<
std
::
vector
<
mmod_rect
>>
crop_boxes
;
// Make 1000 crops.
cropper
(
1000
,
images
,
boxes
,
crops
,
crop_boxes
);
// Finally, lets look at the results
image_window
win
;
for
(
size_t
i
=
0
;
i
<
crops
.
size
();
++
i
)
{
win
.
clear_overlay
();
win
.
set_image
(
crops
[
i
]);
for
(
auto
b
:
crop_boxes
[
i
])
{
// Note that mmod_rect has an ignore field. If an object was labeled
// ignore in boxes then it will still be labeled as ignore in
// crop_boxes. Moreover, objects that are not well contained within
// the crop are also set to ignore.
if
(
b
.
ignore
)
win
.
add_overlay
(
b
.
rect
,
rgb_pixel
(
255
,
255
,
0
));
// draw ignored boxes as orange
else
win
.
add_overlay
(
b
.
rect
,
rgb_pixel
(
255
,
0
,
0
));
// draw other boxes as red
}
cout
<<
"Hit enter to view the next random crop."
;
cin
.
get
();
}
}
catch
(
std
::
exception
&
e
)
{
cout
<<
e
.
what
()
<<
endl
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment