예제 #1
0
  bool tracking_thread<Tnet>::get_data(vector<bbox*> &bboxes2,
				       idx<ubyte> &frame2, idx<ubyte> &tpl2) {
    // lock data
    pthread_mutex_lock(&mutex_out);
    // only read data if it has been updated
    if (!out_updated) {
      // unlock data
      pthread_mutex_unlock(&mutex_out);
      return false;
    }
    // clear bboxes
    for (ibox = bboxes2.begin(); ibox != bboxes2.end(); ++ibox) {
      if (*ibox)
	delete *ibox;
    }
    bboxes2.clear();
    // copy bboxes pointers (now responsible for deleting them).
    for (ibox = bboxes.begin(); ibox != bboxes.end(); ++ibox) {
      bboxes2.push_back(*ibox);
    }
    // check frame is correctly allocated, if not, allocate.
    if (frame2.order() != frame.order()) 
      frame2 = idx<ubyte>(frame.get_idxdim());
    else if (frame2.get_idxdim() != frame.get_idxdim())
      frame2.resize(frame.get_idxdim());
    // copy frame
    idx_copy(frame, frame2);    
    // check tpl is correctly allocated, if not, allocate.
    if (tpl2.order() != tpl.order()) 
      tpl2 = idx<ubyte>(tpl.get_idxdim());
    else if (tpl2.get_idxdim() != tpl.get_idxdim())
      tpl2.resize(tpl.get_idxdim());
    // copy tpl
    idx_copy(tpl, tpl2);    
    // reset updated flag
    out_updated = false; 
    // unlock data
    pthread_mutex_unlock(&mutex_out);
    // confirm that we copied data.
    return true;
  }
예제 #2
0
파일: matlab.hpp 프로젝트: athuls/gsra
  void matlab::read_cast_matrix(mxArray *var, idx<T> &m) {
#ifdef __MATLAB__
    // allocate a temporary matrix with same type as original matrix type
    idx<Tmatlab> tmp(m.get_idxdim());
    // load data
    void *data = mxGetData(var);
    // copy to idx 
    memcpy(m.idx_ptr(), (Tmatlab*) data, m.nelements() * sizeof (Tmatlab));
    // copy-cast
    idx_copy(tmp, m);
#endif
  }
예제 #3
0
bool detection_thread<T>::set_data(idx<ubyte> &frame2,
                                   std::string &fullname,
                                   std::string &name, uint id) {
  // lock data (non blocking)
  if (!mutex_in.trylock())
    return false;
  // check frame is correctly allocated, if not, allocate.
  if (frame2.order() != uframe.order())
    uframe = idx<ubyte>(frame2.get_idxdim());
  else if (frame2.get_idxdim() != uframe.get_idxdim())
    uframe.resize(frame2.get_idxdim());
  idx_copy(frame2, uframe);	// copy frame
  frame_loaded = true;        // frame is loaded
  frame_fullname = fullname;
  frame_name = name;		// copy name
  frame_id   = id;		// copy frame_id
  in_updated = true;		// reset updated flag
  bavailable = false;		// declare thread as not available
  bfed       = true;		// data has been fed at least once
  mutex_in.unlock();		// unlock data
  return true;		// confirm that we copied data.
}
예제 #4
0
파일: padder.hpp 프로젝트: 2php/eblearn
 void padder<T>::pad(idx<T> &in, idx<T> &out) {
   // allocate padded buffer
   idxdim d = in;
   d.setdim(1, d.dim(1) + nrow + nrow2);
   d.setdim(2, d.dim(2) + ncol + ncol2);
   if (out.get_idxdim() != d)
     out.resize(d);
   idx_clear(out);
   // copy in to padded buffer
   idx<T> tmp = out.narrow(1, in.dim(1), nrow);
   tmp = tmp.narrow(2, in.dim(2), ncol);
   idx_copy(in, tmp);
   if (bmirror)
     mirror(in, out);
 }
