简体   繁体   English

Bag Of Words的标签数据

[英]Labeling data for Bag Of Words

I've been looking at this tutorial and the labeling part confuses me. 我一直在看这个教程 ,标签部分让我很困惑。 Not the act of labeling itself, but the way the process is shown in the tutorial. 不是标记自身的行为,而是教程中显示过程的方式。

More specifically the #pragma omp sections: 更具体地说, #pragma omp部分:

#pragma omp parallel for schedule(dynamic,3)
for(..loop a directory?..) {

   ...

   #pragma omp critical
   {
      if(classes_training_data.count(class_) == 0) { //not yet created...
         classes_training_data[class_].create(0,response_hist.cols,response_hist.type());
         classes_names.push_back(class_);
      }
      classes_training_data[class_].push_back(response_hist);
   }
   total_samples++;
}

As well as the following code below it. 以及下面的代码如下。

Could anyone explain what is going on here? 谁能解释一下这里发生了什么?

The pragmas are from OpenMP , a specification for a set of compiler directives, library routines, and environment variables that can be used to specify high-level parallelism in Fortran and C/C++ programs. 这些编译指示来自OpenMP ,它是一组编译器指令,库例程和环境变量规范,可用于在Fortran和C / C ++程序中指定高级并行性。

The #pragma omp parallel for schedule(dynamic,3) is a shorthand that combines several other pragmas. #pragma omp parallel for schedule(dynamic,3)是一个结合了其他几个pragma的简写。 Let's see them: 我们来看看他们:

#pragma omp parallel starts a parellel block with a set of threads that will execute the next stament in parallel. #pragma omp parallel启动一个带有一组线程的parellel块,这些线程将并行执行下一个stament。

You can also specify "parallel loops", like a for loop : #pragma omp parallel for . 您还可以指定“并行循环”,如for loop#pragma omp parallel for This pragma will split the for-loop between all the threads inside the parallel block and each thread will execute its portion of the loop. 该pragma将拆分并行块内所有线程之间的for循环,每个线程将执行其循环部分。

For example: 例如:

 #pragma omp parallel
 {
  #pragma omp for
  for(int n(0); n < 5; ++n) {
     std::cout << "Hello\n";
 }

This will create a parallel block that will execute a for-loop. 这将创建一个执行for循环的并行块。 The threads will print to the standard output Hello five times, in no specified order (I mean, thread #3 can print its "Hello" before thread #1 and so.). 线程将打印到标准输出Hello五次,没有指定的顺序(我的意思是,线程#3可以在线程#1之前打印它的“Hello”等等。)。

Now, you can also schedule which chunk of work will each thread receive. 现在,您还可以安排每个线程接收的工作块。 There are several policies: static (the default) and dynamic . 有几个策略: static (默认)和dynamic Check this awesome answer in regards to scheduling policies . 检查有关调度策略的这个很棒的答案

Now, all of this pragmas can be shortened to one: 现在,所有这些pragma都可以缩短为一个:

#pragma omp parallel for schedule(dynamic,3)

which will create a parallel block that will execute a for-loop, with dynamic scheduling and each thread in the block will execute 3 iterations of the loop before asking the scheduler for more chunks. 这将创建一个将执行for循环的并行块,使用动态调度,并且块中的每个线程将在向调度程序请求更多块之前执行循环的3次迭代。

The critical pragma will restrict the execution of the next block to a single thread at time. critical编译指示会将下一个块的执行限制为单个线程。 In your example, only one thread at a time will execute this: 在您的示例中,一次只有一个线程将执行此操作:

   {
      if(classes_training_data.count(class_) == 0) { //not yet created...
         classes_training_data[class_].create(0,response_hist.cols,response_hist.type());
         classes_names.push_back(class_);
      }
      classes_training_data[class_].push_back(response_hist);
   }

Here you have an introduction to OpenMP 3.0 . 在这里,您将了解OpenMP 3.0

Finally, the variables you mention are specified in the tutorial, just look before your posted code: 最后,您提到的变量在教程中指定,只需查看您发布的代码:

vector<KeyPoint> keypoints;
Mat response_hist;
Mat img;
string filepath;
map<string,Mat> classes_training_data;

Ptr<FeatureDetector > detector(new SurfFeatureDetector());
Ptr<DescriptorMatcher > matcher(new BruteForceMatcher<L2<float> >());
Ptr<DescriptorExtractor > extractor(new OpponentColorDescriptorExtractor(Ptr<DescriptorExtractor>(new SurfDescriptorExtractor())));
Ptr<BOWImgDescriptorExtractor> bowide(new BOWImgDescriptorExtractor(extractor,matcher));
bowide->setVocabulary(vocabulary);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM