DetectionTransformationCalculator handles empty input.

PiperOrigin-RevId: 511881969
This commit is contained in:
MediaPipe Team 2023-02-23 14:09:26 -08:00 committed by Copybara-Service
parent 0b989f8c8d
commit 0981367e84
2 changed files with 39 additions and 0 deletions

View File

@ -227,6 +227,9 @@ class DetectionTransformationCalculator : public Node {
std::pair<int, int> image_size = kInImageSize(cc).Get(); std::pair<int, int> image_size = kInImageSize(cc).Get();
std::vector<Detection> transformed_detections; std::vector<Detection> transformed_detections;
LocationData::Format input_location_data_format; LocationData::Format input_location_data_format;
if (kInDetections(cc).IsEmpty() && kInDetection(cc).IsEmpty()) {
return absl::OkStatus();
}
if (kInDetections(cc).IsConnected()) { if (kInDetections(cc).IsConnected()) {
transformed_detections = kInDetections(cc).Visit( transformed_detections = kInDetections(cc).Visit(
[&](const DetectionList& detection_list) { [&](const DetectionList& detection_list) {

View File

@ -161,6 +161,42 @@ TEST(DetectionsTransformationCalculatorTest, WrongLocationDataFormat) {
"RELATIVE_BOUNDING_BOX or BOUNDING_BOX")); "RELATIVE_BOUNDING_BOX or BOUNDING_BOX"));
} }
TEST(DetectionsTransformationCalculatorTest, EmptyDetection) {
CalculatorRunner runner(ParseTextProtoOrDie<CalculatorGraphConfig::Node>(R"pb(
calculator: "DetectionTransformationCalculator"
input_stream: "DETECTION:input_detection"
input_stream: "IMAGE_SIZE:image_size"
output_stream: "PIXEL_DETECTION:output_detection"
)pb"));
std::pair<int, int> image_size({2000, 1000});
runner.MutableInputs()
->Tag(kImageSizeTag)
.packets.push_back(
MakePacket<std::pair<int, int>>(image_size).At(Timestamp(0)));
auto status = runner.Run();
ASSERT_TRUE(status.ok());
}
TEST(DetectionsTransformationCalculatorTest, EmptyDetections) {
CalculatorRunner runner(ParseTextProtoOrDie<CalculatorGraphConfig::Node>(R"pb(
calculator: "DetectionTransformationCalculator"
input_stream: "DETECTIONS:input_detection"
input_stream: "IMAGE_SIZE:image_size"
output_stream: "PIXEL_DETECTIONS:output_detection"
)pb"));
std::pair<int, int> image_size({2000, 1000});
runner.MutableInputs()
->Tag(kImageSizeTag)
.packets.push_back(
MakePacket<std::pair<int, int>>(image_size).At(Timestamp(0)));
auto status = runner.Run();
ASSERT_TRUE(status.ok());
}
TEST(DetectionsTransformationCalculatorTest, TEST(DetectionsTransformationCalculatorTest,
ConvertBoundingBoxToRelativeBoundingBox) { ConvertBoundingBoxToRelativeBoundingBox) {
CalculatorRunner runner(ParseTextProtoOrDie<CalculatorGraphConfig::Node>(R"pb( CalculatorRunner runner(ParseTextProtoOrDie<CalculatorGraphConfig::Node>(R"pb(