Commit 9c6f437d7de200d1abc6d82ee5e0a306a3dc1f0c

Authored by KeyurPatel
1 parent d37ecaa4

eval.cpp Fixed bug in print statements and added check to ensure the keys exist …

…in the templates metadata
roi.cpp copyOnCrop=True is now the default
rotate.cpp rotates a mat by 90 intervals
extractvaluefromLlist.cpp extracts a single value from a list in metadata and saves it in a new key
majorityvoting.cpp Calculates which class has the highest scores when given a list of scores for each class
scorelevelfusion.cpp Fuses the scores together for each class when given a list of scores for each class
openbr/core/eval.cpp
... ... @@ -1179,6 +1179,8 @@ void EvalEER(const QString &predictedXML, QString gt_property, QString distribut
1179 1179 QHash<QString, int> gtLabels;
1180 1180 QHash<QString, QList<float> > scores;
1181 1181 for (int i=0; i<templateList.size(); i++) {
  1182 + if (!templateList[i].file.contains(distribution_property) || !templateList[i].file.contains(gt_property))
  1183 + continue;
1182 1184 QString templateKey = templateList[i].file.path() + templateList[i].file.baseName();
1183 1185 int gtLabel = templateList[i].file.get<int>(gt_property);
1184 1186 if (gtLabel == 1)
... ... @@ -1225,10 +1227,9 @@ void EvalEER(const QString &amp;predictedXML, QString gt_property, QString distribut
1225 1227 thres += stepSize;
1226 1228 }
1227 1229  
1228   - qDebug() <<"Class 0 Templates:" << classOneTemplateCount << "Class 1 Templates:"
1229   - << numTemplates - classOneTemplateCount << "Total Templates:" << numTemplates;
  1230 + qDebug() <<"Class 0 Templates:" << numTemplates - classOneTemplateCount << "Class 1 Templates:"
  1231 + << classOneTemplateCount << "Total Templates:" << numTemplates;
1230 1232 qDebug("EER: %.3f @ Threshold %.3f", EER*100, EERThres);
1231   -
1232 1233 }
1233 1234  
1234 1235  
... ...
openbr/plugins/classification/caffe.cpp
... ... @@ -2,7 +2,7 @@
2 2 #include <openbr/core/opencvutils.h>
3 3  
4 4 #include <caffe/caffe.hpp>
5   -#include <caffe/layers/memory_data_layer.hpp>
  5 +//#include <caffe/layers/memory_data_layer.hpp>
6 6  
7 7 using caffe::Caffe;
8 8 using caffe::Net;
... ...
openbr/plugins/imgproc/roi.cpp
... ... @@ -36,7 +36,7 @@ class ROITransform : public UntrainableTransform
36 36 Q_PROPERTY(bool copyOnCrop READ get_copyOnCrop WRITE set_copyOnCrop RESET reset_copyOnCrop STORED false)
37 37 Q_PROPERTY(int shiftPoints READ get_shiftPoints WRITE set_shiftPoints RESET reset_shiftPoints STORED false)
38 38 BR_PROPERTY(QString, propName, "")
39   - BR_PROPERTY(bool, copyOnCrop, false)
  39 + BR_PROPERTY(bool, copyOnCrop, true)
40 40 BR_PROPERTY(int, shiftPoints, -1)
41 41  
42 42 void project(const Template &src, Template &dst) const
... ...
openbr/plugins/imgproc/rotate.cpp 0 → 100644
  1 +#include <opencv2/imgproc/imgproc.hpp>
  2 +#include <openbr/plugins/openbr_internal.h>
  3 +
  4 +using namespace cv;
  5 +
  6 +namespace br
  7 +{
  8 +
  9 +/*!
  10 + * \ingroup transforms
  11 + * \brief Rotates an image in 90 degree intervals.
  12 + * \author Keyur Patel \cite patel
  13 + */
  14 +class RotateTransform : public UntrainableTransform
  15 +{
  16 + Q_OBJECT
  17 +
  18 + Q_PROPERTY(int angle READ get_angle WRITE set_angle RESET reset_angle STORED false)
  19 + BR_PROPERTY(int, angle, -90)
  20 +
  21 + void project(const Template &src, Template &dst) const {
  22 +
  23 + if(angle == 270 || angle == -90){
  24 + // Rotate clockwise 270 degrees
  25 + cv::transpose(src, dst);
  26 + cv::flip(dst, dst, 0);
  27 + }else if(angle == 180 || angle == -180){
  28 + // Rotate clockwise 180 degrees
  29 + cv::flip(src, dst, -1);
  30 + }else if(angle == 90 || angle == -270){
  31 + // Rotate clockwise 90 degrees
  32 + cv::transpose(src, dst);
  33 + cv::flip(dst, dst, 1);
  34 + }else {
  35 + dst = src;
  36 + }
  37 + }
  38 +};
  39 +
  40 +BR_REGISTER(Transform, RotateTransform)
  41 +
  42 +} // namespace br
  43 +
  44 +#include "imgproc/rotate.moc"
  45 +
... ...
openbr/plugins/metadata/extractvaluefromlist.cpp 0 → 100644
  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 Extracts a single value from a list and sets the specified key to that value.
  26 + * \br_property QString key The meta-data key that contains a list of values
  27 + * \br_property int index The index of the value of interest (0 offset)
  28 + * \br_property QString outputKey The output metadata key which stores the value of interest
  29 + * \author Keyur Patel \cite kpatel
  30 + */
  31 +class ExtractValueFromListTransform : public UntrainableMetadataTransform
  32 +{
  33 + Q_OBJECT
  34 + Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false)
  35 + Q_PROPERTY(int index READ get_index WRITE set_index RESET reset_index STORED false)
  36 + Q_PROPERTY(QString outputKey READ get_outputKey WRITE set_outputKey RESET reset_outputKey STORED false)
  37 +
  38 + BR_PROPERTY(QString, key, "")
  39 + BR_PROPERTY(int, index, 0)
  40 + BR_PROPERTY(QString, outputKey, "ExtractedValue")
  41 +
  42 + void projectMetadata(const File &src, File &dst) const
  43 + {
  44 + dst = src;
  45 +
  46 + if (src.contains(key)){
  47 + QList<float> values = src.getList<float>(key);
  48 + if (values.size() -1 >= index && index >= 0)
  49 + dst.set(outputKey,values[index]);
  50 + }
  51 + }
  52 +
  53 +};
  54 +
  55 +BR_REGISTER(Transform, ExtractValueFromListTransform)
  56 +
  57 +} // namespace br
  58 +
  59 +#include "metadata/extractvaluefromlist.moc"
  60 +
