Commit ed2a8f7b758fc97e71c31d15afa15db2d03d8a66
1 parent
bd31789d
remove majorityvoting
Showing
1 changed file
with
0 additions
and
104 deletions
openbr/plugins/metadata/majorityvoting.cpp deleted
| 1 | - | |
| 2 | -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 3 | - * Copyright 2015 Rank One Computing Corporation * | |
| 4 | - * * | |
| 5 | - * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 6 | - * you may not use this file except in compliance with the License. * | |
| 7 | - * You may obtain a copy of the License at * | |
| 8 | - * * | |
| 9 | - * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 10 | - * * | |
| 11 | - * Unless required by applicable law or agreed to in writing, software * | |
| 12 | - * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 14 | - * See the License for the specific language governing permissions and * | |
| 15 | - * limitations under the License. * | |
| 16 | - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 17 | - | |
| 18 | -#include <openbr/plugins/openbr_internal.h> | |
| 19 | - | |
| 20 | -namespace br | |
| 21 | -{ | |
| 22 | - | |
| 23 | -/*! | |
| 24 | - * \ingroup transforms | |
| 25 | - * \brief Performs majority voting from a single metadata key or multiple keys and sets the result in the specified key. | |
| 26 | - * \br_property QString keys The meta-data key(s) used for Majority Voting. | |
| 27 | - * \br_property int numClasses The number of possible classes. | |
| 28 | - * \br_property QString outputKey The output metadata key which stores the a list with the index of the winning class set to 1. | |
| 29 | - * \br_property float thresh Allows users to specify a threshold for the first class, if exceeded the first class wins else class 2 wins. | |
| 30 | - * \author Keyur Patel \cite kpatel | |
| 31 | - */ | |
| 32 | -class MajorityVotingTransform : public UntrainableMetadataTransform | |
| 33 | -{ | |
| 34 | - Q_OBJECT | |
| 35 | - Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) | |
| 36 | - Q_PROPERTY(int numClasses READ get_numClasses WRITE set_numClasses RESET reset_numClasses STORED false) | |
| 37 | - Q_PROPERTY(QString outputKey READ get_outputKey WRITE set_outputKey RESET reset_outputKey STORED false) | |
| 38 | - Q_PROPERTY(float thresh READ get_thresh WRITE set_thresh RESET reset_thresh STORED false) | |
| 39 | - | |
| 40 | - BR_PROPERTY(QStringList, keys, QStringList()) | |
| 41 | - BR_PROPERTY(int, numClasses, 2) | |
| 42 | - BR_PROPERTY(QString, outputKey, "MajorityVoting") | |
| 43 | - BR_PROPERTY(float, thresh, -1) | |
| 44 | - | |
| 45 | - void projectMetadata(const File &src, File &dst) const | |
| 46 | - { | |
| 47 | - dst = src; | |
| 48 | - | |
| 49 | - QList<float> scores = QList<float>(); | |
| 50 | - foreach (QString key, keys){ | |
| 51 | - if (src.contains(key)){ | |
| 52 | - QList<float> templateScores = src.getList<float>(key); | |
| 53 | - scores.append(templateScores); | |
| 54 | - } else { | |
| 55 | - dst.fte = true; | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - } | |
| 59 | - QVector<int> classCount(numClasses, 0); | |
| 60 | - for (int c = 0; c < scores.size(); c+= numClasses){ | |
| 61 | - if ((numClasses == 2) && (thresh != -1)){ | |
| 62 | - if (scores[c] > thresh) | |
| 63 | - classCount[0]++; | |
| 64 | - else | |
| 65 | - classCount[1]++; | |
| 66 | - } else { | |
| 67 | - int highestScoringClass = 0; | |
| 68 | - float highestScore = scores[c]; | |
| 69 | - for (int b = 1; b < numClasses; b++){ | |
| 70 | - if (scores[c+b] > highestScore){ | |
| 71 | - highestScore = scores[c+b]; | |
| 72 | - highestScoringClass = b; | |
| 73 | - } | |
| 74 | - } | |
| 75 | - classCount[highestScoringClass]++; | |
| 76 | - } | |
| 77 | - } | |
| 78 | - int largestIndex = getIndexOfLargestElement(classCount); | |
| 79 | - | |
| 80 | - QList<int> output = QList<int>(); | |
| 81 | - for(int i=0; i <numClasses; i++){ | |
| 82 | - if(i == largestIndex) output.append(1); | |
| 83 | - else output.append(0); | |
| 84 | - } | |
| 85 | - dst.setList(outputKey,output); | |
| 86 | - } | |
| 87 | - | |
| 88 | - int getIndexOfLargestElement(const QVector<int> &arr) const { | |
| 89 | - int largestIndex = 0; | |
| 90 | - for (int i = largestIndex; i < arr.size(); i++) { | |
| 91 | - if (arr[largestIndex] <= arr[i]) { | |
| 92 | - largestIndex = i; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - return largestIndex; | |
| 96 | - } | |
| 97 | -}; | |
| 98 | - | |
| 99 | -BR_REGISTER(Transform, MajorityVotingTransform) | |
| 100 | - | |
| 101 | -} // namespace br | |
| 102 | - | |
| 103 | -#include "metadata/majorityvoting.moc" | |
| 104 | - |