예제 #1
0
int RankClassifier::Classify( const QImage& label, float *outScore ) const {
  assert( label.width() == RC_LABEL_WIDTH );
  assert( label.height() == RC_LABEL_HEIGHT );

  MLP::Vector input = BinarizeImageSV( label, RC_BINARIZE_MAX_SATURATION, RC_BINARIZE_MIN_VALUE );

  MLP::Vector result = mMLP.Compute( input );
  std::vector< std::pair<int, float> > scores;
  for( int i = 0; i < (int)result.size(); i++ ) {
    scores.push_back( std::pair< int, float >( i, result[ i ] ) );
  }

  std::sort( scores.begin(), scores.end(), []( const std::pair< int, float>& p1, const std::pair< int, float>& p2 ) {
    return p1.second > p2.second;
  });

  for( int i = 0; i < (int)scores.size(); i++ ) {
    DBG( "Rank %d = %f", scores[i].first + 1, scores[i].second );
  }

  float bestScore = scores.front().second;
  if( outScore )
    *outScore = bestScore;

  int rank = 0; // RANK_UNKNOWN
  if( bestScore >= RC_PROBA_THRESHOLD ) {
    rank = scores.front().first + 1;
  }

  DBG( "Best score %.3f >= %.3f. Return %d", bestScore, RC_PROBA_THRESHOLD, rank );
  return rank;
}
예제 #2
0
int RankClassifier::Classify( const QImage& label, float *outScore ) const {
  assert( label.width() == RC_LABEL_WIDTH );
  assert( label.height() == RC_LABEL_HEIGHT );

  MLP::Vector input = BinarizeImageSV( label, RC_BINARIZE_MAX_SATURATION, RC_BINARIZE_MIN_VALUE );

  MLP::Vector result = mMLP.Compute( input );
  std::vector< std::pair<int, float> > scores;
  for( int i = 0; i < (int)result.size(); i++ ) {
    scores.push_back( std::pair< int, float >( i, result[ i ] ) );
  }

  std::sort( scores.begin(), scores.end(), []( const std::pair< int, float>& p1, const std::pair< int, float>& p2 ) {
    return p1.second > p2.second;
  });

  for( int i = 0; i < (int)scores.size(); i++ ) {
    DBG( "Rank %d = %f", scores[i].first + 1, scores[i].second );
  }

  if( outScore )
    *outScore = scores.front().second;

  return scores.front().first + 1;
}