... ...
openbr/plugins/metadata/majorityvoting.cpp 0 → 100644
  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(QList<QString> 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(QList<QString>, keys, QList<QString>())
  41 + BR_PROPERTY(int, numClasses, 2)
  42 + BR_PROPERTY(QString, outputKey, "MajorityVoting")
  43 + BR_PROPERTY(float, thresh, -1)
  44 +
  45 +
  46 + void projectMetadata(const File &src, File &dst) const
  47 + {
  48 + dst = src;
  49 +
  50 + QList<float> scores = QList<float>();
  51 + foreach (QString key, keys){
  52 + if (src.contains(key)){
  53 + QList<float> templateScores = src.getList<float>(key);
  54 + scores.append(templateScores);
  55 + } else {
  56 + dst.fte = true;
  57 + return;
  58 + }
  59 + }
  60 + int classCount[numClasses]; //= {0};
  61 + for (int i = 0; i < numClasses; i++){
  62 + classCount[i] = 0;
  63 + }
  64 + for (int c = 0; c < scores.size(); c+= numClasses){
  65 + if(numClasses == 2 and thresh != -1){
  66 + if (scores[c] > thresh)
  67 + classCount[0]++;
  68 + else
  69 + classCount[1]++;
  70 + } else {
  71 + int highestScoringClass = 0;
  72 + float highestScore = scores[c];
  73 + for (int b = 1; b < numClasses; b++){
  74 + if (scores[c+b] > highestScore){
  75 + highestScore = scores[c+b];
  76 + highestScoringClass = b;
  77 + }
  78 + }
  79 + classCount[highestScoringClass]++;
  80 + }
  81 + }
  82 + int largestIndex = getIndexOfLargestElement(classCount,numClasses);
  83 +
  84 + QList<int> output = QList<int>();
  85 + for(int i=0; i <numClasses; i++){
  86 + if(i == largestIndex) output.append(1);
  87 + else output.append(0);
  88 + }
  89 + dst.setList(outputKey,output);
  90 + }
  91 +
  92 + int getIndexOfLargestElement(int arr[], int numClasses) const {
  93 + int largestIndex = 0;
  94 + for (int i = largestIndex; i < numClasses; i++) {
  95 + if (arr[largestIndex] <= arr[i]) {
  96 + largestIndex = i;
  97 + }
  98 + }
  99 + return largestIndex;
  100 + }
  101 +
  102 +};
  103 +
  104 +BR_REGISTER(Transform, MajorityVotingTransform)
  105 +
  106 +} // namespace br
  107 +
  108 +#include "metadata/majorityvoting.moc"
  109 +