예제 #5
0
bool detection_thread<T>::get_data(bboxes &bboxes2, idx<ubyte> &frame2,
                                   uint &total_saved_, std::string &frame_name_,
                                   uint *id, svector<midx<T> > *samples,
                                   bboxes *bbsamples, bool *skipped) {
  // lock data
  mutex_out.lock();
  // only read data if it has been updated
  if (!out_updated) {
    // unlock data
    mutex_out.unlock();
    return false;
  }
  // data is updated, but just to tell we skipped the frame
  if (frame_skipped) {
    if (skipped) *skipped = true;
    frame_skipped = false;
    // reset updated flag
    out_updated = false;
    // declare thread as available
    bavailable = true;
    // unlock data
    mutex_out.unlock();
    return false;
  }
  if (skipped) *skipped = false;
  // clear bboxes
  bboxes2.clear();
  bboxes2.push_back_new(bbs);
  bbs.clear(); // no use for local bounding boxes anymore, clear them
  // check frame is correctly allocated, if not, allocate.
  if (frame2.order() != uframe.order())
    frame2 = idx<ubyte>(uframe.get_idxdim());
  else if (frame2.get_idxdim() != uframe.get_idxdim())
    frame2.resize(uframe.get_idxdim());
  // copy frame
  idx_copy(uframe, frame2);
  // set total of boxes saved
  total_saved_ = total_saved;
  // set frame name
  frame_name_ = frame_name;
  // set frame id
  if (id) *id = frame_id;
  // overwrite samples
  if (samples) {
    samples->clear();
    samples->push_back_new(returned_samples);
    returned_samples.clear();
  }
  if (bbsamples) {
    bbsamples->clear();
    bbsamples->push_back_new(returned_samples_bboxes);
    returned_samples_bboxes.clear();
  }
  // reset updated flag
  out_updated = false;
  // declare thread as available
  bavailable = true;
  // unlock data
  mutex_out.unlock();
  // confirm that we copied data.
  return true;
}
예제 #6
0
파일: idxIO.hpp 프로젝트: athuls/gsra
 void read_cast_matrix(FILE *fp, idx<T2> &out) {
   idx<T> m(out.get_idxdim());
   read_matrix_body(fp, m);
   idx_copy(m, out);
 }
예제 #7
0
void class_answer<T, Tds1, Tds2>::fprop1(idx<T> &in, idx<T> &out)
{
    // resize out if necessary
    idxdim d(in);

    d.setdim(0, 2); // 2 outputs per pixel: class,confidence
    idx<T> outx = out;
    idx<T> inx = in;
    if (resize_output)
    {
        if (d != out.get_idxdim())
        {
            out.resize(d);
            outx = out;
        }
    }
    else   // if not resizing, narrow to the number of targets
    {
        if (outx.dim(0) != targets.dim(0))
            outx = outx.narrow(0, targets.dim(0), 0);
    }
    // apply tanh if required
    if (apply_tanh)
    {
        mtanh.fprop1(in, tmp);
        inx = tmp;
    }
    // loop on features (dimension 0) to set class and confidence
    int classid;
    T conf, max2 = 0;
    idx_1loop2(ii, inx, T, oo, outx, T, {
                   if (binary_target)
                   {
                       T t0 = targets.gget(0);
                       T t1 = targets.gget(1);
                       T a = ii.gget();
                       if (std::fabs((double)a - t0) < std::fabs((double)a - t1))
                       {
                           oo.set((T)0, 0); // class 0
                           oo.set((T)(2 - std::fabs((double)a - t0)) / 2, 1); // conf
                       }
                       else
                       {
                           oo.set((T)1, 0); // class 1
                           oo.set((T)(2 - std::fabs((double)a - t1)) / 2, 1); // conf
                       }
                   }
                   else if (single_output >= 0)
                   {
                       oo.set((T)single_output, 0); // all answers are the same class
                       oo.set((T)((ii.get(single_output) - target_min) / target_range), 1);
                   }
                   else // 1-of-n target
                   { // set class answer
                       if (force_class >= 0) classid = force_class;
                       else classid = idx_indexmax(ii);
                       oo.set((T)classid, 0);
                       // set confidence
                       intg p;
                       bool ini = false;
                       switch (conf_type)
                       {
                       case confidence_sqrdist: // squared distance to target
                           target = targets.select(0, classid);
                           conf = (T)(1.0 - ((idx_sqrdist(target, ii) - conf_shift)
                                             / conf_ratio));
                           oo.set(conf, 1);
                           break;
                       case confidence_single: // simply return class' out (normalized)
                           conf = (T)((ii.get(classid) - conf_shift) / conf_ratio);
                           oo.set(conf, 1);
                           break;
                       case confidence_max: // distance with 2nd max answer
                           conf = std::max(target_min, std::min(target_max, ii.get(classid)));
                           for (p = 0; p < ii.dim(0); ++p)
                           {
                               if (p != classid)
                               {
                                   if (!ini)
                                   {
                                       max2 = ii.get(p);
                                       ini = true;
                                   }
                                   else
                                   {
                                       if (ii.get(p) > max2)
                                           max2 = ii.get(p);
                                   }
                               }
                           }

                           max2 = std::max(target_min, std::min(target_max, max2));
                           oo.set((T)(((conf - max2) - conf_shift) / conf_ratio), 1);
                           break;
                       default:
                           eblerror("confidence type " << conf_type << " undefined");
                       }
                   }
               });