-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major refactoring of classes and layout
- Loading branch information
1 parent
5fb8f3f
commit a7b44b6
Showing
512 changed files
with
24,009 additions
and
1,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#define CAMERA_MODEL_M5STACK_WIDE | ||
#include <EloquentVision.h> | ||
|
||
Eloquent::Vision::ESP32Camera camera; | ||
camera_fb_t *frame; | ||
|
||
|
||
|
||
/** | ||
* Configure camera | ||
*/ | ||
void initCamera() { | ||
camera.begin(FRAMESIZE_QVGA, PIXFORMAT_GRAYSCALE, 20000000); | ||
} | ||
|
||
|
||
/** | ||
* Capture frame from ESP32 camera | ||
*/ | ||
uint8_t* captureFrame() { | ||
frame = camera.capture(); | ||
|
||
return frame->buf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <EloquentTinyML.h> | ||
#include <eloquent_tinyml/tensorflow/person_detection.h> | ||
|
||
#if defined(ESP32) | ||
#include "ESP32Camera.h" | ||
#else | ||
#include "PortentaVision.h" | ||
#endif | ||
|
||
const uint16_t imageWidth = 320; | ||
const uint16_t imageHeight = 240; | ||
|
||
|
||
Eloquent::TinyML::TensorFlow::PersonDetection<imageWidth, imageHeight> detector; | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(5000); | ||
initCamera(); | ||
|
||
// configure a threshold for "robust" person detection | ||
// if no threshold is set, "person" would be detected everytime person_score > not_person_score | ||
// even if just by 1 | ||
// by trial and error, considering that scores range from 0 to 255, a threshold of 190-200 | ||
// dramatically reduces the number of false positives | ||
detector.setDetectionAbsoluteThreshold(190); | ||
detector.begin(); | ||
|
||
// abort if an error occurred | ||
if (!detector.isOk()) { | ||
Serial.print("Setup error: "); | ||
Serial.println(detector.getErrorMessage()); | ||
|
||
while (true) delay(1000); | ||
} | ||
} | ||
|
||
void loop() { | ||
uint8_t *frame = captureFrame(); | ||
bool isPersonInFrame = detector.detectPerson(frame); | ||
|
||
if (!detector.isOk()) { | ||
Serial.print("Loop error: "); | ||
Serial.println(detector.getErrorMessage()); | ||
|
||
delay(10000); | ||
return; | ||
} | ||
|
||
Serial.print(isPersonInFrame ? "Person detected" : "No person detected"); | ||
Serial.print(" (it took "); | ||
Serial.print(detector.getElapsedTime()); | ||
Serial.println("ms to detect)"); | ||
Serial.print("\t > Person score: "); | ||
Serial.println(detector.getPersonScore()); | ||
Serial.print("\t > Not person score: "); | ||
Serial.println(detector.getNotPersonScore()); | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "camera.h" | ||
|
||
CameraClass cam; | ||
uint8_t frame[320*240]; | ||
|
||
|
||
/** | ||
* Configure camera | ||
*/ | ||
void initCamera() { | ||
cam.begin(CAMERA_R320x240, 30); | ||
} | ||
|
||
|
||
/** | ||
* Capture frame from Vision shield | ||
*/ | ||
uint8_t* captureFrame() { | ||
cam.grab(frame); | ||
|
||
return frame; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <EloquentTinyML.h> | ||
#include <eloquent_tinyml/tensorflow.h> | ||
|
||
// sine_model.h contains the array you exported from Python with xxd or tinymlgen | ||
#include "sine_model.h" | ||
|
||
#define N_INPUTS 1 | ||
#define N_OUTPUTS 1 | ||
// in future projects you may need to tweak this value: it's a trial and error process | ||
#define TENSOR_ARENA_SIZE 2*1024 | ||
|
||
Eloquent::TinyML::TensorFlow::TensorFlow<N_INPUTS, N_OUTPUTS, TENSOR_ARENA_SIZE> tf; | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(4000); | ||
tf.begin(sine_model); | ||
|
||
// check if model loaded fine | ||
if (!tf.isOk()) { | ||
Serial.print("ERROR: "); | ||
Serial.println(tf.getErrorMessage()); | ||
|
||
while (true) delay(1000); | ||
} | ||
} | ||
|
||
void loop() { | ||
for (float i = 0; i < 10; i++) { | ||
// pick x from 0 to PI | ||
float x = 3.14 * i / 10; | ||
float y = sin(x); | ||
float input[1] = { x }; | ||
float predicted = tf.predict(input); | ||
|
||
Serial.print("sin("); | ||
Serial.print(x); | ||
Serial.print(") = "); | ||
Serial.print(y); | ||
Serial.print("\t predicted: "); | ||
Serial.println(predicted); | ||
} | ||
|
||
delay(1000); | ||
} |
Oops, something went wrong.