Commit a69c9c3522288ccd699b677f09ec02051443f9d0
1 parent
2ca8d515
Attempting to squish...
PP5 building, bypassing _compare for now added backProject to Context and Transform made pixel happy fixed enroll some final changes to pittpatt added author information
Showing
7 changed files
with
148 additions
and
15 deletions
sdk/core/core.cpp
| ... | ... | @@ -133,7 +133,15 @@ struct AlgorithmCore |
| 133 | 133 | if (data.isEmpty()) break; |
| 134 | 134 | const int numFiles = data.size(); |
| 135 | 135 | |
| 136 | - data >> *transform; | |
| 136 | + if (!Globals->backProject){ | |
| 137 | + data >> *transform; | |
| 138 | + } else { | |
| 139 | + // I don't really know if this makes sense. | |
| 140 | + //TemplateList dst; | |
| 141 | + transform->backProject(data, data); | |
| 142 | + //data = dst; | |
| 143 | + } | |
| 144 | + | |
| 137 | 145 | g->writeBlock(data); |
| 138 | 146 | const FileList newFiles = data.files(); |
| 139 | 147 | fileList.append(newFiles); | ... | ... |
sdk/openbr_plugin.cpp
| ... | ... | @@ -637,6 +637,7 @@ br::Context::Context() |
| 637 | 637 | quiet = verbose = false; |
| 638 | 638 | currentStep = totalSteps = 0; |
| 639 | 639 | enrollAll = false; |
| 640 | + backProject = false; | |
| 640 | 641 | } |
| 641 | 642 | |
| 642 | 643 | int br::Context::blocks(int size) const |
| ... | ... | @@ -1080,6 +1081,8 @@ private: |
| 1080 | 1081 | } |
| 1081 | 1082 | } |
| 1082 | 1083 | |
| 1084 | + | |
| 1085 | + | |
| 1083 | 1086 | void store(QDataStream &stream) const |
| 1084 | 1087 | { |
| 1085 | 1088 | const int size = transforms.size(); |
| ... | ... | @@ -1175,6 +1178,18 @@ static void _project(const Transform *transform, const Template *src, Template * |
| 1175 | 1178 | } |
| 1176 | 1179 | } |
| 1177 | 1180 | |
| 1181 | +static void _backProject(const Transform *transform, const Template *dst, Template *src) | |
| 1182 | +{ | |
| 1183 | + try { | |
| 1184 | + transform->backProject(*dst, *src); | |
| 1185 | + } catch (...) { | |
| 1186 | + qWarning("Exception triggered when processing %s with transform %s", qPrintable(src->file.flat()), qPrintable(transform->name())); | |
| 1187 | + *src = Template(dst->file); | |
| 1188 | + src->file.setBool("FTE"); | |
| 1189 | + } | |
| 1190 | +} | |
| 1191 | + | |
| 1192 | + | |
| 1178 | 1193 | void Transform::project(const TemplateList &src, TemplateList &dst) const |
| 1179 | 1194 | { |
| 1180 | 1195 | dst.reserve(src.size()); |
| ... | ... | @@ -1188,6 +1203,24 @@ void Transform::project(const TemplateList &src, TemplateList &dst) const |
| 1188 | 1203 | if (Globals->parallelism) Globals->trackFutures(futures); |
| 1189 | 1204 | } |
| 1190 | 1205 | |
| 1206 | +void Transform::backProject(const Template &dst, Template &src) const | |
| 1207 | +{ | |
| 1208 | + src = dst; | |
| 1209 | +} | |
| 1210 | + | |
| 1211 | +void Transform::backProject(const TemplateList &dst, TemplateList &src) const | |
| 1212 | +{ | |
| 1213 | + src.reserve(dst.size()); | |
| 1214 | + for (int i=0; i<dst.size(); i++) src.append(Template()); | |
| 1215 | + | |
| 1216 | + QList< QFuture<void> > futures; | |
| 1217 | + if (Globals->parallelism) futures.reserve(dst.size()); | |
| 1218 | + for (int i=0; i<dst.size(); i++) | |
| 1219 | + if (Globals->parallelism) futures.append(QtConcurrent::run(_backProject, this, &dst[i], &src[i])); | |
| 1220 | + else _backProject (this, &dst[i], &src[i]); | |
| 1221 | + if (Globals->parallelism) Globals->trackFutures(futures); | |
| 1222 | +} | |
| 1223 | + | |
| 1191 | 1224 | /* Distance - public methods */ |
| 1192 | 1225 | void Distance::train(const TemplateList &templates) |
| 1193 | 1226 | { | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -450,6 +450,13 @@ public: |
| 450 | 450 | BR_PROPERTY(int, parallelism, 0) |
| 451 | 451 | |
| 452 | 452 | /*! |
| 453 | + * \brief true if backProject should be used instead of project (the algorithm should be inverted) | |
| 454 | + */ | |
| 455 | + Q_PROPERTY(bool backProject READ get_backProject WRITE set_backProject RESET reset_backProject) | |
| 456 | + BR_PROPERTY(bool, backProject, false) | |
| 457 | + | |
| 458 | + | |
| 459 | + /*! | |
| 453 | 460 | * \brief If \c true no messages will be sent to the terminal, \c false by default. |
| 454 | 461 | */ |
| 455 | 462 | Q_PROPERTY(bool quiet READ get_quiet WRITE set_quiet RESET reset_quiet) |
| ... | ... | @@ -919,6 +926,10 @@ public: |
| 919 | 926 | virtual void train(const TemplateList &data) = 0; /*!< \brief Train the transform. */ |
| 920 | 927 | virtual void project(const Template &src, Template &dst) const = 0; /*!< \brief Apply the transform. */ |
| 921 | 928 | virtual void project(const TemplateList &src, TemplateList &dst) const; /*!< \brief Apply the transform. */ |
| 929 | + virtual void backProject(const Template &dst, Template &src) const; /*!< \brief Invert the transform. */ | |
| 930 | + virtual void backProject(const TemplateList &dst, TemplateList &src) const; /*!< \brief Invert the transform. */ | |
| 931 | + | |
| 932 | + | |
| 922 | 933 | |
| 923 | 934 | /*! |
| 924 | 935 | * \brief Convenience function equivalent to project(). |
| ... | ... | @@ -944,6 +955,7 @@ public: |
| 944 | 955 | protected: |
| 945 | 956 | Transform(bool independent = true); /*!< \brief Construct a transform. */ |
| 946 | 957 | inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ |
| 958 | + | |
| 947 | 959 | }; |
| 948 | 960 | |
| 949 | 961 | /*! |
| ... | ... | @@ -1010,6 +1022,7 @@ private: |
| 1010 | 1022 | void load(QDataStream &stream) { (void) stream; } |
| 1011 | 1023 | }; |
| 1012 | 1024 | |
| 1025 | + | |
| 1013 | 1026 | /*! |
| 1014 | 1027 | * \brief A br::MetaTransform that does not require training data. |
| 1015 | 1028 | */ |
| ... | ... | @@ -1057,7 +1070,7 @@ private: |
| 1057 | 1070 | * \brief Returns \c true if the algorithm is a classifier, \c false otherwise. |
| 1058 | 1071 | * |
| 1059 | 1072 | * Classifers have no br::Distance associated with their br::Transform. |
| 1060 | -* Instead they populate br::Template::file \c Label metadata fielf with the predicted class. | |
| 1073 | +* Instead they populate br::Template::file \c Label metadata field with the predicted class. | |
| 1061 | 1074 | */ |
| 1062 | 1075 | BR_EXPORT bool IsClassifier(const QString &algorithm); |
| 1063 | 1076 | ... | ... |
sdk/plugins/eigen3.cpp
| ... | ... | @@ -52,6 +52,7 @@ public: |
| 52 | 52 | PCA() : keep(0.95), drop(0), whiten(false) {} |
| 53 | 53 | |
| 54 | 54 | private: |
| 55 | + /* | |
| 55 | 56 | void backProject(const Template &src, Template &dst) const |
| 56 | 57 | { |
| 57 | 58 | const cv::Mat &m = src; |
| ... | ... | @@ -64,6 +65,7 @@ private: |
| 64 | 65 | // Do projection |
| 65 | 66 | outMap = (eVecs * inMap) + mean; |
| 66 | 67 | } |
| 68 | + */ | |
| 67 | 69 | |
| 68 | 70 | double residualReconstructionError(const Template &src) const |
| 69 | 71 | { | ... | ... |
sdk/plugins/meta.cpp
| ... | ... | @@ -136,6 +136,25 @@ class PipeTransform : public MetaTransform |
| 136 | 136 | Transform::project(src, dst); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | + | |
| 140 | + void projectBack(const Template &dst, Template &src) const | |
| 141 | + { | |
| 142 | + src = dst; | |
| 143 | + //reverse order in which transforms are processed | |
| 144 | + int length = transforms.length(); | |
| 145 | + //foreach (const Transform *f, transforms) { | |
| 146 | + for (int i = 0; i < length; i++){ | |
| 147 | + Transform *f = transforms.at(length - i - 1); | |
| 148 | + try { | |
| 149 | + src >> *f; | |
| 150 | + } catch (...) { | |
| 151 | + qWarning("Exception triggered when processing %s with transform %s", qPrintable(dst.file.flat()), qPrintable(f->name())); | |
| 152 | + src = Template(src.file); | |
| 153 | + src.file.setBool("FTE"); | |
| 154 | + } | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 139 | 158 | }; |
| 140 | 159 | |
| 141 | 160 | BR_REGISTER(Transform, PipeTransform) |
| ... | ... | @@ -193,6 +212,24 @@ class ChainTransform : public MetaTransform |
| 193 | 212 | dst = Simplified(dst); |
| 194 | 213 | } |
| 195 | 214 | } |
| 215 | + | |
| 216 | + void projectBack(const Template &dst, Template &src) const | |
| 217 | + { | |
| 218 | + src = dst; | |
| 219 | + //reverse order in which transforms are processed | |
| 220 | + int length = transforms.length(); | |
| 221 | + //foreach (const Transform *f, transforms) { | |
| 222 | + for (int i = 0; i < length; i++){ | |
| 223 | + Transform *f = transforms.at(length - i - 1); | |
| 224 | + try { | |
| 225 | + src >> *f; | |
| 226 | + } catch (...) { | |
| 227 | + qWarning("Exception triggered when processing %s with transform %s", qPrintable(dst.file.flat()), qPrintable(f->name())); | |
| 228 | + src = Template(src.file); | |
| 229 | + src.file.setBool("FTE"); | |
| 230 | + } | |
| 231 | + } | |
| 232 | + } | |
| 196 | 233 | }; |
| 197 | 234 | |
| 198 | 235 | BR_REGISTER(Transform, ChainTransform) | ... | ... |
sdk/plugins/pixel.cpp
| ... | ... | @@ -52,7 +52,7 @@ class PerPixelClassifier : public MetaTransform |
| 52 | 52 | |
| 53 | 53 | void rotate(Template &src, Template &dst) const |
| 54 | 54 | { |
| 55 | - if (temp.m.cols()%9 != 0) qFatal("Rotation invariance can only be used after Neighbors"); | |
| 55 | + //if (src.m().cols%9 != 0) qFatal("Rotation invariance can only be used after Neighbors"); | |
| 56 | 56 | int images = (src.m().cols)/9; |
| 57 | 57 | dst = src; |
| 58 | 58 | for (int i = 0; i < images; i++){ | ... | ... |
sdk/plugins/pp5.cpp
| ... | ... | @@ -11,9 +11,9 @@ |
| 11 | 11 | #include <pittpatt_raw_image_io.h> |
| 12 | 12 | #include <pittpatt_sdk.h> |
| 13 | 13 | #include <pittpatt_license.h> |
| 14 | -#include <mm_plugin.h> | |
| 14 | +#include <openbr_plugin.h> | |
| 15 | 15 | |
| 16 | -#include "common/resource.h" | |
| 16 | +#include "core/resource.h" | |
| 17 | 17 | |
| 18 | 18 | #define TRY(CC) \ |
| 19 | 19 | { \ |
| ... | ... | @@ -30,7 +30,15 @@ |
| 30 | 30 | if ((CC) != PPR_RAW_IMAGE_SUCCESS) qFatal("%d error (%s, %d): %s.", CC, __FILE__, __LINE__, ppr_raw_image_error_message(CC)); \ |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | -using namespace mm; | |
| 33 | +using namespace br; | |
| 34 | + | |
| 35 | + | |
| 36 | +/*! | |
| 37 | + * \ingroup initializers | |
| 38 | + * \brief Initialize PP5 | |
| 39 | + * \author Josh Klontz \cite jklontz | |
| 40 | + * \author E. Taborsky \cite mmtaborsky | |
| 41 | + */ | |
| 34 | 42 | |
| 35 | 43 | class PP5Initializer : public Initializer |
| 36 | 44 | { |
| ... | ... | @@ -38,8 +46,8 @@ class PP5Initializer : public Initializer |
| 38 | 46 | |
| 39 | 47 | void initialize() const |
| 40 | 48 | { |
| 41 | - TRY(ppr_initialize_sdk(qPrintable(Globals->SDKPath + "/models/pp5/"), my_license_id, my_license_key)) | |
| 42 | - Globals->Abbreviations.insert("PP5","Open+PP5Enroll!Identity:PP5Compare"); | |
| 49 | + TRY(ppr_initialize_sdk(qPrintable(Globals->sdkPath + "/share/openbr/models/pp5/"), my_license_id, my_license_key)) | |
| 50 | + Globals->abbreviations.insert("PP5","Open+PP5Enroll!Identity:PP5Compare"); | |
| 43 | 51 | } |
| 44 | 52 | |
| 45 | 53 | void finalize() const |
| ... | ... | @@ -48,7 +56,13 @@ class PP5Initializer : public Initializer |
| 48 | 56 | } |
| 49 | 57 | }; |
| 50 | 58 | |
| 51 | -MM_REGISTER(Initializer, PP5Initializer, "") | |
| 59 | +BR_REGISTER(Initializer, PP5Initializer) | |
| 60 | + | |
| 61 | +/*! | |
| 62 | + * \brief PP5 context | |
| 63 | + * \author Josh Klontz \cite jklontz | |
| 64 | + * \author E. Taborsky \cite mmtaborsky | |
| 65 | + */ | |
| 52 | 66 | |
| 53 | 67 | struct PP5Context |
| 54 | 68 | { |
| ... | ... | @@ -194,11 +208,19 @@ struct PP5Context |
| 194 | 208 | } |
| 195 | 209 | }; |
| 196 | 210 | |
| 197 | -class PP5Enroll : public UntrainableFeature | |
| 211 | + | |
| 212 | +/*! | |
| 213 | + * \ingroup transforms | |
| 214 | + * \brief Enroll faces in PP5 | |
| 215 | + * \author Josh Klontz \cite jklontz | |
| 216 | + * \author E. Taborsky \cite mmtaborsky | |
| 217 | + */ | |
| 218 | + | |
| 219 | +class PP5Enroll : public UntrainableTransform | |
| 198 | 220 | { |
| 199 | 221 | Q_OBJECT |
| 200 | 222 | Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly) |
| 201 | - MM_MEMBER(bool, detectOnly) | |
| 223 | + BR_PROPERTY(bool, detectOnly, false) | |
| 202 | 224 | Resource<PP5Context> contexts; |
| 203 | 225 | |
| 204 | 226 | void project(const Template &src, Template &dst) const |
| ... | ... | @@ -245,13 +267,29 @@ class PP5Enroll : public UntrainableFeature |
| 245 | 267 | } |
| 246 | 268 | }; |
| 247 | 269 | |
| 248 | -MM_REGISTER(Feature, PP5Enroll, "bool detectOnly = 0") | |
| 270 | +BR_REGISTER(Transform, PP5Enroll) | |
| 271 | + | |
| 272 | + | |
| 249 | 273 | |
| 250 | -class PP5Compare : public Comparer | |
| 274 | +/*! | |
| 275 | + * \ingroup distances | |
| 276 | + * \brief Compare templates with PP5 | |
| 277 | + * \author Josh Klontz \cite jklontz | |
| 278 | + * \author E. Taborsky \cite mmtaborsky | |
| 279 | + */ | |
| 280 | + | |
| 281 | +class PP5Compare : public Distance | |
| 251 | 282 | , public PP5Context |
| 252 | 283 | { |
| 253 | 284 | Q_OBJECT |
| 254 | 285 | |
| 286 | + | |
| 287 | + float _compare(const Template &target, const Template &query) const | |
| 288 | + { | |
| 289 | + qFatal("PP5Compare: _compare should never be called"); | |
| 290 | + return 0; | |
| 291 | + } | |
| 292 | + | |
| 255 | 293 | void compare(const TemplateList &target, const TemplateList &query, Output *output) const |
| 256 | 294 | { |
| 257 | 295 | const float DefaultNonMatchScore = -1.5; |
| ... | ... | @@ -274,7 +312,7 @@ class PP5Compare : public Comparer |
| 274 | 312 | if ((query_face_id != -1) && (target_face_id != -1)) { |
| 275 | 313 | TRY(ppr_get_face_similarity_score(context, similarity_matrix, query_face_id, target_face_id, &score)) |
| 276 | 314 | } |
| 277 | - output->setData(score, i, j); | |
| 315 | + output->setRelative(score, i, j); | |
| 278 | 316 | } |
| 279 | 317 | } |
| 280 | 318 | |
| ... | ... | @@ -301,6 +339,8 @@ class PP5Compare : public Comparer |
| 301 | 339 | } |
| 302 | 340 | }; |
| 303 | 341 | |
| 304 | -MM_REGISTER(Comparer, PP5Compare, "") | |
| 342 | +BR_REGISTER(Distance, PP5Compare) | |
| 343 | + | |
| 344 | + | |
| 305 | 345 | |
| 306 | 346 | #include "plugins/pp5.moc" | ... | ... |