Skip to content

Commit

Permalink
refactor: define IrisLandmarksFromFaceLandmarks calculators
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Jul 4, 2021
1 parent 49c275b commit be7cf44
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 719 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ node {

# Detects iris landmarks
node {
calculator: "IrisLandmarkLeftAndRightFromFaceLandmarksGpu"
calculator: "IrisLandmarksFromFaceLandmarksGpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "FACE_LANDMARKS:gated_face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ node {

# Detects iris landmarks
node {
calculator: "IrisLandmarkLeftAndRightFromFaceLandmarksCpu"
calculator: "IrisLandmarksFromFaceLandmarksCpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "FACE_LANDMARKS:gated_face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ node {

# Detects iris landmarks
node {
calculator: "IrisLandmarkLeftAndRightFromFaceLandmarksGpu"
calculator: "IrisLandmarksFromFaceLandmarksGpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "FACE_LANDMARKS:gated_face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,74 +114,22 @@ node {
}
}

# Gets two landmarks which define left eye boundary.
# Detects iris landmarks
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "left_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 33 end: 34 }
ranges: { begin: 133 end: 134 }
combine_outputs: true
}
}
}

# Gets two landmarks which define right eye boundary.
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "right_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 362 end: 363 }
ranges: { begin: 263 end: 264 }
combine_outputs: true
}
}
}

# Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI).
node {
calculator: "IrisLandmarkLeftAndRightGpu"
calculator: "IrisLandmarksFromFaceLandmarksGpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks"
input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks"
output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks"
output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "left_eye_contour_landmarks"
input_stream: "right_eye_contour_landmarks"
output_stream: "refined_eye_landmarks"
}

node {
calculator: "UpdateFaceLandmarksCalculator"
input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks"
input_stream: "FACE_LANDMARKS:face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:updated_face_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
}

# Concatenate iris landmarks from both eyes.
node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "left_iris_landmarks"
input_stream: "right_iris_landmarks"
output_stream: "iris_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "iris_landmarks"
output_stream: "face_landmarks_with_iris"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,74 +94,22 @@ node {
}
}

# Gets two landmarks which define left eye boundary.
# Detects iris landmarks
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "left_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 33 end: 34 }
ranges: { begin: 133 end: 134 }
combine_outputs: true
}
}
}

# Gets two landmarks which define right eye boundary.
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "right_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 362 end: 363 }
ranges: { begin: 263 end: 264 }
combine_outputs: true
}
}
}

# Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI).
node {
calculator: "IrisLandmarkLeftAndRightCpu"
calculator: "IrisLandmarksFromFaceLandmarksCpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks"
input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks"
output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks"
output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "left_eye_contour_landmarks"
input_stream: "right_eye_contour_landmarks"
output_stream: "refined_eye_landmarks"
}

node {
calculator: "UpdateFaceLandmarksCalculator"
input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks"
input_stream: "FACE_LANDMARKS:face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:updated_face_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
}

# Concatenate iris landmarks from both eyes.
node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "left_iris_landmarks"
input_stream: "right_iris_landmarks"
output_stream: "iris_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "iris_landmarks"
output_stream: "face_landmarks_with_iris"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,74 +121,22 @@ node {
}
}

# Gets two landmarks which define left eye boundary.
# Detects iris landmarks
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "left_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 33 end: 34 }
ranges: { begin: 133 end: 134 }
combine_outputs: true
}
}
}

# Gets two landmarks which define right eye boundary.
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "right_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 362 end: 363 }
ranges: { begin: 263 end: 264 }
combine_outputs: true
}
}
}

# Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI).
node {
calculator: "IrisLandmarkLeftAndRightGpu"
calculator: "IrisLandmarksFromFaceLandmarksGpu"
input_stream: "IMAGE:transformed_input_video"
input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks"
input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks"
output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks"
output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "left_eye_contour_landmarks"
input_stream: "right_eye_contour_landmarks"
output_stream: "refined_eye_landmarks"
}

node {
calculator: "UpdateFaceLandmarksCalculator"
input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks"
input_stream: "FACE_LANDMARKS:face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:updated_face_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
}

# Concatenate iris landmarks from both eyes.
node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "left_iris_landmarks"
input_stream: "right_iris_landmarks"
output_stream: "iris_landmarks"
}

node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "updated_face_landmarks"
input_stream: "iris_landmarks"
output_stream: "face_landmarks_with_iris"
}

