libeblearntools
|
#include <dataset.h>
Public Member Functions | |
dataset (const char *name, const char *inroot=NULL) | |
virtual | ~dataset () |
Destructor. | |
bool | alloc (intg max=0) |
virtual bool | extract () |
Extract data from files into dataset. | |
virtual void | extract_statistics () |
Extracts statistics about dataset into outdir/stats.csv. | |
bool | split_max_and_save (const char *name1, const char *name2, intg max, const string &outroot) |
void | split_max (dataset< Tdata > &ds1, dataset< Tdata > &ds2, intg max) |
void | merge_and_save (const char *name1, const char *name2, const string &outroot) |
void | shuffle () |
Shuffle order of samples. | |
virtual void | set_unique_label (const string &class_name) |
Set a unique label 'class_name' to all samples. | |
void | set_planar_loading () |
Input is loaded as planar (channels in first dimension). | |
const idxdim & | get_sample_outdim () |
Get sample dimensions. | |
intg | size () |
Return the number of samples in the dataset. | |
t_label | get_label_from_class (const string &class_name) |
Return unsigned int label corresponding to class name. | |
void | set_display (bool display) |
Turn display on or off. | |
void | set_sleepdisplay (uint delay) |
Make the display sleep delay milliseconds between frames. | |
void | set_preprocessing (vector< resizepp_module< fs(Tdata)> * > &p) |
Set a vector for preprocessing modules. | |
virtual void | set_outdims (const idxdim &d) |
virtual void | set_outdir (const char *s, const char *tmp=NULL) |
Specify output directory 's' and a temporary output directory 'tmp'. | |
void | set_mindims (const idxdim &d) |
void | set_maxdims (const idxdim &d) |
Specify the maximum dimensions of input samples. | |
void | set_scales (const vector< double > &sc, const string &od) |
void | set_fovea (const vector< double > &scales) |
void | set_max_per_class (intg max) |
Set all max per class to max. | |
void | set_max_data (intg max) |
Set maximum number of samples. | |
void | set_image_pattern (const string &p) |
Set the pattern used to find image. | |
void | set_exclude (const vector< string > &ex) |
Set the list of classes to exclude (including everything else). | |
void | set_include (const vector< string > &inc) |
Set the list of classes to include (excluding everything else). | |
void | set_save (const string &save) |
void | set_individual_save (bool b) |
If 'b' is true, save each intermediate sample file individually. | |
void | set_separate_layers_save (bool b) |
If 'b' is true, save each layer of each sample individually. | |
void | set_name (const string &name) |
void | set_label (const string &label) |
void | set_bbox_woverh (float factor) |
void | set_nopadded (bool nopadded) |
void | set_videobox (uint nframes, uint stride) |
void | set_jitter (uint tjitter_step, uint tjitter_hmin, uint tjitter_hmax, uint tjitter_wmin, uint tjitter_wmax, uint scale_steps, float scale_min, float scale_max, uint rotation_steps, float rotation_range, uint njitter) |
virtual void | set_minvisibility (float minvis) |
void | set_wmirror () |
Add sample mirrored with vertical-axis symmetry. | |
void | save_display (const string &dir, uint h=0, uint w=0) |
void | use_pose () |
void | use_parts () |
void | use_parts_only () |
bool | full (t_label label=-1) |
virtual intg | count_total () |
bool | load (const string &root) |
bool | save (const string &root, bool save_data=true) |
void | print_classes () |
Prints number of classes and list on standard output. | |
void | print_stats () |
Prints number of samples for each class on std output. | |
Static Public Member Functions | |
static idx< ubyte > | build_classes_idx (vector< string > &classes) |
Returns a matrix of class names based on the classes vector. | |
Protected Member Functions | |
bool | allocate (intg n, idxdim &d) |
virtual bool | add_data (midx< Tdata > &d, const t_label label, const string *class_name, const char *filename=NULL, const rect< int > *r=NULL, pair< int, int > *center=NULL, const rect< int > *visr=NULL, const rect< int > *cropr=NULL, const vector< object * > *objs=NULL, const jitter *jittforce=NULL) |
void | add_data2 (midx< Tdata > &sample, t_label label, const string *class_name, const char *filename, const jitter *jitt, idx< t_jitter > *js) |
add/save sample, called at the end of add_data(). | |
void | add_label (t_label label, const string *class_name, const char *filename, const jitter *jitt, idx< t_jitter > *js) |
Add/save label, called by add_data2(). | |
virtual void | clear_classes () |
Clear the classes. | |
virtual bool | add_class (const string &class_name) |
add a class name | |
virtual void | set_classes (idx< ubyte > &classidx) |
set all classes directly using an idx of classes strings | |
virtual intg | count_samples () |
Count and returns how many samples are present in data. | |
void | split (dataset< Tdata > &ds1, dataset< Tdata > &ds2) |
template<class Toriginal > | |
bool | save_scales (idx< Toriginal > &d, const string &filename) |
virtual bool | included (t_label &lab) |
virtual bool | included (const string &class_name) |
midx< Tdata > | preprocess_data (midx< Tdata > &d, const string *class_name, const char *filename=NULL, const rect< int > *r=NULL, double scale=0, rect< int > *outr=NULL, pair< int, int > *center=NULL, jitter *jitt=NULL, const rect< int > *visr=NULL, const rect< int > *cropr=NULL, rect< int > *inr_out=NULL) |
void | display_added (midx< Tdata > &added, idx< Tdata > &original, const string *class_name, const char *filename=NULL, const rect< int > *inr=NULL, const rect< int > *origr=NULL, bool active_sleepd=true, pair< int, int > *center=NULL, const rect< int > *visr=NULL, const rect< int > *cropr=NULL, const vector< object * > *objs=NULL, const jitter *jitt=NULL, idx< t_jitter > *js=NULL, uint *woriginal=NULL) |
string & | get_class_string (t_label id) |
Return the class name associated with label id. | |
t_label | get_class_id (const string &name) |
Return the label id associated with class name. | |
void | compute_stats () |
Compute statistics about the dataset. | |
uint | count_matches (const string &dir, const string &pattern) |
Count (recursively) how many files matching pattern are inside dir. | |
void | process_dir (const string &dir, const string &ext, const string &class_name) |
virtual void | load_data (const string &fname) |
Method to load an image. | |
virtual void | compute_random_jitter () |
Protected Attributes | |
midx< Tdata > | data |
data matrix | |
idx< t_label > | labels |
labels matrix | |
idx< intg > | ids |
indices matrix | |
midx< t_jitter > | jitters |
jitter info matrix | |
vector< string > | classes |
list of classes strings | |
idx< t_label > | classpairs |
sample pairs class-wise | |
idx< t_label > | deformpairs |
sample pairs deformation-wise | |
uint | height |
height of output | |
uint | width |
width of output | |
bool | allocated |
data matrices allocated or not | |
bool | no_outdims |
no outdims were specified. | |
idxdim | outdims |
dims of sample out dimensions | |
idxdim | mindims |
min dims of input samples | |
idxdim | maxdims |
max dims of input samples | |
bool | maxdims_set |
max dims of input samples is set? | |
idxdim | datadims |
dimensions of data out dimensions | |
uint | nlayers |
# layers per sample | |
intg | data_cnt |
number of samples added so far | |
intg | processed_cnt |
#processed (not necessarly added) | |
intg | max_data |
user can limit samples# with this | |
bool | max_data_set |
max_data been set by user or not | |
intg | total_samples |
number of samples of dataset | |
idx< intg > | max_per_class |
max # samples per class | |
intg | mpc |
value to put in max_per_class | |
bool | max_per_class_set |
mpc has been set or not | |
midx< Tdata > | load_img |
temporary image loader | |
bool | scale_mode |
scales saving mode | |
vector< double > | scales |
integer scales | |
bool | interleaved_input |
indicate input is interleaved | |
bool | load_planar |
input is planar when loaded | |
vector< string > | exclude |
list of excluded classes | |
vector< string > | include |
list of included classes | |
bool | usepose |
use pose or not | |
bool | useparts |
use parts or not | |
bool | usepartsonly |
use parts only or not | |
string | save_mode |
saving mode (dataset, ppm, png..) | |
bool | individual_save |
Save individual files or not. | |
bool | separate_layers_save |
Save separate layers or not. | |
list< string > | images_list |
List of saved image files. | |
bool | wmirror |
add vertical-axis symmetry | |
float | bbox_woverh |
bounding boxes width over h factor | |
string | force_label |
force all labels to this one | |
bool | nopadded |
ignore too small samples | |
float | minvisibility |
int | tjitter_step |
Translation step, in pixels. | |
int | tjitter_hmin |
Translation height jitter min. | |
int | tjitter_hmax |
Translation height jitter max. | |
int | tjitter_wmin |
Translation width jitter min. | |
int | tjitter_wmax |
Translation width jitter max. | |
int | sjitter_steps |
number of possible scales | |
float | sjitter_min |
min range of scales | |
float | sjitter_max |
max range of scales | |
int | rjitter_steps |
number of possible rotations | |
float | rjitter |
range of rotations | |
uint | njitter |
number of random jitters | |
bool | bjitter |
use jitter or not | |
vector< jitter > | random_jitter |
pre-computed list of random jitter | |
string | name |
dataset name | |
string | data_fname |
data filename | |
string | labels_fname |
labels filename | |
string | jitters_fname |
jitters filename | |
string | ids_fname |
ids filename | |
string | classes_fname |
classes filename | |
string | classpairs_fname |
classpairs filename | |
string | deformpairs_fname |
deformpairs filename | |
string | inroot |
root directory of input files | |
string | outdir |
root directory of output files | |
string | outtmp |
root directory of tmp output files | |
string | extension |
extension of files to extract | |
bool | display_extraction |
display during extraction | |
bool | display_result |
display extracted dataset | |
bool | sleep_display |
enable sleeping when displaying | |
uint | sleep_delay |
display sleep delay in ms | |
bool | bsave_display |
string | save_display_dir |
uint | nclasses |
Number of classes. | |
idx< intg > | class_tally |
counter for class tally | |
idx< intg > | add_tally |
counter for additions tally | |
uint | add_errors |
Number of adding failures. | |
timer | xtimer |
Extraction timer. | |
bool | do_preprocessing |
activate or deactivate pp | |
vector< resizepp_module< fs(Tdata)> * > | ppmods |
pp resizing module | |
string | pp_names |
All preprocessing names. | |
rect< int > | original_bbox |
bbox of image in resized image | |
vector< double > | fovea |
fovea context | |
bool | do_videobox |
Activate or deactivate videobox. | |
uint | videobox_nframes |
Number of future frames. | |
uint | videobox_stride |
Stride of iterating over frames. |
The dataset class allows to extract a dataset from sample files and compile all samples into one dataset matrix, formatted for learning.
ebl::dataset< Tdata >::dataset | ( | const char * | name, |
const char * | inroot = NULL |
||
) |
Initialize the dataset's name and other internal variables, but does not allocate data matrices, user must call alloc for that effect. outdims are the target output dimensions of each sample. inroot is the root directory where to extract data.
bool ebl::dataset< Tdata >::add_data | ( | midx< Tdata > & | d, |
const t_label | label, | ||
const string * | class_name, | ||
const char * | filename = NULL , |
||
const rect< int > * | r = NULL , |
||
pair< int, int > * | center = NULL , |
||
const rect< int > * | visr = NULL , |
||
const rect< int > * | cropr = NULL , |
||
const vector< object * > * | objs = NULL , |
||
const jitter * | jittforce = NULL |
||
) | [protected, virtual] |
add sample d to the data with label class_name (and converting from Toriginal to Tdata type). r is an optional region of interest rectangle in the image d.
visr | An optional bounding box for the visible area of the object |
cropr | An optional bounding box of ROI of the image to crop. Image should already be cropped, use only for display. |
objs | An optional vector of other objects in current image, for display purposes. |
objs | An optional vector of other objects in current image, for display purposes. |
jittforce | If not null, ignore other jittering and use only this one. |
bool ebl::dataset< Tdata >::alloc | ( | intg | max = 0 | ) |
Count how many samples are present in files to be compiled, and allocate buffers to the number of samples. If max is given (default is 0), then the dataset is limited to max samples (or counted samples if less).
bool ebl::dataset< Tdata >::allocate | ( | intg | n, |
idxdim & | d | ||
) | [protected] |
Allocate dataset with n samples, each with dimensions d. This method is not called by the constructor and must be called before adding data samples. The buffers can be allocated only once, this is not meant to be used as a buffer resize method.
void ebl::dataset< Tdata >::compute_random_jitter | ( | ) | [protected, virtual] |
Fills internal 'random_jitter' vector with all possible jitters in random order.
Reimplemented in ebl::pascal_dataset< Tdata >.
intg ebl::dataset< Tdata >::count_total | ( | ) | [virtual] |
Count how many samples will be present in dataset files to be compiled, this may be more than count_samples() when jitter or mirroring is activated. This returns the total.
void ebl::dataset< Tdata >::display_added | ( | midx< Tdata > & | added, |
idx< Tdata > & | original, | ||
const string * | class_name, | ||
const char * | filename = NULL , |
||
const rect< int > * | inr = NULL , |
||
const rect< int > * | origr = NULL , |
||
bool | active_sleepd = true , |
||
pair< int, int > * | center = NULL , |
||
const rect< int > * | visr = NULL , |
||
const rect< int > * | cropr = NULL , |
||
const vector< object * > * | objs = NULL , |
||
const jitter * | jitt = NULL , |
||
idx< t_jitter > * | js = NULL , |
||
uint * | woriginal = NULL |
||
) | [protected] |
Display the added sample and the original image.
visr | An optional bounding box for the visible area of the object |
cropr | An optional bounding box of ROI of the image to crop. Image should already be cropped, use only for display. |
scale | Scale the input box by this factor. |
inr | The actual rectangle used for extraction. |
origr | The original object bounding box. |
woriginal | If defined, it gets filled with the width offset at which the original image gets painted. |
bool ebl::dataset< Tdata >::full | ( | t_label | label = -1 | ) |
Dataset has reached maximum sample capacity (this can be controlled by setting max_data variable). A label can be optionally passed to return if the dataset is full for a particular class (this is relevant only if set_max_per_class has been previously set.
bool ebl::dataset< Tdata >::included | ( | t_label & | lab | ) | [protected, virtual] |
Returns true if label is authorized (based on excluded and included variables).
bool ebl::dataset< Tdata >::included | ( | const string & | class_name | ) | [protected, virtual] |
Returns true if class_name is authorized (based on excluded and included variables).
bool ebl::dataset< Tdata >::load | ( | const string & | root | ) |
Load dataset found in root. root should be including the name of the dataset, e.g.: "/data/dataset1" is going to load dataset1_*.mat
void ebl::dataset< Tdata >::merge_and_save | ( | const char * | name1, |
const char * | name2, | ||
const string & | outroot | ||
) |
merge datasets with names name1 and name2 found in outroot into this dataset and save it.
midx< Tdata > ebl::dataset< Tdata >::preprocess_data | ( | midx< Tdata > & | d, |
const string * | class_name, | ||
const char * | filename = NULL , |
||
const rect< int > * | r = NULL , |
||
double | scale = 0 , |
||
rect< int > * | outr = NULL , |
||
pair< int, int > * | center = NULL , |
||
jitter * | jitt = NULL , |
||
const rect< int > * | visr = NULL , |
||
const rect< int > * | cropr = NULL , |
||
rect< int > * | inr_out = NULL |
||
) | [protected] |
Preprocess data d of type Toriginal into an idx of type Tdata with output dimensions outdims and return the result. The type of preprocessing can be selected using set_pp_conversion().
outr | If not null, copy the rect of the input region in the output image. |
visr | An optional bounding box for the visible area of the object |
cropr | An optional bounding box of ROI of the image to crop. Image should already be cropped, use only for display. |
scale | Scale the input box by this factor. |
inr_out | If not null, this rectangle will be filled with the actual rectangle used for extraction. |
void ebl::dataset< Tdata >::process_dir | ( | const string & | dir, |
const string & | ext, | ||
const string & | class_name | ||
) | [protected] |
Recursively add all files matching the pattern ext to the dataset with class class_name.
bool ebl::dataset< Tdata >::save | ( | const string & | root, |
bool | save_data = true |
||
) |
Save dataset in root.
save_data | If false, do not save data matrix. |
void ebl::dataset< Tdata >::save_display | ( | const string & | dir, |
uint | h = 0 , |
||
uint | w = 0 |
||
) |
Saves all displayed frames to 'dir'. If h and w are different than 0, fix the saved frames to hxw.
void ebl::dataset< Tdata >::set_bbox_woverh | ( | float | factor | ) |
Force bounding box width to be h * factor. This is useful to normalize bounding boxes with varying width to a fixed height/width ratio.
void ebl::dataset< Tdata >::set_fovea | ( | const vector< double > & | scales | ) |
Setting fovea scales: the feature layer is duplicated for each scale factor provided here.
void ebl::dataset< Tdata >::set_jitter | ( | uint | tjitter_step, |
uint | tjitter_hmin, | ||
uint | tjitter_hmax, | ||
uint | tjitter_wmin, | ||
uint | tjitter_wmax, | ||
uint | scale_steps, | ||
float | scale_min, | ||
float | scale_max, | ||
uint | rotation_steps, | ||
float | rotation_range, | ||
uint | njitter | ||
) |
Add n samples randomly jittered over in a (minradius,maxradius) spatial neighborhood around original location.
void ebl::dataset< Tdata >::set_label | ( | const string & | label | ) |
If called, this method will force the dataset to assign this one label to all collected images.
void ebl::dataset< Tdata >::set_mindims | ( | const idxdim & | d | ) |
Specify the minimum dimensions of input samples. The default is: 1x1
void ebl::dataset< Tdata >::set_minvisibility | ( | float | minvis | ) | [virtual] |
Set minimum visibility ratio (between 0.0 and 1.0) of a sample. This may be used to ignore sample rects that are cropped too much while jittering. It may also be used when visible regions are defined, in which case the ratio is computed using the overlap of the visible bounding box with the original bounding box.
void ebl::dataset< Tdata >::set_name | ( | const string & | name | ) |
Set name of dataset. This name will be used by load and save methods. It is usually set in the constructor, but one can also use this method instead.
void ebl::dataset< Tdata >::set_nopadded | ( | bool | nopadded | ) |
If true, ignore samples with padded areas, i.e. too small for target size.
void ebl::dataset< Tdata >::set_outdims | ( | const idxdim & | d | ) | [virtual] |
Specify the dimensions of 1 output sample. The default is: 96x96x3
void ebl::dataset< Tdata >::set_save | ( | const string & | save | ) |
Set saving mode, default is "dataset", saving everything in single lush matrix format. other values can be "ppm", "jpg", etc.
void ebl::dataset< Tdata >::set_scales | ( | const vector< double > & | sc, |
const string & | od | ||
) |
Setting scale mode and scales: preprocess and save each image in each scale in outdir directory.
void ebl::dataset< Tdata >::set_videobox | ( | uint | nframes, |
uint | stride | ||
) |
Extract temporal features in video sequences by extracting the bboxes over n multiple frames(with a stride)
void ebl::dataset< Tdata >::split | ( | dataset< Tdata > & | ds1, |
dataset< Tdata > & | ds2 | ||
) | [protected] |
split current dataset into ds1 and ds2, using their max_per_class array (first filling ds1 until full, then ds2, therefore assuming that maximums are lower for ds1 than ds2).
void ebl::dataset< Tdata >::split_max | ( | dataset< Tdata > & | ds1, |
dataset< Tdata > & | ds2, | ||
intg | max | ||
) |
Split dataset into datasets ds1 and ds2, by limiting ds1 to max samples per class, putting anything left into ds2.
bool ebl::dataset< Tdata >::split_max_and_save | ( | const char * | name1, |
const char * | name2, | ||
intg | max, | ||
const string & | outroot | ||
) |
Split dataset into datasets ds1 and ds2, by limiting ds1 to max samples per class, putting anything left into ds2. Then save each dataset in outroot directory.
void ebl::dataset< Tdata >::use_parts | ( | ) |
also extract parts of objects if available. e.g. in pascal if for class "person", parts "face", "hand" and "foot" are available.
void ebl::dataset< Tdata >::use_parts_only | ( | ) |
only extract parts of objects if available. e.g. in pascal if for class "person", parts "face", "hand" and "foot" are available.
void ebl::dataset< Tdata >::use_pose | ( | ) |
use pose information to separate classes. e.g. if for class "person" we have "front" and "side" pose, create 2 classes "person_front" and "person_side" instead of 1 class "person".