Internal change

PiperOrigin-RevId: 520726897
This commit is contained in:
MediaPipe Team 2023-03-30 13:25:01 -07:00 committed by Copybara-Service
parent d43579fe3e
commit f8f7126bdd
5 changed files with 219 additions and 176 deletions

View File

@ -65,6 +65,8 @@ constexpr char kTestDataDirectory[] = "/mediapipe/tasks/testdata/vision/";
constexpr char kPoseDetectionModel[] = "pose_detection.tflite"; constexpr char kPoseDetectionModel[] = "pose_detection.tflite";
constexpr char kPortraitImage[] = "pose.jpg"; constexpr char kPortraitImage[] = "pose.jpg";
constexpr char kPoseExpectedDetection[] = "pose_expected_detection.pbtxt"; constexpr char kPoseExpectedDetection[] = "pose_expected_detection.pbtxt";
constexpr char kPoseExpectedExpandedRect[] =
"pose_expected_expanded_rect.pbtxt";
constexpr char kImageTag[] = "IMAGE"; constexpr char kImageTag[] = "IMAGE";
constexpr char kImageName[] = "image"; constexpr char kImageName[] = "image";
@ -72,8 +74,11 @@ constexpr char kNormRectTag[] = "NORM_RECT";
constexpr char kNormRectName[] = "norm_rect"; constexpr char kNormRectName[] = "norm_rect";
constexpr char kDetectionsTag[] = "DETECTIONS"; constexpr char kDetectionsTag[] = "DETECTIONS";
constexpr char kDetectionsName[] = "detections"; constexpr char kDetectionsName[] = "detections";
constexpr char kExpandedPoseRectsTag[] = "EXPANDED_POSE_RECTS";
constexpr char kExpandedPoseRectsName[] = "expanded_pose_rects";
constexpr float kPoseDetectionMaxDiff = 0.01; constexpr float kPoseDetectionMaxDiff = 0.01;
constexpr float kExpandedPoseRectMaxDiff = 0.01;
// Helper function to create a TaskRunner. // Helper function to create a TaskRunner.
absl::StatusOr<std::unique_ptr<TaskRunner>> CreateTaskRunner( absl::StatusOr<std::unique_ptr<TaskRunner>> CreateTaskRunner(
@ -99,6 +104,10 @@ absl::StatusOr<std::unique_ptr<TaskRunner>> CreateTaskRunner(
pose_detector_graph.Out(kDetectionsTag).SetName(kDetectionsName) >> pose_detector_graph.Out(kDetectionsTag).SetName(kDetectionsName) >>
graph[Output<std::vector<Detection>>(kDetectionsTag)]; graph[Output<std::vector<Detection>>(kDetectionsTag)];
pose_detector_graph.Out(kExpandedPoseRectsTag)
.SetName(kExpandedPoseRectsName) >>
graph[Output<std::vector<NormalizedRect>>(kExpandedPoseRectsTag)];
return TaskRunner::Create( return TaskRunner::Create(
graph.GetConfig(), std::make_unique<core::MediaPipeBuiltinOpResolver>()); graph.GetConfig(), std::make_unique<core::MediaPipeBuiltinOpResolver>());
} }
@ -111,6 +120,14 @@ Detection GetExpectedPoseDetectionResult(absl::string_view file_name) {
return detection; return detection;
} }
NormalizedRect GetExpectedExpandedPoseRect(absl::string_view file_name) {
NormalizedRect expanded_rect;
CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name),
&expanded_rect, Defaults()))
<< "Expected expanded pose rect does not exist.";
return expanded_rect;
}
struct TestParams { struct TestParams {
// The name of this test, for convenience when displaying test results. // The name of this test, for convenience when displaying test results.
std::string test_name; std::string test_name;
@ -119,7 +136,9 @@ struct TestParams {
// The filename of test image. // The filename of test image.
std::string test_image_name; std::string test_image_name;
// Expected pose detection results. // Expected pose detection results.
std::vector<Detection> expected_result; std::vector<Detection> expected_detection;
// Expected expanded pose rects.
std::vector<NormalizedRect> expected_expanded_pose_rect;
}; };
class PoseDetectorGraphTest : public testing::TestWithParam<TestParams> {}; class PoseDetectorGraphTest : public testing::TestWithParam<TestParams> {};
@ -144,16 +163,27 @@ TEST_P(PoseDetectorGraphTest, Succeed) {
(*output_packets)[kDetectionsName].Get<std::vector<Detection>>(); (*output_packets)[kDetectionsName].Get<std::vector<Detection>>();
EXPECT_THAT(pose_detections, Pointwise(Approximately(Partially(EqualsProto()), EXPECT_THAT(pose_detections, Pointwise(Approximately(Partially(EqualsProto()),
kPoseDetectionMaxDiff), kPoseDetectionMaxDiff),
GetParam().expected_result)); GetParam().expected_detection));
const std::vector<NormalizedRect>& expanded_pose_rects =
(*output_packets)[kExpandedPoseRectsName]
.Get<std::vector<NormalizedRect>>();
EXPECT_THAT(expanded_pose_rects,
Pointwise(Approximately(Partially(EqualsProto()),
kExpandedPoseRectMaxDiff),
GetParam().expected_expanded_pose_rect));
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
PoseDetectorGraphTest, PoseDetectorGraphTest, PoseDetectorGraphTest, PoseDetectorGraphTest,
Values(TestParams{.test_name = "DetectPose", Values(TestParams{
.test_name = "DetectPose",
.pose_detection_model_name = kPoseDetectionModel, .pose_detection_model_name = kPoseDetectionModel,
.test_image_name = kPortraitImage, .test_image_name = kPortraitImage,
.expected_result = {GetExpectedPoseDetectionResult( .expected_detection = {GetExpectedPoseDetectionResult(
kPoseExpectedDetection)}}), kPoseExpectedDetection)},
.expected_expanded_pose_rect = {GetExpectedExpandedPoseRect(
kPoseExpectedExpandedRect)}}),
[](const TestParamInfo<PoseDetectorGraphTest::ParamType>& info) { [](const TestParamInfo<PoseDetectorGraphTest::ParamType>& info) {
return info.param.test_name; return info.param.test_name;
}); });