Expand Down
2 changes: 2 additions & 0 deletions mediapipe_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ cc_library(
"@com_google_mediapipe//mediapipe/calculators/image:image_transformation_calculator",
] + select({
"@com_google_mediapipe//mediapipe/gpu:disable_gpu": [
"//mediapipe_api/modules/iris_landmark:iris_landmarks_from_face_landmarks_cpu",
"@com_google_mediapipe//mediapipe/graphs/face_detection:desktop_live_calculators",
"@com_google_mediapipe//mediapipe/graphs/face_mesh:desktop_live_calculators",
"@com_google_mediapipe//mediapipe/graphs/hand_tracking:desktop_tflite_calculators",
Expand All @@ -97,6 +98,7 @@ cc_library(
"@com_google_mediapipe//mediapipe/graphs/tracking:desktop_calculators",
],
"//conditions:default": [
"//mediapipe_api/modules/iris_landmark:iris_landmarks_from_face_landmarks_gpu",
# ATTENTION!
# If you're building for Android with debug symobls (--compilation_mode=dbg), exclude `instant_motion_tracking_deps`
# or exclude the other deps defined under `mediapipe/graphs`.
Expand Down
30 changes: 30 additions & 0 deletions mediapipe_api/modules/iris_landmark/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load(
"@com_google_mediapipe//mediapipe/framework/tool:mediapipe_graph.bzl",
"mediapipe_simple_subgraph",
)

package(default_visibility = ["//visibility:public"])

mediapipe_simple_subgraph(
name = "iris_landmarks_from_face_landmarks_gpu",
graph = "iris_landmarks_from_face_landmarks_gpu.pbtxt",
register_as = "IrisLandmarksFromFaceLandmarksGpu",
deps = [
"@com_google_mediapipe//mediapipe/modules/iris_landmark:iris_landmark_left_and_right_gpu",
"@com_google_mediapipe//mediapipe/calculators/core:concatenate_normalized_landmark_list_calculator",
"@com_google_mediapipe//mediapipe/calculators/core:split_normalized_landmark_list_calculator",
"@com_google_mediapipe//mediapipe/graphs/iris_tracking/calculators:update_face_landmarks_calculator",
],
)

mediapipe_simple_subgraph(
name = "iris_landmarks_from_face_landmarks_cpu",
graph = "iris_landmarks_from_face_landmarks_cpu.pbtxt",
register_as = "IrisLandmarksFromFaceLandmarksCpu",
deps = [
"@com_google_mediapipe//mediapipe/modules/iris_landmark:iris_landmark_left_and_right_cpu",
"@com_google_mediapipe//mediapipe/calculators/core:concatenate_normalized_landmark_list_calculator",
"@com_google_mediapipe//mediapipe/calculators/core:split_normalized_landmark_list_calculator",
"@com_google_mediapipe//mediapipe/graphs/iris_tracking/calculators:update_face_landmarks_calculator",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI) from face landmarks.

type: "IrisLandmarkLeftAndRightFromFaceLandmarksCpu"

# CPU image. (ImageFrame)
input_stream: "IMAGE:image"
# Face landmarks. (NormalizedLandmarkList)
input_stream: "FACE_LANDMARKS:face_landmarks"

# Refined face landmarks. (NormalizedLandmarkList)
output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks"

# 71 normalized eye contour landmarks. (NormalizedLandmarkList)
output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks"
# 5 normalized iris landmarks. (NormalizedLandmarkList)
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
# Region of interest used to do calculations for the left eye. (NormalizedRect)
output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks"

# 71 normalized eye contour landmarks. (NormalizedLandmarkList)
output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks"
# 5 normalized iris landmarks. (NormalizedLandmarkList)
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
# Region of interest used to do calculations for the right eye. (NormalizedRect)
output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks"


# Gets two landmarks which define left eye boundary.
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "left_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 33 end: 34 }
ranges: { begin: 133 end: 134 }
combine_outputs: true
}
}
}
# Gets two landmarks which define right eye boundary.
node {
calculator: "SplitNormalizedLandmarkListCalculator"
input_stream: "face_landmarks"
output_stream: "right_eye_boundary_landmarks"
node_options: {
[type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
ranges: { begin: 362 end: 363 }
ranges: { begin: 263 end: 264 }
combine_outputs: true
}
}
}
# Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI).
node {
calculator: "IrisLandmarkLeftAndRightCpu"
input_stream: "IMAGE:image"
input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks"
input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks"
output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks"
output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks"
output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks"
output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks"
output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks"
output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks"
}
node {
calculator: "ConcatenateNormalizedLandmarkListCalculator"
input_stream: "left_eye_contour_landmarks"
input_stream: "right_eye_contour_landmarks"
output_stream: "refined_eye_landmarks"
}
node {
calculator: "UpdateFaceLandmarksCalculator"
input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks"
input_stream: "FACE_LANDMARKS:face_landmarks"
output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks"
}
Loading

0 comments on commit be7cf44

Please sign in to comment.