summaryrefslogtreecommitdiffhomepage
path: root/tracker-neuralnet/tests.cpp
diff options
context:
space:
mode:
authorMichael Welter <michael@welter-4d.de>2022-09-11 20:55:26 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-11-01 13:51:35 +0100
commit08f1fcad1c74e25f97641a0ccbd229b267ec528c (patch)
tree000b1b276bc7df4a74fd493dab05bcce68801de8 /tracker-neuralnet/tests.cpp
parent77d6abaf53dbe2ee6334bd59b112e25d694a2f65 (diff)
tracker/nn: Tweaks, refactoring, a deadzone filtering and support for uncertainty estimation
* Add rudimentary test for two functions .. maybe more in future * Fix the rotation correction from vertical translation * Move preview class to new files * Move neural network model adapters to new files * Add utility functions for opencv * Query the model inputs/outputs by name to see what is available * Supports outputs for standard deviation of the data distribution - What you get if you let your model output the full parameters of a gaussian distribution (depending on the inputs) and fit it with negative log likelihood loss. * Disabled support for sequence models * Add support for detection of eye open/close classification. Scale uncertainty estimate up if eyes closed * Add a deadzone filter which activates if the model supports uncertainty quantification. The deadzone scales becomes larger the more uncertain the model/data are. This is mostly supposed to be useful to suppress large estimate errors when the user blinks with the eyes * Fix distance being twice of what it should have been
Diffstat (limited to 'tracker-neuralnet/tests.cpp')
-rw-r--r--tracker-neuralnet/tests.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tracker-neuralnet/tests.cpp b/tracker-neuralnet/tests.cpp
new file mode 100644
index 00000000..b1d2a6d0
--- /dev/null
+++ b/tracker-neuralnet/tests.cpp
@@ -0,0 +1,58 @@
+#include "model_adapters.h"
+
+#include <algorithm>
+#include <numeric>
+#include <cstdio>
+
+namespace neuralnet_tracker_tests
+{
+
+
+void assert_(bool ok, const std::string& msg)
+{
+ if (ok)
+ return;
+ std::cout << msg << std::endl;
+ std::exit(-1);
+}
+
+
+void test_find_input_intensity_quantile()
+{
+ cv::Mat data(10,10, CV_8UC1);
+ std::iota(data.begin<uint8_t>(), data.end<uint8_t>(), 0);
+
+ const float pct = 90;
+
+ const int val = neuralnet_tracker_ns::find_input_intensity_quantile(data, pct);
+
+ assert_(val == int(10*10*pct/100.f), "test_find_input_intensity_quantile failed");
+}
+
+
+void test_normalize_brightness()
+{
+ cv::Mat data(10,10, CV_8UC1);
+ std::iota(data.begin<uint8_t>(), data.end<uint8_t>(), 0);
+
+ cv::Mat out;
+ neuralnet_tracker_ns::normalize_brightness(data, out);
+
+ auto [minit,maxit] = std::minmax_element(out.begin<float>(),out.end<float>());
+ const auto minval = *minit;
+ const auto maxval = *maxit;
+ assert_(std::abs(minval + 0.5f) < 0.02, "test_normalize_brightness failed");
+ // If the brightest value is lower than half-max, it will be boosted to half-max.
+ // Otherwise it will just be rescaled to [-.5, 0.5 ]. Here we have the low-brightness case.
+ assert_(std::abs(maxval - 0.0f) < 0.02, "test_normalize_brightness failed");
+}
+
+
+void run()
+{
+ test_find_input_intensity_quantile();
+ test_normalize_brightness();
+}
+
+
+} \ No newline at end of file