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 kPortraitImage[] = "pose.jpg";
constexpr char kPoseExpectedDetection[] = "pose_expected_detection.pbtxt";
constexpr char kPoseExpectedExpandedRect[] =
"pose_expected_expanded_rect.pbtxt";
constexpr char kImageTag[] = "IMAGE";
constexpr char kImageName[] = "image";
@ -72,8 +74,11 @@ constexpr char kNormRectTag[] = "NORM_RECT";
constexpr char kNormRectName[] = "norm_rect";
constexpr char kDetectionsTag[] = "DETECTIONS";
constexpr char kDetectionsName[] = "detections";
constexpr char kExpandedPoseRectsTag[] = "EXPANDED_POSE_RECTS";
constexpr char kExpandedPoseRectsName[] = "expanded_pose_rects";
constexpr float kPoseDetectionMaxDiff = 0.01;
constexpr float kExpandedPoseRectMaxDiff = 0.01;
// Helper function to create a TaskRunner.
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) >>
graph[Output<std::vector<Detection>>(kDetectionsTag)];
pose_detector_graph.Out(kExpandedPoseRectsTag)
.SetName(kExpandedPoseRectsName) >>
graph[Output<std::vector<NormalizedRect>>(kExpandedPoseRectsTag)];
return TaskRunner::Create(
graph.GetConfig(), std::make_unique<core::MediaPipeBuiltinOpResolver>());
}
@ -111,6 +120,14 @@ Detection GetExpectedPoseDetectionResult(absl::string_view file_name) {
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 {
// The name of this test, for convenience when displaying test results.
std::string test_name;
@ -119,7 +136,9 @@ struct TestParams {
// The filename of test image.
std::string test_image_name;
// 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> {};
@ -144,16 +163,27 @@ TEST_P(PoseDetectorGraphTest, Succeed) {
(*output_packets)[kDetectionsName].Get<std::vector<Detection>>();
EXPECT_THAT(pose_detections, Pointwise(Approximately(Partially(EqualsProto()),
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(
PoseDetectorGraphTest, PoseDetectorGraphTest,
Values(TestParams{.test_name = "DetectPose",
Values(TestParams{
.test_name = "DetectPose",
.pose_detection_model_name = kPoseDetectionModel,
.test_image_name = kPortraitImage,
.expected_result = {GetExpectedPoseDetectionResult(
kPoseExpectedDetection)}}),
.expected_detection = {GetExpectedPoseDetectionResult(
kPoseExpectedDetection)},
.expected_expanded_pose_rect = {GetExpectedExpandedPoseRect(
kPoseExpectedExpandedRect)}}),
[](const TestParamInfo<PoseDetectorGraphTest::ParamType>& info) {
return info.param.test_name;
});

View File

@ -319,6 +319,8 @@ TEST_P(MultiPoseLandmarkerTest, Succeeds) {
GetParam().expected_landmark_lists));
}
// 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(
PoseLandmarkerTest, PoseLandmarkerTest,
Values(
@ -326,7 +328,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "PoseLandmarkerLiteModel",
.input_model_name = kPoseLandmarkerLiteModel,
.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_landmarks =
GetExpectedLandmarkList(kExpectedPoseLandmarksFilename),
@ -335,7 +338,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "PoseLandmarkerLiteModelNoPose",
.input_model_name = kPoseLandmarkerLiteModel,
.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_landmarks = std::nullopt,
.landmarks_diff_threshold = kLiteModelFractionDiff}),
@ -349,7 +353,8 @@ INSTANTIATE_TEST_SUITE_P(
.test_name = "MultiPoseLandmarkerLiteModel",
.input_model_name = kPoseLandmarkerLiteModel,
.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_landmark_lists = {GetExpectedLandmarkList(
kExpectedPoseLandmarksFilename)},

View File

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

View File

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