View File

@ -319,6 +319,8 @@ TEST_P(MultiPoseLandmarkerTest, Succeeds) {
GetParam().expected_landmark_lists)); GetParam().expected_landmark_lists));
} }
// TODO: Add additional tests for MP Tasks Pose Graphs. // TODO: Add additional tests for MP Tasks Pose Graphs.
// PoseRects below are based on result from PoseDetectorGraph,
// mediapipe/tasks/testdata/vision/pose_expected_expanded_rect.pbtxt.
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
PoseLandmarkerTest, PoseLandmarkerTest, PoseLandmarkerTest, PoseLandmarkerTest,
Values( Values(
@ -326,7 +328,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "PoseLandmarkerLiteModel", .test_name = "PoseLandmarkerLiteModel",
.input_model_name = kPoseLandmarkerLiteModel, .input_model_name = kPoseLandmarkerLiteModel,
.test_image_name = kPoseImage, .test_image_name = kPoseImage,
.pose_rect = MakePoseRect(0.25, 0.5, 0.5, 1.0, 0), .pose_rect = MakePoseRect(0.5450622, 0.31605977, 0.5196669,
0.77911085, 0.50149304),
.expected_presence = true, .expected_presence = true,
.expected_landmarks = .expected_landmarks =
GetExpectedLandmarkList(kExpectedPoseLandmarksFilename), GetExpectedLandmarkList(kExpectedPoseLandmarksFilename),
@ -335,7 +338,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "PoseLandmarkerLiteModelNoPose", .test_name = "PoseLandmarkerLiteModelNoPose",
.input_model_name = kPoseLandmarkerLiteModel, .input_model_name = kPoseLandmarkerLiteModel,
.test_image_name = kBurgerImage, .test_image_name = kBurgerImage,
.pose_rect = MakePoseRect(0.25, 0.5, 0.5, 1.0, 0), .pose_rect = MakePoseRect(0.5450622, 0.31605977, 0.5196669,
0.77911085, 0.50149304),
.expected_presence = false, .expected_presence = false,
.expected_landmarks = std::nullopt, .expected_landmarks = std::nullopt,
.landmarks_diff_threshold = kLiteModelFractionDiff}), .landmarks_diff_threshold = kLiteModelFractionDiff}),
@ -349,7 +353,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "MultiPoseLandmarkerLiteModel", .test_name = "MultiPoseLandmarkerLiteModel",
.input_model_name = kPoseLandmarkerLiteModel, .input_model_name = kPoseLandmarkerLiteModel,
.test_image_name = kPoseImage, .test_image_name = kPoseImage,
.pose_rects = {MakePoseRect(0.25, 0.5, 0.5, 1.0, 0)}, .pose_rects = {MakePoseRect(0.5450622, 0.31605977, 0.5196669,
0.77911085, 0.50149304)},
.expected_presences = {true}, .expected_presences = {true},
.expected_landmark_lists = {GetExpectedLandmarkList( .expected_landmark_lists = {GetExpectedLandmarkList(
kExpectedPoseLandmarksFilename)}, kExpectedPoseLandmarksFilename)},

View File

