RFBoVCodebook.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifdef NICE_USELIB_OPENMP
  2. #include <omp.h>
  3. #endif
  4. #include "vislearning/features/regionfeatures/RFBoVCodebook.h"
  5. #include <iostream>
  6. #include "core/basics/Timer.h"
  7. using namespace OBJREC;
  8. using namespace std;
  9. using namespace NICE;
  10. RFBoVCodebook::RFBoVCodebook( const Config *_conf, LocalFeature *_lf ):RFBoV(_conf, _lf)
  11. {
  12. cb = NULL;
  13. }
  14. void RFBoVCodebook::setCodebook(Codebook *_cb){
  15. cb = _cb;
  16. }
  17. void RFBoVCodebook::convert(const Matrix &mask, const RegionGraph &rg, VVector &infeats, VVector &outfeats, VVector &positions)
  18. {
  19. int fsize = conf->gI("BoVMoosmann", "codebooksize", 1024);
  20. for(int i = 0; i < (int)rg.size(); i++)
  21. {
  22. Vector v(fsize);
  23. v.set(0.0);
  24. outfeats.push_back(v);
  25. }
  26. vector<double> counter(rg.size(), 0.0);
  27. #pragma omp parallel for
  28. for(int i = 0; i < (int)infeats.size(); i++)
  29. {
  30. SparseVector probs;
  31. cb->vote(infeats[i], probs);
  32. int r = mask(positions[i][0], positions[i][1]);
  33. #pragma omp critical
  34. {
  35. for(int j = 0; j < fsize; j++)
  36. {
  37. double val = probs.get(j);
  38. outfeats[r][j] += val;
  39. counter[r] += val;
  40. }
  41. }
  42. }
  43. for(int i = 0; i < (int)rg.size(); i++)
  44. {
  45. outfeats[i] /= counter[i];
  46. }
  47. }
  48. RFBoVCodebook::~RFBoVCodebook()
  49. {
  50. }