Exemple #1
0
int
main (int argc, char **argv)
{
    if (argc < 2)
        usage ();

    if (!strcmp (argv[1], "testpat"))
        make_testpat ();
    else if (!strcmp (argv[1], "gradient"))
        test_gradient ();
    else if (!strcmp (argv[1], "dist"))
        test_dist ();
    else if (!strcmp (argv[1], "dash"))
        test_dash ();
    else if (!strcmp (argv[1], "intersect"))
        test_intersect ();
    else if (!strcmp (argv[1], "intersect1"))
        test_intersection();
    else
        usage ();
    return 0;
}
inline
float
cv_dist_vector_GrassBC::test(int ts_scale, int ts_shift)
{
  
  int n_actions = actions.n_rows;
  int k = 0;
  
  field <std::string> action_seq_names (150,3);  ///From the dataset description (150)
  
  
  for (int act=0; act<n_actions; ++act)
  {
    std::stringstream  ss_folders;
    ss_folders << path_dataset << actions (act) << "/list_folders.txt";
    field <std::string> list_folders;
    list_folders.load( ss_folders.str() );
    int n_folders = list_folders.n_rows;
    //cout <<  actions (act) << endl;
    //list_folders.print();
    for (int i=0; i< n_folders; ++i)
    {
      
      std::ostringstream ss_action;
      ss_action << act;
      action_seq_names(k,0) = actions(act); //Action
      action_seq_names(k,1) = list_folders(i); //Video Sequence
      action_seq_names(k,2) = ss_action.str();; //Action index
      k++;
    }
  }
  
  
  int n_test = 150 - 1;  //Problem with Run-Side_001_dim14 
  int n_dim = n_test -1;
  fvec dist_vector;
  
  float acc=0;
  vec real_labels;
  vec est_labels;
  field<std::string> test_video_list(n_test);
  
  
  real_labels.zeros(n_test);
  est_labels.zeros(n_test);
  
  int j =0;
  
  std::stringstream load_sub_path;
  load_sub_path  << path << "dim_" << dim << "/grass_points/one-grass-point/scale" << ts_scale << "-shift"<< ts_shift ;
  
  
  
  
  for (int test_i = 0; test_i< action_seq_names.n_rows; ++test_i)
  {
    
    std::string action_name = action_seq_names(test_i,0);   
    std::string folder_n    = action_seq_names(test_i,1);
    int act_ts  = atoi( action_seq_names(test_i,2).c_str() );
    
    if (!(action_name=="Run-Side" && folder_n=="001"))
    {
      CvSVM SVM;
      std::stringstream load_svm_model;
      load_svm_model << "./svm_models/GrassBC_run_" << test_i+1;
      SVM.load( load_svm_model.str().c_str() );
      
      vec test_dist;
      
      std::stringstream load_Gnp;
      load_Gnp << load_sub_path.str() << "/grass_pt_" << action_name << "_" <<  folder_n << "_dim" << dim << "_p" << p << ".h5";
     
      
      test_dist = dist_one_video( action_seq_names, test_i, load_sub_path.str(), load_Gnp.str() );
      
      //test_dist.print("");
      
      cv::Mat cvMatTesting_onevideo(1, n_dim, CV_32FC1);
      
      for (uword d=0; d<n_dim; ++d)
      {
	cvMatTesting_onevideo.at<float>(0,d) = test_dist(d); 
	
      }
      
      float response = SVM.predict(cvMatTesting_onevideo, true);
      
      std::stringstream test_video_name;
      test_video_name << action_name << "_" <<  folder_n ;
      
      
      //cout << "response " << response << endl;
      real_labels(j) = act_ts;
      est_labels(j) = response;
      test_video_list(j) = test_video_name.str();
      j++;
      
      //cout << act_ts << " " << response << endl;
      if (response == act_ts)  {
	acc++;
      }
      
      std::stringstream main_save;
      main_save << "./svm_results/GrassBC_scale" <<  ts_scale << "-shift"<< ts_shift << "-p" << p;
      
      
      std::stringstream save1, save2,save3;
      
      save1 << main_save.str() << "_real_labels.dat";
      save2 << main_save.str() << "_est_labels.dat";
      save3 << main_save.str() << "_test_video_list.dat";
      
      real_labels.save(save1.str(), raw_ascii);
      est_labels.save( save2.str(), raw_ascii);
      test_video_list.save(save3.str(), raw_ascii); 
      
    }
    
  }
  acc = acc*100/(n_test);
  cout << "Performance for Grassmann Binet-Cauchy Metric: " <<  acc << " %" << endl;
  
  return acc;
}