Pete Warden 4e3095f218 Modify magic wand example to work more robustly on Arduino
- Shuffles the accelerometer data axes so that they match the training data orientation with the Arduino mounted as desired.

 - Replaced the run-based post-processing with averaging over time.

 - Reverted the model data back to the original version.

 - Replaced the output buffer resetting with a detection suppression window after a gesture is found.

 - Removed the wait on the serial port, and added LED indicators for 'ring' and 'slope' (which seem to be the most accurately-detected gestures).

For an Arduino library zip file based off this change, see https://storage.googleapis.com/download.tensorflow.org/deps/tflite/arduino_library/tensorflow_lite_2020_02_09.zip

PiperOrigin-RevId: 296528242
Change-Id: I5219484de8f003bdac5fdd75bd6ec65ee51006e2
2020-02-21 15:55:45 -08:00

39 lines
1.6 KiB
C++

/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_
// The expected accelerometer data sample frequency
const float kTargetHz = 25;
// What gestures are supported.
constexpr int kGestureCount = 4;
constexpr int kWingGesture = 0;
constexpr int kRingGesture = 1;
constexpr int kSlopeGesture = 2;
constexpr int kNoGesture = 3;
// These control the sensitivity of the detection algorithm. If you're seeing
// too many false positives or not enough true positives, you can try tweaking
// these thresholds. Often, increasing the size of the training set will give
// more robust results though, so consider retraining if you are seeing poor
// predictions.
constexpr float kDetectionThreshold = 0.8f;
constexpr int kPredictionHistoryLength = 5;
constexpr int kPredictionSuppressionDuration = 25;
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_