Internal change
PiperOrigin-RevId: 516520860
This commit is contained in:
		
							parent
							
								
									46ba1d8051
								
							
						
					
					
						commit
						bc641a22a8
					
				| 
						 | 
					@ -108,31 +108,31 @@ std::vector<DetectionProto>
 | 
				
			||||||
GenerateMobileSsdNoImageResizingFullExpectedResults() {
 | 
					GenerateMobileSsdNoImageResizingFullExpectedResults() {
 | 
				
			||||||
  return {ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					  return {ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
            label: "cat"
 | 
					            label: "cat"
 | 
				
			||||||
            score: 0.6328125
 | 
					            score: 0.6210937
 | 
				
			||||||
            location_data {
 | 
					            location_data {
 | 
				
			||||||
              format: BOUNDING_BOX
 | 
					              format: BOUNDING_BOX
 | 
				
			||||||
              bounding_box { xmin: 14 ymin: 197 width: 98 height: 99 }
 | 
					              bounding_box { xmin: 15 ymin: 197 width: 98 height: 99 }
 | 
				
			||||||
            })pb"),
 | 
					            })pb"),
 | 
				
			||||||
          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
            label: "cat"
 | 
					            label: "cat"
 | 
				
			||||||
            score: 0.59765625
 | 
					            score: 0.609375
 | 
				
			||||||
            location_data {
 | 
					            location_data {
 | 
				
			||||||
              format: BOUNDING_BOX
 | 
					              format: BOUNDING_BOX
 | 
				
			||||||
              bounding_box { xmin: 151 ymin: 78 width: 104 height: 223 }
 | 
					              bounding_box { xmin: 150 ymin: 78 width: 104 height: 223 }
 | 
				
			||||||
            })pb"),
 | 
					            })pb"),
 | 
				
			||||||
          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
            label: "cat"
 | 
					            label: "cat"
 | 
				
			||||||
            score: 0.5
 | 
					            score: 0.5
 | 
				
			||||||
            location_data {
 | 
					            location_data {
 | 
				
			||||||
              format: BOUNDING_BOX
 | 
					              format: BOUNDING_BOX
 | 
				
			||||||
              bounding_box { xmin: 65 ymin: 199 width: 41 height: 101 }
 | 
					              bounding_box { xmin: 64 ymin: 199 width: 42 height: 101 }
 | 
				
			||||||
            })pb"),
 | 
					            })pb"),
 | 
				
			||||||
          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					          ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
            label: "dog"
 | 
					            label: "dog"
 | 
				
			||||||
            score: 0.48828125
 | 
					            score: 0.5
 | 
				
			||||||
            location_data {
 | 
					            location_data {
 | 
				
			||||||
              format: BOUNDING_BOX
 | 
					              format: BOUNDING_BOX
 | 
				
			||||||
              bounding_box { xmin: 12 ymin: 110 width: 153 height: 193 }
 | 
					              bounding_box { xmin: 14 ymin: 110 width: 153 height: 193 }
 | 
				
			||||||
            })pb")};
 | 
					            })pb")};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -268,7 +268,7 @@ TEST_F(CreateFromOptionsTest, FailsWithIllegalCallbackInImageOrVideoMode) {
 | 
				
			||||||
    options->running_mode = running_mode;
 | 
					    options->running_mode = running_mode;
 | 
				
			||||||
    options->result_callback =
 | 
					    options->result_callback =
 | 
				
			||||||
        [](absl::StatusOr<ObjectDetectorResult> detections, const Image& image,
 | 
					        [](absl::StatusOr<ObjectDetectorResult> detections, const Image& image,
 | 
				
			||||||
           int64 timestamp_ms) {};
 | 
					           int64_t timestamp_ms) {};
 | 
				
			||||||
    absl::StatusOr<std::unique_ptr<ObjectDetector>> object_detector =
 | 
					    absl::StatusOr<std::unique_ptr<ObjectDetector>> object_detector =
 | 
				
			||||||
        ObjectDetector::Create(std::move(options));
 | 
					        ObjectDetector::Create(std::move(options));
 | 
				
			||||||
    EXPECT_EQ(object_detector.status().code(),
 | 
					    EXPECT_EQ(object_detector.status().code(),
 | 
				
			||||||
| 
						 | 
					@ -381,28 +381,28 @@ TEST_F(ImageModeTest, Succeeds) {
 | 
				
			||||||
             score: 0.69921875
 | 
					             score: 0.69921875
 | 
				
			||||||
             location_data {
 | 
					             location_data {
 | 
				
			||||||
               format: BOUNDING_BOX
 | 
					               format: BOUNDING_BOX
 | 
				
			||||||
               bounding_box { xmin: 608 ymin: 161 width: 381 height: 439 }
 | 
					               bounding_box { xmin: 608 ymin: 164 width: 381 height: 432 }
 | 
				
			||||||
             })pb"),
 | 
					             })pb"),
 | 
				
			||||||
           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
             label: "cat"
 | 
					             label: "cat"
 | 
				
			||||||
             score: 0.64453125
 | 
					             score: 0.65625
 | 
				
			||||||
             location_data {
 | 
					             location_data {
 | 
				
			||||||
               format: BOUNDING_BOX
 | 
					               format: BOUNDING_BOX
 | 
				
			||||||
               bounding_box { xmin: 60 ymin: 398 width: 386 height: 196 }
 | 
					               bounding_box { xmin: 57 ymin: 398 width: 386 height: 196 }
 | 
				
			||||||
             })pb"),
 | 
					             })pb"),
 | 
				
			||||||
           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
             label: "cat"
 | 
					             label: "cat"
 | 
				
			||||||
             score: 0.51171875
 | 
					             score: 0.51171875
 | 
				
			||||||
             location_data {
 | 
					             location_data {
 | 
				
			||||||
               format: BOUNDING_BOX
 | 
					               format: BOUNDING_BOX
 | 
				
			||||||
               bounding_box { xmin: 256 ymin: 395 width: 173 height: 202 }
 | 
					               bounding_box { xmin: 256 ymin: 394 width: 173 height: 202 }
 | 
				
			||||||
             })pb"),
 | 
					             })pb"),
 | 
				
			||||||
           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					           ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
             label: "cat"
 | 
					             label: "cat"
 | 
				
			||||||
             score: 0.48828125
 | 
					             score: 0.48828125
 | 
				
			||||||
             location_data {
 | 
					             location_data {
 | 
				
			||||||
               format: BOUNDING_BOX
 | 
					               format: BOUNDING_BOX
 | 
				
			||||||
               bounding_box { xmin: 362 ymin: 191 width: 325 height: 419 }
 | 
					               bounding_box { xmin: 360 ymin: 195 width: 330 height: 412 }
 | 
				
			||||||
             })pb")}));
 | 
					             })pb")}));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -484,10 +484,10 @@ TEST_F(ImageModeTest, SucceedsWithScoreCalibration) {
 | 
				
			||||||
      results,
 | 
					      results,
 | 
				
			||||||
      ConvertToDetectionResult({ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
					      ConvertToDetectionResult({ParseTextProtoOrDie<DetectionProto>(R"pb(
 | 
				
			||||||
        label: "cat"
 | 
					        label: "cat"
 | 
				
			||||||
        score: 0.6531269142
 | 
					        score: 0.650467276
 | 
				
			||||||
        location_data {
 | 
					        location_data {
 | 
				
			||||||
          format: BOUNDING_BOX
 | 
					          format: BOUNDING_BOX
 | 
				
			||||||
          bounding_box { xmin: 14 ymin: 197 width: 98 height: 99 }
 | 
					          bounding_box { xmin: 15 ymin: 197 width: 98 height: 99 }
 | 
				
			||||||
        })pb")}));
 | 
					        })pb")}));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -507,9 +507,9 @@ TEST_F(ImageModeTest, SucceedsWithScoreThresholdOption) {
 | 
				
			||||||
      GenerateMobileSsdNoImageResizingFullExpectedResults();
 | 
					      GenerateMobileSsdNoImageResizingFullExpectedResults();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ExpectApproximatelyEqual(
 | 
					  ExpectApproximatelyEqual(
 | 
				
			||||||
      results, ConvertToDetectionResult({full_expected_results[0],
 | 
					      results, ConvertToDetectionResult(
 | 
				
			||||||
                                         full_expected_results[1],
 | 
					                   {full_expected_results[0], full_expected_results[1],
 | 
				
			||||||
                                         full_expected_results[2]}));
 | 
					                    full_expected_results[2], full_expected_results[3]}));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_F(ImageModeTest, SucceedsWithMaxResultsOption) {
 | 
					TEST_F(ImageModeTest, SucceedsWithMaxResultsOption) {
 | 
				
			||||||
| 
						 | 
					@ -685,7 +685,7 @@ TEST_F(LiveStreamModeTest, FailsWithCallingWrongMethod) {
 | 
				
			||||||
      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
					      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
				
			||||||
  options->running_mode = core::RunningMode::LIVE_STREAM;
 | 
					  options->running_mode = core::RunningMode::LIVE_STREAM;
 | 
				
			||||||
  options->result_callback = [](absl::StatusOr<ObjectDetectorResult> detections,
 | 
					  options->result_callback = [](absl::StatusOr<ObjectDetectorResult> detections,
 | 
				
			||||||
                                const Image& image, int64 timestamp_ms) {};
 | 
					                                const Image& image, int64_t timestamp_ms) {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  MP_ASSERT_OK_AND_ASSIGN(std::unique_ptr<ObjectDetector> object_detector,
 | 
					  MP_ASSERT_OK_AND_ASSIGN(std::unique_ptr<ObjectDetector> object_detector,
 | 
				
			||||||
                          ObjectDetector::Create(std::move(options)));
 | 
					                          ObjectDetector::Create(std::move(options)));
 | 
				
			||||||
| 
						 | 
					@ -716,7 +716,7 @@ TEST_F(LiveStreamModeTest, FailsWithOutOfOrderInputTimestamps) {
 | 
				
			||||||
  options->base_options.model_asset_path =
 | 
					  options->base_options.model_asset_path =
 | 
				
			||||||
      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
					      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
				
			||||||
  options->result_callback = [](absl::StatusOr<ObjectDetectorResult> detections,
 | 
					  options->result_callback = [](absl::StatusOr<ObjectDetectorResult> detections,
 | 
				
			||||||
                                const Image& image, int64 timestamp_ms) {};
 | 
					                                const Image& image, int64_t timestamp_ms) {};
 | 
				
			||||||
  MP_ASSERT_OK_AND_ASSIGN(std::unique_ptr<ObjectDetector> object_detector,
 | 
					  MP_ASSERT_OK_AND_ASSIGN(std::unique_ptr<ObjectDetector> object_detector,
 | 
				
			||||||
                          ObjectDetector::Create(std::move(options)));
 | 
					                          ObjectDetector::Create(std::move(options)));
 | 
				
			||||||
  MP_ASSERT_OK(object_detector->DetectAsync(image, 1));
 | 
					  MP_ASSERT_OK(object_detector->DetectAsync(image, 1));
 | 
				
			||||||
| 
						 | 
					@ -742,13 +742,13 @@ TEST_F(LiveStreamModeTest, Succeeds) {
 | 
				
			||||||
  options->running_mode = core::RunningMode::LIVE_STREAM;
 | 
					  options->running_mode = core::RunningMode::LIVE_STREAM;
 | 
				
			||||||
  std::vector<ObjectDetectorResult> detection_results;
 | 
					  std::vector<ObjectDetectorResult> detection_results;
 | 
				
			||||||
  std::vector<std::pair<int, int>> image_sizes;
 | 
					  std::vector<std::pair<int, int>> image_sizes;
 | 
				
			||||||
  std::vector<int64> timestamps;
 | 
					  std::vector<int64_t> timestamps;
 | 
				
			||||||
  options->base_options.model_asset_path =
 | 
					  options->base_options.model_asset_path =
 | 
				
			||||||
      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
					      JoinPath("./", kTestDataDirectory, kMobileSsdWithMetadata);
 | 
				
			||||||
  options->result_callback =
 | 
					  options->result_callback =
 | 
				
			||||||
      [&detection_results, &image_sizes, ×tamps](
 | 
					      [&detection_results, &image_sizes, ×tamps](
 | 
				
			||||||
          absl::StatusOr<ObjectDetectorResult> detections, const Image& image,
 | 
					          absl::StatusOr<ObjectDetectorResult> detections, const Image& image,
 | 
				
			||||||
          int64 timestamp_ms) {
 | 
					          int64_t timestamp_ms) {
 | 
				
			||||||
        MP_ASSERT_OK(detections.status());
 | 
					        MP_ASSERT_OK(detections.status());
 | 
				
			||||||
        detection_results.push_back(std::move(detections).value());
 | 
					        detection_results.push_back(std::move(detections).value());
 | 
				
			||||||
        image_sizes.push_back({image.width(), image.height()});
 | 
					        image_sizes.push_back({image.width(), image.height()});
 | 
				
			||||||
| 
						 | 
					@ -775,7 +775,7 @@ TEST_F(LiveStreamModeTest, Succeeds) {
 | 
				
			||||||
    EXPECT_EQ(image_size.first, image.width());
 | 
					    EXPECT_EQ(image_size.first, image.width());
 | 
				
			||||||
    EXPECT_EQ(image_size.second, image.height());
 | 
					    EXPECT_EQ(image_size.second, image.height());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  int64 timestamp_ms = -1;
 | 
					  int64_t timestamp_ms = -1;
 | 
				
			||||||
  for (const auto& timestamp : timestamps) {
 | 
					  for (const auto& timestamp : timestamps) {
 | 
				
			||||||
    EXPECT_GT(timestamp, timestamp_ms);
 | 
					    EXPECT_GT(timestamp, timestamp_ms);
 | 
				
			||||||
    timestamp_ms = timestamp;
 | 
					    timestamp_ms = timestamp;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,48 +42,62 @@ _RUNNING_MODE = running_mode_module.VisionTaskRunningMode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_MODEL_FILE = 'coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.tflite'
 | 
					_MODEL_FILE = 'coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.tflite'
 | 
				
			||||||
_IMAGE_FILE = 'cats_and_dogs.jpg'
 | 
					_IMAGE_FILE = 'cats_and_dogs.jpg'
 | 
				
			||||||
_EXPECTED_DETECTION_RESULT = _DetectionResult(detections=[
 | 
					_EXPECTED_DETECTION_RESULT = _DetectionResult(
 | 
				
			||||||
    _Detection(
 | 
					    detections=[
 | 
				
			||||||
        bounding_box=_BoundingBox(
 | 
					        _Detection(
 | 
				
			||||||
            origin_x=608, origin_y=161, width=381, height=439),
 | 
					            bounding_box=_BoundingBox(
 | 
				
			||||||
        categories=[
 | 
					                origin_x=608, origin_y=161, width=381, height=439
 | 
				
			||||||
            _Category(
 | 
					            ),
 | 
				
			||||||
                index=None,
 | 
					            categories=[
 | 
				
			||||||
                score=0.69921875,
 | 
					                _Category(
 | 
				
			||||||
                display_name=None,
 | 
					                    index=None,
 | 
				
			||||||
                category_name='cat')
 | 
					                    score=0.69921875,
 | 
				
			||||||
        ]),
 | 
					                    display_name=None,
 | 
				
			||||||
    _Detection(
 | 
					                    category_name='cat',
 | 
				
			||||||
        bounding_box=_BoundingBox(
 | 
					                )
 | 
				
			||||||
            origin_x=60, origin_y=398, width=386, height=196),
 | 
					            ],
 | 
				
			||||||
        categories=[
 | 
					        ),
 | 
				
			||||||
            _Category(
 | 
					        _Detection(
 | 
				
			||||||
                index=None,
 | 
					            bounding_box=_BoundingBox(
 | 
				
			||||||
                score=0.64453125,
 | 
					                origin_x=60, origin_y=398, width=386, height=196
 | 
				
			||||||
                display_name=None,
 | 
					            ),
 | 
				
			||||||
                category_name='cat')
 | 
					            categories=[
 | 
				
			||||||
        ]),
 | 
					                _Category(
 | 
				
			||||||
    _Detection(
 | 
					                    index=None,
 | 
				
			||||||
        bounding_box=_BoundingBox(
 | 
					                    score=0.64453125,
 | 
				
			||||||
            origin_x=256, origin_y=395, width=173, height=202),
 | 
					                    display_name=None,
 | 
				
			||||||
        categories=[
 | 
					                    category_name='cat',
 | 
				
			||||||
            _Category(
 | 
					                )
 | 
				
			||||||
                index=None,
 | 
					            ],
 | 
				
			||||||
                score=0.51171875,
 | 
					        ),
 | 
				
			||||||
                display_name=None,
 | 
					        _Detection(
 | 
				
			||||||
                category_name='cat')
 | 
					            bounding_box=_BoundingBox(
 | 
				
			||||||
        ]),
 | 
					                origin_x=256, origin_y=395, width=173, height=202
 | 
				
			||||||
    _Detection(
 | 
					            ),
 | 
				
			||||||
        bounding_box=_BoundingBox(
 | 
					            categories=[
 | 
				
			||||||
            origin_x=362, origin_y=191, width=325, height=419),
 | 
					                _Category(
 | 
				
			||||||
        categories=[
 | 
					                    index=None,
 | 
				
			||||||
            _Category(
 | 
					                    score=0.51171875,
 | 
				
			||||||
                index=None,
 | 
					                    display_name=None,
 | 
				
			||||||
                score=0.48828125,
 | 
					                    category_name='cat',
 | 
				
			||||||
                display_name=None,
 | 
					                )
 | 
				
			||||||
                category_name='cat')
 | 
					            ],
 | 
				
			||||||
        ])
 | 
					        ),
 | 
				
			||||||
])
 | 
					        _Detection(
 | 
				
			||||||
 | 
					            bounding_box=_BoundingBox(
 | 
				
			||||||
 | 
					                origin_x=362, origin_y=191, width=325, height=419
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					            categories=[
 | 
				
			||||||
 | 
					                _Category(
 | 
				
			||||||
 | 
					                    index=None,
 | 
				
			||||||
 | 
					                    score=0.48828125,
 | 
				
			||||||
 | 
					                    display_name=None,
 | 
				
			||||||
 | 
					                    category_name='cat',
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
_ALLOW_LIST = ['cat', 'dog']
 | 
					_ALLOW_LIST = ['cat', 'dog']
 | 
				
			||||||
_DENY_LIST = ['cat']
 | 
					_DENY_LIST = ['cat']
 | 
				
			||||||
_SCORE_THRESHOLD = 0.3
 | 
					_SCORE_THRESHOLD = 0.3
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user