libeblearntools
/home/rex/ebltrunk/tools/libeblearntools/include/bootstrapping.h
00001 /***************************************************************************
00002  *   Copyright (C) 2012 by Pierre Sermanet *
00003  *   pierre.sermanet@gmail.com *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source
00014  *       Initiative (http://www.opensource.org) must display the
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef BOOTSTRAPPING_H_
00034 #define BOOTSTRAPPING_H_
00035 
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 
00039 #include "defines_tools.h"
00040 #include "detector.h"
00041 #include "configuration.h"
00042 #include "pascal_xml.h"
00043 
00044 using namespace std;
00045 
00046 namespace ebl {
00047 
00049   template <typename T, class Tstate = fstate_idx<T> > class bootstrapping {
00050   public:
00051     bootstrapping(configuration &conf);
00052     virtual ~bootstrapping();
00053 
00058     void fprop(detector<T,Tstate> &detect, string &fname, bool reset = true,
00059                double scale = 1.0);
00061     void clear();
00062 
00063     // accessors ///////////////////////////////////////////////////////////////
00064 
00066     bboxes& get_bbpos();
00068     bboxes& get_bbneg();
00070     bboxes& get_bball();
00072     bboxes& get_gtall();
00074     bboxes& get_gtclean();
00076     bboxes& get_gtrest();
00078     svector<midx<T> >& get_pos();
00080     svector<midx<T> >& get_neg();
00082     svector<midx<T> >& get_all();
00083 
00085     bool activated();
00087     bool extract_positives();
00089     bool groundtruth_found(string &frame_name);
00093     bool skip_frame(string &frame_name);
00096     intg max_size();
00097   
00098     // dataset methods /////////////////////////////////////////////////////////
00099 
00101     void save_dataset(svector<midx<T> > &samples, bboxes &bb, string &outdir,
00102                       idx<ubyte> &classes);
00103 
00104     // internal methods ////////////////////////////////////////////////////////
00105   protected:
00106   
00108     string groundtruth_file(string &frame_name);
00110     bboxes load_groundtruth(string &frame_name);
00113     bboxes load_clean_groundtruth(string &frame_name, configuration &conf,
00114                                   bboxes &rest);
00115   
00116     bboxes get_positives(mstate<Tstate> &outputs, bboxes &groundtruth,
00117                          mfidxdim &topleft, mfidxdim &topright,
00118                          mfidxdim &bottomleft, mfidxdim &bottomright,
00119                          float matching, float min_context);
00120     bboxes get_negatives(mstate<Tstate> &answers, bboxes &filtered,
00121                          bboxes &nonfiltered,
00122                          mfidxdim &topleft, mfidxdim &topright,
00123                          mfidxdim &bottomleft, mfidxdim &bottomright,
00124                          float matching, uint nmax, int neg_id, T threshold);
00127     void add_mirrors(svector<midx<T> > &samples, bboxes &boxes);
00128 
00129     // private members /////////////////////////////////////////////////////////
00130   protected:
00131     configuration &conf;
00132     bool silent;
00133     string gt_path; 
00134     bboxes gt_all; 
00135     bboxes gt_clean; 
00136     bboxes gt_rest; 
00137     bboxes bbpos; 
00138     bboxes bbneg; 
00139     bboxes bball; 
00140     svector<midx<T> > spos; 
00141     svector<midx<T> > sneg; 
00142     svector<midx<T> > sall; 
00143     string xml_fullname; 
00144     bool extract_pos; 
00145     bool extract_neg; 
00146     bool _activated;
00147     intg _max_size;
00148     bool neg_gt_only; 
00149     T neg_threshold; 
00150     mfidxdim bbox_scalings; 
00151     bool mirror_pos; 
00152   };
00153 
00154 } // end namespace ebl
00155 
00156 #include "bootstrapping.hpp"
00157 
00158 #endif /* BOOTSTRAPPING_H_ */
00159