Commit a9e0fa4faa03c5a5e71fde592cfdccf266caf7e2

Authored by Josh Klontz
1 parent c11ed94c

initial interface for writing model files to likely

app/br/br.cpp
... ... @@ -189,6 +189,9 @@ public:
189 189 } else if (!strcmp(fun, "deduplicate")) {
190 190 check(parc == 3, "Incorrect parameter count for 'deduplicate'.");
191 191 br_deduplicate(parv[0], parv[1], parv[2]);
  192 + } else if (!strcmp(fun, "likely")) {
  193 + check(parc == 3, "Incorrect parameter count for 'likely'.");
  194 + br_likely(parv[0], parv[1], parv[2]);
192 195 }
193 196  
194 197 // Miscellaneous
... ... @@ -280,7 +283,8 @@ private:
280 283 "-plotLandmarking <file> ... <file> {destination}\n"
281 284 "-plotMetadata <file> ... <file> <columns>\n"
282 285 "-project <input_gallery> {output_gallery}\n"
283   - "-deduplicate <input_gallery> <output_gallery> <threshold>"
  286 + "-deduplicate <input_gallery> <output_gallery> <threshold>\n"
  287 + "-likely <input_type> <output_type> <output_likely_source>\n"
284 288 "-getHeader <matrix>\n"
285 289 "-setHeader {<matrix>} <target_gallery> <query_gallery>\n"
286 290 "-<key> <value>\n"
... ...
openbr/core/likely.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 "likely.h"
  18 +
  19 +using namespace br;
  20 +
  21 +void br::Likely(const QString &inputType, const QString &outputType, const File &outputSourceFile)
  22 +{
  23 + const QSharedPointer<Transform> t(Transform::fromAlgorithm(Globals->algorithm));
  24 +
  25 + QFile file(outputSourceFile.name);
  26 + if (!file.open(QFile::WriteOnly))
  27 + qFatal("Failed to open Likely output source file for writing!");
  28 +
  29 + file.write("; Automatically generated source code from:\n");
  30 + file.write("; $ br -algorithm ");
  31 + file.write(Globals->algorithm.toLatin1());
  32 + file.write(" -likely ");
  33 + file.write(inputType.toLatin1());
  34 + file.write(" ");
  35 + file.write(outputType.toLatin1());
  36 + file.write(" ");
  37 + file.write(outputSourceFile.flat().toLatin1());
  38 + file.write("\n\n");
  39 +
  40 + file.write("f :=\n");
  41 + file.write(" src :->\n");
  42 +
  43 + file.write(t->likely(""));
  44 + file.write("\n");
  45 +
  46 + file.write("\n(extern ");
  47 + file.write(outputType.toLatin1());
  48 + file.write(" ");
  49 + file.write(Globals->algorithm.toLower().toLatin1());
  50 + file.write(" ");
  51 + file.write(inputType.toLatin1());
  52 + file.write(" f)\n");
  53 +}
... ...
openbr/core/likely.h 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 +#ifndef BR_LIKELY_H
  18 +#define BR_LIKELY_H
  19 +
  20 +#include "openbr/openbr_plugin.h"
  21 +
  22 +namespace br
  23 +{
  24 + void Likely(const QString &inputType, const QString &outputType, const File &outputSourceFile);
  25 +}
  26 +
  27 +#endif // BR_LIKELY_H
... ...
openbr/openbr.cpp
... ... @@ -20,6 +20,7 @@
20 20 #include "core/cluster.h"
21 21 #include "core/eval.h"
22 22 #include "core/fuse.h"
  23 +#include "core/likely.h"
23 24 #include "core/plot.h"
24 25 #include "core/qtutils.h"
25 26 #include "plugins/openbr_internal.h"
... ... @@ -481,3 +482,8 @@ void br_deduplicate(const char *input_gallery, const char *output_gallery, const
481 482 {
482 483 br::Deduplicate(input_gallery, output_gallery, threshold);
483 484 }
  485 +
  486 +void br_likely(const char *input_type, const char *output_type, const char *output_source_file)
  487 +{
  488 + br::Likely(input_type, output_type, output_source_file);
  489 +}
... ...
openbr/openbr.h
... ... @@ -115,6 +115,8 @@ BR_EXPORT const char *br_version();
115 115  
116 116 BR_EXPORT void br_slave_process(const char * baseKey);
117 117  
  118 +BR_EXPORT void br_likely(const char *input_type, const char *output_type, const char *output_source_file);
  119 +
118 120 // to avoid having to include unwanted headers
119 121 // this will be this header's conception of a Template
120 122 // any functions that need a Template pointer
... ...
openbr/openbr_plugin.h
... ... @@ -813,6 +813,7 @@ public:
813 813 }
814 814  
815 815 virtual Transform * simplify(bool &newTransform) { newTransform = false; return this; }
  816 + virtual QByteArray likely(const QByteArray &indentation) const { (void) indentation; return "src"; }
816 817  
817 818 protected:
818 819 Transform(bool independent = true, bool trainable = true);
... ...
openbr/plugins/core/independent.cpp
... ... @@ -222,6 +222,13 @@ class IndependentTransform : public MetaTransform
222 222 for (int i=0; i<size; i++)
223 223 transforms[i]->load(stream);
224 224 }
  225 +
  226 + QByteArray likely(const QByteArray &indentation) const
  227 + {
  228 + if (transforms.size() != 1)
  229 + return "src"; // TODO: implement
  230 + return transforms.first()->likely(indentation);
  231 + }
225 232 };
226 233  
227 234 BR_REGISTER(Transform, IndependentTransform)
... ...
openbr/plugins/core/pipe.cpp
... ... @@ -179,6 +179,23 @@ class PipeTransform : public CompositeTransform
179 179 CompositeTransform::init();
180 180 }
181 181  
  182 + QByteArray likely(const QByteArray &indentation) const
  183 + {
  184 + QByteArray result;
  185 + result.append("{\n");
  186 + foreach (Transform *t, transforms) {
  187 + const QByteArray dst = t->likely(indentation + " ");
  188 + if (dst == "src")
  189 + continue; // Not implemented
  190 + result.append(indentation + " src := ");
  191 + result.append(dst);
  192 + result.append("\n");
  193 + }
  194 +
  195 + result.append(indentation + " src\n}");
  196 + return result;
  197 + }
  198 +
182 199 protected:
183 200 // Template list project -- process templates in parallel through Transform::project
184 201 // or if parallelism is disabled, handle them sequentially
... ...
openbr/plugins/imgproc/quantize.cpp
... ... @@ -48,6 +48,21 @@ class QuantizeTransform : public Transform
48 48 {
49 49 src.m().convertTo(dst, CV_8U, a, b);
50 50 }
  51 +
  52 + QByteArray likely(const QByteArray &indentation) const
  53 + {
  54 + QByteArray result;
  55 + result.append("\n" + indentation + "{ ; Quantize\n");
  56 + result.append(indentation + " dst := (imitate-size src (imitate-dimensions u8 src.type))\n");
  57 + result.append(indentation + " (dst src) :=>\n");
  58 + result.append(indentation + " dst :<- src.(* ");
  59 + result.append(QByteArray::number(a, 'g', 9));
  60 + result.append(").(+ ");
  61 + result.append(QByteArray::number(b, 'g', 9));
  62 + result.append(")\n");
  63 + result.append(indentation + "}");
  64 + return result;
  65 + }
51 66 };
52 67  
53 68 BR_REGISTER(Transform, QuantizeTransform)
... ...