Commit 4f8a2319206c0f9f788143da755efa07f9b5f974

Authored by Scott Klum
1 parent 091df77e

Added MTurkTransform for converting from maps to values

openbr/plugins/svm.cpp
... ... @@ -136,12 +136,12 @@ private:
136 136 Mat data = OpenCVUtils::toMat(_data.data());
137 137 Mat lab;
138 138 // If we are doing regression, the input variable should have float
139   - // values
  139 + // values
140 140 if (type == EPS_SVR || type == NU_SVR) {
141 141 lab = OpenCVUtils::toMat(File::get<float>(_data, inputVariable));
142 142 }
143 143 // If we are doing classification, we should be dealing with discrete
144   - // values. Map them and store the mapping data
  144 + // values. Map them and store the mapping data
145 145 else {
146 146 QList<int> dataLabels = _data.indexProperty(inputVariable, labelMap, reverseLookup);
147 147 lab = OpenCVUtils::toMat(dataLabels);
... ...
openbr/plugins/template.cpp
... ... @@ -42,8 +42,8 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform
42 42 void project(const Template &src, Template &dst) const
43 43 {
44 44 const QRegularExpression re(regexp);
45   - const QRegularExpressionMatch match = re.match(key.isEmpty() ? src.file.suffix() : src.file.get<QString>(key));
46   - if (match.hasMatch()) dst = Template();
  45 + const QRegularExpressionMatch match = re.match(key.isEmpty() ? src.file.baseName() : src.file.get<QString>(key));
  46 + if (!match.hasMatch()) dst = Template();
47 47 else dst = src;
48 48 }
49 49 };
... ... @@ -95,19 +95,34 @@ BR_REGISTER(Transform, SelectPointsTransform)
95 95  
96 96 /*!
97 97 * \ingroup transforms
98   - * \brief Does nothing.
  98 + * \brief Converts Amazon MTurk labels
  99 + * \author Scott Klum \cite sklum
99 100 */
100   -class NoneTransform : public UntrainableMetaTransform
  101 +class MTurkTransform : public UntrainableTransform
101 102 {
102 103 Q_OBJECT
  104 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
  105 + Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false)
  106 + BR_PROPERTY(QString, inputVariable, QString())
  107 + BR_PROPERTY(float, maxVotes, 1.)
103 108  
104 109 void project(const Template &src, Template &dst) const
105 110 {
106 111 dst = src;
  112 +
  113 + QMap<QString,QVariant> map = dst.file.get<QMap<QString,QVariant> >(inputVariable);
  114 +
  115 + bool ok;
  116 +
  117 + QMapIterator<QString, QVariant> i(map);
  118 + while (i.hasNext()) {
  119 + i.next();
  120 + dst.file.set(i.key(), i.value().toFloat(&ok)/maxVotes);
  121 + }
107 122 }
108 123 };
109 124  
110   -BR_REGISTER(Transform, NoneTransform)
  125 +BR_REGISTER(Transform, MTurkTransform)
111 126  
112 127 } // namespace br
113 128  
... ...