146 lines
4.5 KiB
Plaintext
146 lines
4.5 KiB
Plaintext
# MediaPipe graph to detect faces. (CPU input, and inference is executed on
|
|
# CPU.)
|
|
#
|
|
# It is required that "face_detection_front.tflite" is available at
|
|
# "mediapipe/modules/face_detection/face_detection_front.tflite"
|
|
# path during execution.
|
|
#
|
|
# EXAMPLE:
|
|
# node {
|
|
# calculator: "FaceDetectionFrontCpu"
|
|
# input_stream: "IMAGE:image"
|
|
# output_stream: "DETECTIONS:face_detections"
|
|
# }
|
|
|
|
type: "FaceDetectionFrontCpu"
|
|
|
|
# CPU image. (ImageFrame)
|
|
input_stream: "IMAGE:image"
|
|
|
|
# Detected faces. (std::vector<Detection>)
|
|
# NOTE: there will not be an output packet in the DETECTIONS stream for this
|
|
# particular timestamp if none of faces detected. However, the MediaPipe
|
|
# framework will internally inform the downstream calculators of the absence of
|
|
# this packet so that they don't wait for it unnecessarily.
|
|
output_stream: "DETECTIONS:detections"
|
|
|
|
# Transforms the input image on CPU to a 128x128 image. To scale the input
|
|
# image, the scale_mode option is set to FIT to preserve the aspect ratio
|
|
# (what is expected by the corresponding face detection model), resulting in
|
|
# potential letterboxing in the transformed image.
|
|
node: {
|
|
calculator: "ImageTransformationCalculator"
|
|
input_stream: "IMAGE:image"
|
|
output_stream: "IMAGE:transformed_image"
|
|
output_stream: "LETTERBOX_PADDING:letterbox_padding"
|
|
options: {
|
|
[mediapipe.ImageTransformationCalculatorOptions.ext] {
|
|
output_width: 128
|
|
output_height: 128
|
|
scale_mode: FIT
|
|
}
|
|
}
|
|
}
|
|
|
|
# Converts the transformed input image on CPU into an image tensor stored as a
|
|
# TfLiteTensor.
|
|
node {
|
|
calculator: "TfLiteConverterCalculator"
|
|
input_stream: "IMAGE:transformed_image"
|
|
output_stream: "TENSORS:input_tensors"
|
|
}
|
|
|
|
# Runs a TensorFlow Lite model on CPU that takes an image tensor and outputs a
|
|
# vector of tensors representing, for instance, detection boxes/keypoints and
|
|
# scores.
|
|
node {
|
|
calculator: "TfLiteInferenceCalculator"
|
|
input_stream: "TENSORS:input_tensors"
|
|
output_stream: "TENSORS:detection_tensors"
|
|
options: {
|
|
[mediapipe.TfLiteInferenceCalculatorOptions.ext] {
|
|
model_path: "mediapipe/modules/face_detection/face_detection_front.tflite"
|
|
delegate { xnnpack {} }
|
|
}
|
|
}
|
|
}
|
|
|
|
# Generates a single side packet containing a vector of SSD anchors based on
|
|
# the specification in the options.
|
|
node {
|
|
calculator: "SsdAnchorsCalculator"
|
|
output_side_packet: "anchors"
|
|
options: {
|
|
[mediapipe.SsdAnchorsCalculatorOptions.ext] {
|
|
num_layers: 4
|
|
min_scale: 0.1484375
|
|
max_scale: 0.75
|
|
input_size_height: 128
|
|
input_size_width: 128
|
|
anchor_offset_x: 0.5
|
|
anchor_offset_y: 0.5
|
|
strides: 8
|
|
strides: 16
|
|
strides: 16
|
|
strides: 16
|
|
aspect_ratios: 1.0
|
|
fixed_anchor_size: true
|
|
}
|
|
}
|
|
}
|
|
|
|
# Decodes the detection tensors generated by the TensorFlow Lite model, based on
|
|
# the SSD anchors and the specification in the options, into a vector of
|
|
# detections. Each detection describes a detected object.
|
|
node {
|
|
calculator: "TfLiteTensorsToDetectionsCalculator"
|
|
input_stream: "TENSORS:detection_tensors"
|
|
input_side_packet: "ANCHORS:anchors"
|
|
output_stream: "DETECTIONS:unfiltered_detections"
|
|
options: {
|
|
[mediapipe.TfLiteTensorsToDetectionsCalculatorOptions.ext] {
|
|
num_classes: 1
|
|
num_boxes: 896
|
|
num_coords: 16
|
|
box_coord_offset: 0
|
|
keypoint_coord_offset: 4
|
|
num_keypoints: 6
|
|
num_values_per_keypoint: 2
|
|
sigmoid_score: true
|
|
score_clipping_thresh: 100.0
|
|
reverse_output_order: true
|
|
x_scale: 128.0
|
|
y_scale: 128.0
|
|
h_scale: 128.0
|
|
w_scale: 128.0
|
|
min_score_thresh: 0.5
|
|
}
|
|
}
|
|
}
|
|
|
|
# Performs non-max suppression to remove excessive detections.
|
|
node {
|
|
calculator: "NonMaxSuppressionCalculator"
|
|
input_stream: "unfiltered_detections"
|
|
output_stream: "filtered_detections"
|
|
options: {
|
|
[mediapipe.NonMaxSuppressionCalculatorOptions.ext] {
|
|
min_suppression_threshold: 0.3
|
|
overlap_type: INTERSECTION_OVER_UNION
|
|
algorithm: WEIGHTED
|
|
error_on_empty_detections: true
|
|
}
|
|
}
|
|
}
|
|
|
|
# Adjusts detection locations (already normalized to [0.f, 1.f]) on the
|
|
# letterboxed image (after image transformation with the FIT scale mode) to the
|
|
# corresponding locations on the same image with the letterbox removed (the
|
|
# input image to the graph before image transformation).
|
|
node {
|
|
calculator: "DetectionLetterboxRemovalCalculator"
|
|
input_stream: "DETECTIONS:filtered_detections"
|
|
input_stream: "LETTERBOX_PADDING:letterbox_padding"
|
|
output_stream: "DETECTIONS:detections"
|
|
}
|