Simplify default options for GestureRecognize
PiperOrigin-RevId: 500729643
This commit is contained in:
parent
e0a254789a
commit
1bbe065647
2
mediapipe/tasks/testdata/vision/BUILD
vendored
2
mediapipe/tasks/testdata/vision/BUILD
vendored
|
@ -38,6 +38,7 @@ mediapipe_files(srcs = [
|
||||||
"coco_ssd_mobilenet_v1_1.0_quant_2018_06_29_with_dummy_score_calibration.tflite",
|
"coco_ssd_mobilenet_v1_1.0_quant_2018_06_29_with_dummy_score_calibration.tflite",
|
||||||
"deeplabv3.tflite",
|
"deeplabv3.tflite",
|
||||||
"fist.jpg",
|
"fist.jpg",
|
||||||
|
"fist.png",
|
||||||
"hand_landmark_full.tflite",
|
"hand_landmark_full.tflite",
|
||||||
"hand_landmark_lite.tflite",
|
"hand_landmark_lite.tflite",
|
||||||
"hand_landmarker.task",
|
"hand_landmarker.task",
|
||||||
|
@ -95,6 +96,7 @@ filegroup(
|
||||||
"cats_and_dogs_no_resizing.jpg",
|
"cats_and_dogs_no_resizing.jpg",
|
||||||
"cats_and_dogs_rotated.jpg",
|
"cats_and_dogs_rotated.jpg",
|
||||||
"fist.jpg",
|
"fist.jpg",
|
||||||
|
"fist.png",
|
||||||
"hand_landmark_full.tflite",
|
"hand_landmark_full.tflite",
|
||||||
"hand_landmark_lite.tflite",
|
"hand_landmark_lite.tflite",
|
||||||
"left_hands.jpg",
|
"left_hands.jpg",
|
||||||
|
|
|
@ -54,7 +54,7 @@ const GESTURE_RECOGNIZER_GRAPH =
|
||||||
'mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph';
|
'mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph';
|
||||||
|
|
||||||
const DEFAULT_NUM_HANDS = 1;
|
const DEFAULT_NUM_HANDS = 1;
|
||||||
const DEFAULT_SCORE_THRESHOLD = 0.5;
|
const DEFAULT_CONFIDENCE = 0.5;
|
||||||
const DEFAULT_CATEGORY_INDEX = -1;
|
const DEFAULT_CATEGORY_INDEX = -1;
|
||||||
|
|
||||||
/** Performs hand gesture recognition on images. */
|
/** Performs hand gesture recognition on images. */
|
||||||
|
@ -143,8 +143,6 @@ export class GestureRecognizer extends VisionTaskRunner {
|
||||||
new HandGestureRecognizerGraphOptions();
|
new HandGestureRecognizerGraphOptions();
|
||||||
this.options.setHandGestureRecognizerGraphOptions(
|
this.options.setHandGestureRecognizerGraphOptions(
|
||||||
this.handGestureRecognizerGraphOptions);
|
this.handGestureRecognizerGraphOptions);
|
||||||
|
|
||||||
this.initDefaults();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override get baseOptions(): BaseOptionsProto {
|
protected override get baseOptions(): BaseOptionsProto {
|
||||||
|
@ -165,22 +163,14 @@ export class GestureRecognizer extends VisionTaskRunner {
|
||||||
* @param options The options for the gesture recognizer.
|
* @param options The options for the gesture recognizer.
|
||||||
*/
|
*/
|
||||||
override setOptions(options: GestureRecognizerOptions): Promise<void> {
|
override setOptions(options: GestureRecognizerOptions): Promise<void> {
|
||||||
if ('numHands' in options) {
|
|
||||||
this.handDetectorGraphOptions.setNumHands(
|
this.handDetectorGraphOptions.setNumHands(
|
||||||
options.numHands ?? DEFAULT_NUM_HANDS);
|
options.numHands ?? DEFAULT_NUM_HANDS);
|
||||||
}
|
|
||||||
if ('minHandDetectionConfidence' in options) {
|
|
||||||
this.handDetectorGraphOptions.setMinDetectionConfidence(
|
this.handDetectorGraphOptions.setMinDetectionConfidence(
|
||||||
options.minHandDetectionConfidence ?? DEFAULT_SCORE_THRESHOLD);
|
options.minHandDetectionConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
}
|
|
||||||
if ('minHandPresenceConfidence' in options) {
|
|
||||||
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
|
||||||
options.minHandPresenceConfidence ?? DEFAULT_SCORE_THRESHOLD);
|
|
||||||
}
|
|
||||||
if ('minTrackingConfidence' in options) {
|
|
||||||
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
||||||
options.minTrackingConfidence ?? DEFAULT_SCORE_THRESHOLD);
|
options.minTrackingConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
}
|
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
||||||
|
options.minHandPresenceConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
|
|
||||||
if (options.cannedGesturesClassifierOptions) {
|
if (options.cannedGesturesClassifierOptions) {
|
||||||
// Note that we have to support both JSPB and ProtobufJS and cannot
|
// Note that we have to support both JSPB and ProtobufJS and cannot
|
||||||
|
@ -281,17 +271,6 @@ export class GestureRecognizer extends VisionTaskRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the default values for the graph. */
|
|
||||||
private initDefaults(): void {
|
|
||||||
this.handDetectorGraphOptions.setNumHands(DEFAULT_NUM_HANDS);
|
|
||||||
this.handDetectorGraphOptions.setMinDetectionConfidence(
|
|
||||||
DEFAULT_SCORE_THRESHOLD);
|
|
||||||
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
|
||||||
DEFAULT_SCORE_THRESHOLD);
|
|
||||||
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
|
||||||
DEFAULT_SCORE_THRESHOLD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Converts the proto data to a Category[][] structure. */
|
/** Converts the proto data to a Category[][] structure. */
|
||||||
private toJsCategories(data: Uint8Array[], populateIndex = true):
|
private toJsCategories(data: Uint8Array[], populateIndex = true):
|
||||||
Category[][] {
|
Category[][] {
|
||||||
|
|
6
third_party/external_files.bzl
vendored
6
third_party/external_files.bzl
vendored
|
@ -286,6 +286,12 @@ def external_files():
|
||||||
urls = ["https://storage.googleapis.com/mediapipe-assets/fist_landmarks.pbtxt?generation=1666999360561864"],
|
urls = ["https://storage.googleapis.com/mediapipe-assets/fist_landmarks.pbtxt?generation=1666999360561864"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
http_file(
|
||||||
|
name = "com_google_mediapipe_fist_png",
|
||||||
|
sha256 = "4397b3d3f590c88a8de7d21c08d73a0df4a97fd93f92cbd086eef37fd246daaa",
|
||||||
|
urls = ["https://storage.googleapis.com/mediapipe-assets/fist.png?generation=1672952068696274"],
|
||||||
|
)
|
||||||
|
|
||||||
http_file(
|
http_file(
|
||||||
name = "com_google_mediapipe_general_meta_json",
|
name = "com_google_mediapipe_general_meta_json",
|
||||||
sha256 = "b95363e4bae89b9c2af484498312aaad4efc7ff57c7eadcc4e5e7adca641445f",
|
sha256 = "b95363e4bae89b9c2af484498312aaad4efc7ff57c7eadcc4e5e7adca641445f",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user