... ...
openbr/plugins/metadata/scorelevelfusion.cpp 0 → 100644
  1 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2 + * Copyright 2015 Rank One Computing Corporation *
  3 + * *
  4 + * Licensed under the Apache License, Version 2.0 (the "License"); *
  5 + * you may not use this file except in compliance with the License. *
  6 + * You may obtain a copy of the License at *
  7 + * *
  8 + * http://www.apache.org/licenses/LICENSE-2.0 *
  9 + * *
  10 + * Unless required by applicable law or agreed to in writing, software *
  11 + * distributed under the License is distributed on an "AS IS" BASIS, *
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13 + * See the License for the specific language governing permissions and *
  14 + * limitations under the License. *
  15 + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  16 +
  17 +#include <openbr/plugins/openbr_internal.h>
  18 +#include <opencv2/core/core.hpp>
  19 +
  20 +using namespace cv;
  21 +
  22 +namespace br
  23 +{
  24 +
  25 +/*!
  26 + * \ingroup transforms
  27 + * \brief Fuses together scores from a single metadata key or multiple keys and sets the computed values in the specified key.
  28 + * \br_property QString keys The meta-data key(s) to fuse on.
  29 + * \br_property QString outputKey The output metadata key.
  30 + * \br_property bool listOfList Flag that tells the program how to parse the metadata key that contains the score values.
  31 + * \author Keyur Patel \cite kpatel
  32 + */
  33 +class ScoreLevelFusionTransform : public UntrainableMetadataTransform
  34 +{
  35 + Q_OBJECT
  36 + Q_PROPERTY(QList<QString> keys READ get_keys WRITE set_keys RESET reset_keys STORED false)
  37 + Q_PROPERTY(int numClasses READ get_numClasses WRITE set_numClasses RESET reset_numClasses STORED false)
  38 + Q_PROPERTY(QString outputKey READ get_outputKey WRITE set_outputKey RESET reset_outputKey STORED false)
  39 + Q_PROPERTY(bool listOfList READ get_listOfList WRITE set_listOfList RESET reset_listOfList STORED false)
  40 +
  41 + BR_PROPERTY(QList<QString>, keys, QList<QString>())
  42 + BR_PROPERTY(int, numClasses, 2)
  43 + BR_PROPERTY(QString, outputKey, "ScoreLevelFusion")
  44 + BR_PROPERTY(bool, listOfList, false)
  45 +
  46 + void projectMetadata(const File &src, File &dst) const
  47 + {
  48 + dst = src;
  49 + QList<QList<float> > scoresList = QList<QList<float> >();
  50 + if (listOfList){ //format [[.8,.2],[.45,.55],[.3,.7]]
  51 + foreach (QString key, keys){
  52 + if (src.contains(key)){
  53 + QList<QString > keyScoresList = src.getList<QString >(key);
  54 + for (int d = 0; d < keyScoresList.size(); d++){
  55 + QList<QString> tmpList = keyScoresList[d].split(",");
  56 + QList<float> tmpScoreList = QList<float>();
  57 + for (int f = 0; f < tmpList.size(); f++){
  58 + tmpScoreList.append(tmpList[f].remove('"').remove("]").remove("[").toFloat());
  59 + }
  60 + scoresList.append(tmpScoreList);
  61 + }
  62 + } else{
  63 + dst.fte = true;
  64 + return;
  65 + }
  66 + }
  67 + } else { //format = [.8,.2,.45,.55,.3.,7]
  68 + QList<float> scores = QList<float>();
  69 + foreach (QString key, keys){
  70 + if (src.contains(key)){
  71 + QList<float> templateScores = src.getList<float>(key);
  72 + scores.append(templateScores);
  73 + } else{
  74 + dst.fte = true;
  75 + return;
  76 + }
  77 + }
  78 + for (int i = 0; i < scores.size(); i+=numClasses){
  79 + QList<float> tmpList = QList<float>();
  80 + for (int b = 0; b < numClasses; b++){
  81 + tmpList.append(scores[i+b]);
  82 + }
  83 + scoresList.append(tmpList);
  84 + }
  85 + }
  86 + Mat m = toMat(scoresList);
  87 + Mat avgDist;
  88 + cv::reduce(m, avgDist, 0, 1);
  89 + dst.setList(outputKey,matrixToVector(avgDist));
  90 + }
  91 +
  92 + cv::Mat toMat(const QList<QList<float> > &src) const
  93 + {
  94 + cv::Mat dst(src.size(), src[0].size(), CV_32F);
  95 + for (int i=0; i<src.size(); i++)
  96 + for (int j=0; j<src[i].size(); j++)
  97 + dst.at<float>(i, j) = src[i][j];
  98 + return dst;
  99 + }
  100 +
  101 + QList<float> matrixToVector(const cv::Mat &m) const
  102 + {
  103 + QList<float> results;
  104 + for (int i=0; i<m.cols; i++)
  105 + results.append(m.at<float>(0, i));
  106 + return results;
  107 + }
  108 +
  109 +};
  110 +
  111 +BR_REGISTER(Transform, ScoreLevelFusionTransform)
  112 +
  113 +} // namespace br
  114 +
  115 +#include "metadata/scorelevelfusion.moc"
  116 +
... ...