@ -217,6 +217,7 @@ filegroup(
"portrait_expected_face_landmarks_with_attention.pbtxt", "portrait_expected_face_landmarks_with_attention.pbtxt",
"portrait_rotated_expected_detection.pbtxt", "portrait_rotated_expected_detection.pbtxt",
"pose_expected_detection.pbtxt", "pose_expected_detection.pbtxt",
"pose_expected_expanded_rect.pbtxt",
"thumb_up_landmarks.pbtxt", "thumb_up_landmarks.pbtxt",
"thumb_up_rotated_landmarks.pbtxt", "thumb_up_rotated_landmarks.pbtxt",
"victory_landmarks.pbtxt", "victory_landmarks.pbtxt",

View File

@ -1,231 +1,231 @@
landmark { landmark {
x: 0.5033445 x: 0.44039154
y: 0.43453366 y: 0.69266146
z: 0.14119335 z: -1.0701033
visibility: 0.9981027 visibility: 0.99999785
presence: 0.9992255 presence: 0.99999964
} }
landmark { landmark {
x: 0.49945074 x: 0.4402231
y: 0.42642897 y: 0.6729447
z: 0.1261509 z: -1.0995388
visibility: 0.99845314 visibility: 0.9999958
presence: 0.9988668 presence: 0.9999989
} }
landmark { landmark {
x: 0.49838358 x: 0.44525078
y: 0.42594656 y: 0.67028874
z: 0.12615599 z: -1.0994295
visibility: 0.9983102 visibility: 0.9999949
presence: 0.9988244 presence: 0.9999989
} }
landmark { landmark {
x: 0.49738216 x: 0.44974685
y: 0.42554975 y: 0.6671066
z: 0.12622544 z: -1.099441
visibility: 0.99852186 visibility: 0.9999943
presence: 0.99873894 presence: 0.9999987
} }
landmark { landmark {
x: 0.5031697 x: 0.43495473
y: 0.42662272 y: 0.67640877
z: 0.13347684 z: -1.0970817
visibility: 0.9978422 visibility: 0.9999975
presence: 0.9989411 presence: 0.99999917
} }
landmark { landmark {
x: 0.5052138 x: 0.43337595
y: 0.42640454 y: 0.6775264
z: 0.13340297 z: -1.0973414
visibility: 0.9973635 visibility: 0.99999714
presence: 0.99888366 presence: 0.99999917
} }
landmark { landmark {
x: 0.50699204 x: 0.43298554
y: 0.42618936 y: 0.6775605
z: 0.13343208 z: -1.0972598
visibility: 0.9977912 visibility: 0.99999726
presence: 0.9987791 presence: 0.99999905
} }
landmark { landmark {
x: 0.50158876 x: 0.4708667
y: 0.42372653 y: 0.6595806
z: 0.075136274 z: -1.0533934
visibility: 0.9976786 visibility: 0.9999908
presence: 0.99851876 presence: 0.99999905
} }
landmark { landmark {
x: 0.51374334 x: 0.44428575
y: 0.42491674 y: 0.67323744
z: 0.10752227 z: -1.0379978
visibility: 0.99754214 visibility: 0.99999785
presence: 0.99863297 presence: 0.9999993
} }
landmark { landmark {
x: 0.5059119 x: 0.4564836
y: 0.43917143 y: 0.6977895
z: 0.12961307 z: -1.0333056
visibility: 0.9958307 visibility: 0.9999943
presence: 0.9977532 presence: 0.9999994
} }
landmark { landmark {
x: 0.5109223 x: 0.44782764
y: 0.43983036 y: 0.7037028
z: 0.13892516 z: -1.0296792
visibility: 0.99557614 visibility: 0.9999962
presence: 0.9976047 presence: 0.9999994
} }
landmark { landmark {
x: 0.5023406 x: 0.5449939
y: 0.45419085 y: 0.62528574
z: 0.045139182 z: -0.7878126
visibility: 0.99948055 visibility: 0.9999747
presence: 0.99782556 presence: 0.9999956
} }
landmark { landmark {
x: 0.5593891 x: 0.3974144
y: 0.44672203 y: 0.68981373
z: 0.09991482 z: -0.77783424
visibility: 0.99833965 visibility: 0.99997735
presence: 0.9977375 presence: 0.99999726
} }
landmark { landmark {
x: 0.49746004 x: 0.69353175
y: 0.4821021 y: 0.63911355
z: 0.037247833 z: -0.69779164
visibility: 0.80266625 visibility: 0.99741924
presence: 0.9972971 presence: 0.99996626
} }
landmark { landmark {
x: 0.57370883 x: 0.32092315
y: 0.47189793 y: 0.8199662
z: 0.13776684 z: -0.7256159
visibility: 0.5926873 visibility: 0.99759066
presence: 0.9988753 presence: 0.9999684
} }
landmark { landmark {
x: 0.5110358 x: 0.83430344
y: 0.44240227 y: 0.5488517
z: 0.040228914 z: -0.7037824
visibility: 0.73293996 visibility: 0.9987625
presence: 0.9983026 presence: 0.99989784
} }
landmark { landmark {
x: 0.55913407 x: 0.20488566
y: 0.45325255 y: 0.8801585
z: 0.15570506 z: -0.76772463
visibility: 0.6228974 visibility: 0.99855787
presence: 0.998798 presence: 0.99988043
} }
landmark { landmark {
x: 0.5122394 x: 0.87126845
y: 0.42851248 y: 0.54215115
z: 0.022895059 z: -0.7420273
visibility: 0.67662305 visibility: 0.99767953
presence: 0.9976555 presence: 0.99979395
} }
landmark { landmark {
x: 0.5534328 x: 0.21015728
y: 0.45476273 y: 0.8867224
z: 0.13998204 z: -0.8027822
visibility: 0.5879434 visibility: 0.99664575
presence: 0.99810314 presence: 0.9997483
} }
landmark { landmark {
x: 0.5166826 x: 0.8741963
y: 0.42873073 y: 0.5460341
z: 0.013023325 z: -0.7887856
visibility: 0.66849846 visibility: 0.9976641
presence: 0.9973978 presence: 0.9997937
} }
landmark { landmark {
x: 0.54080456 x: 0.22013207
y: 0.45333704 y: 0.88651013
z: 0.13224734 z: -0.85653603
visibility: 0.58104885 visibility: 0.9964618
presence: 0.99810755 presence: 0.9997515
} }
landmark { landmark {
x: 0.5170599 x: 0.8552971
y: 0.43338987 y: 0.5635247
z: 0.03576146 z: -0.7320286
visibility: 0.65676475 visibility: 0.9979176
presence: 0.99781895 presence: 0.9998549
} }
landmark { landmark {
x: 0.550342 x: 0.23674019
y: 0.4529801 y: 0.87909704
z: 0.15014008 z: -0.7946802
visibility: 0.57411015 visibility: 0.9968817
presence: 0.9985139 presence: 0.9998123
} }
landmark { landmark {
x: 0.5236847 x: 0.5296566
y: 0.5765062 y: 0.583189
z: -0.03329975 z: -0.0068905717
visibility: 0.9998833 visibility: 0.99999726
presence: 0.99935263 presence: 0.99999833
} }
landmark { landmark {
x: 0.55076087 x: 0.45126596
y: 0.57722 y: 0.610716
z: 0.033408616 z: 0.0076607587
visibility: 0.99978465 visibility: 0.9999982
presence: 0.9994066 presence: 0.9999993
} }
landmark { landmark {
x: 0.56554604 x: 0.5673191
y: 0.68362844 y: 0.67022914
z: -0.1572319 z: -0.012459015
visibility: 0.8825664 visibility: 0.87660104
presence: 0.99819404 presence: 0.99997973
} }
landmark { landmark {
x: 0.6127089 x: 0.40346304
y: 0.6976384 y: 0.68889683
z: 0.034268316 z: 0.048518207
visibility: 0.6231058 visibility: 0.79370135
presence: 0.9986853 presence: 0.9999901
} }
landmark { landmark {
x: 0.63440466 x: 0.5971223
y: 0.85055786 y: 0.7035845
z: -0.21429145 z: 0.29914334
visibility: 0.93542594 visibility: 0.9536318
presence: 0.99297804 presence: 0.9999622
} }
landmark { landmark {
x: 0.68133575 x: 0.3654526
y: 0.8420663 y: 0.7461876
z: 0.024820065 z: 0.31222725
visibility: 0.8150173 visibility: 0.9724159
presence: 0.994477 presence: 0.99995387
} }
landmark { landmark {
x: 0.65322053 x: 0.6009192
y: 0.8746961 y: 0.711494
z: -0.22213714 z: 0.32301757
visibility: 0.89239687 visibility: 0.8800503
presence: 0.986766 presence: 0.99994063
} }
landmark { landmark {
x: 0.69881815 x: 0.3758035
y: 0.862424 y: 0.7603447
z: 0.018177645 z: 0.3248874
visibility: 0.7516772 visibility: 0.90657604
presence: 0.98905355 presence: 0.99992514
} }
landmark { landmark {
x: 0.62477547 x: 0.60657954
y: 0.9208759 y: 0.71376836
z: -0.31597853 z: 0.16594526
visibility: 0.92574716 visibility: 0.94293
presence: 0.9792296 presence: 0.9998517
} }
landmark { landmark {
x: 0.6807446 x: 0.32244906
y: 0.8746925 y: 0.75465155
z: -0.059982482 z: 0.12916707
visibility: 0.8126682 visibility: 0.95600617
presence: 0.98336893 presence: 0.9998241
} }

View File

@ -0,0 +1,7 @@
# proto-file: mediapipe/framework/formats/rect.proto
# proto-message: NormalizedRect
x_center: 0.5450622
y_center: 0.31605977
width: 0.5196669
height: 0.77911085
rotation: 0.50149304