-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mkulakow/mediapipe kfs rest test #2377
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e15ca5
Add unit tests for KFS REST Mediapipe support
michalkulakowski ddefb38
Add deserialization of json string input to OVMS pytensor
michalkulakowski 802e99f
Review fixes
michalkulakowski 3b440fd
Review fixes
michalkulakowski ed96629
Review fixes
michalkulakowski 24361f3
fix
michalkulakowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,10 @@ class HttpRestApiHandlerWithMediapipe : public ::testing::TestWithParam<std::str | |
handler = std::make_unique<HttpRestApiHandler>(server, 5); | ||
} | ||
|
||
void SetUp() { | ||
SetUpServer("/ovms/src/test/mediapipe/config_python_summator.json"); | ||
} | ||
|
||
void TearDown() { | ||
handler.reset(); | ||
server.setShutdownRequest(1); | ||
|
@@ -156,10 +160,10 @@ class HttpRestApiHandlerWithMediapipe : public ::testing::TestWithParam<std::str | |
} | ||
}; | ||
|
||
class HttpRestApiHandlerWithMediapipeForkTest : public HttpRestApiHandlerWithMediapipe { | ||
public: | ||
class HttpRestApiHandlerWithMediapipePassthrough : public HttpRestApiHandlerWithMediapipe { | ||
protected: | ||
void SetUp() { | ||
SetUpServer("/ovms/src/test/mediapipe/config_summator.json"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we remove this json & pbtxt? |
||
SetUpServer("/ovms/src/test/mediapipe/config_mp_pytensor_passthrough.json"); | ||
} | ||
}; | ||
|
||
|
@@ -224,16 +228,14 @@ class HttpRestApiHandlerWithStringModelTest : public HttpRestApiHandlerTest { | |
std::unique_ptr<MockedServer> HttpRestApiHandlerTest::server = nullptr; | ||
std::unique_ptr<std::thread> HttpRestApiHandlerTest::thread = nullptr; | ||
|
||
static void testInference(int headerLength, std::string& request_body, std::unique_ptr<HttpRestApiHandler>& handler) { | ||
std::string request = "/v2/models/mediapipeAdd/versions/1/infer"; | ||
|
||
static void testInference(int headerLength, std::string& request_body, std::unique_ptr<HttpRestApiHandler>& handler, const std::string endpoint = "/v2/models/mediapipeAdd/versions/1/infer") { | ||
std::vector<std::pair<std::string, std::string>> headers; | ||
std::pair<std::string, std::string> binaryInputsHeader{"Inference-Header-Content-Length", std::to_string(headerLength)}; | ||
headers.emplace_back(binaryInputsHeader); | ||
|
||
ovms::HttpRequestComponents comp; | ||
|
||
ASSERT_EQ(handler->parseRequestComponents(comp, "POST", request, headers), ovms::StatusCode::OK); | ||
ASSERT_EQ(handler->parseRequestComponents(comp, "POST", endpoint, headers), ovms::StatusCode::OK); | ||
|
||
std::string response; | ||
ovms::HttpResponseComponents responseComponents; | ||
|
@@ -245,21 +247,96 @@ static void testInference(int headerLength, std::string& request_body, std::uniq | |
|
||
auto output = doc["outputs"].GetArray()[0].GetObject()["data"].GetArray(); | ||
ASSERT_EQ(output.Size(), 10); | ||
|
||
auto datatype = doc["outputs"].GetArray()[0].GetObject()["datatype"].GetString(); | ||
for (auto& data : output) { | ||
ASSERT_EQ(data.GetFloat(), 2); | ||
if (strcmp(datatype, "BOOL") == 0) { | ||
ASSERT_EQ(data.GetBool(), true); | ||
} else { | ||
ASSERT_EQ(data.GetFloat(), 2); | ||
} | ||
} | ||
} | ||
|
||
static void testInferenceNegative(int headerLength, std::string& request_body, std::unique_ptr<HttpRestApiHandler>& handler, ovms::Status processorStatus) { | ||
std::string request = "/v2/models/mediapipeAdd/versions/1/infer"; | ||
|
||
std::vector<std::pair<std::string, std::string>> headers; | ||
std::pair<std::string, std::string> binaryInputsHeader{"Inference-Header-Content-Length", std::to_string(headerLength)}; | ||
headers.emplace_back(binaryInputsHeader); | ||
|
||
ovms::HttpRequestComponents comp; | ||
|
||
ASSERT_EQ(handler->parseRequestComponents(comp, "POST", request, headers), ovms::StatusCode::OK); | ||
|
||
std::string response; | ||
ovms::HttpResponseComponents responseComponents; | ||
ASSERT_EQ(handler->dispatchToProcessor(request_body, &response, comp, responseComponents), processorStatus); | ||
} | ||
|
||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wnarrowing" | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipeForkTest, inferRequestFP32) { | ||
TEST_P(HttpRestApiHandlerWithMediapipe, inferRequestWithSupportedPrecision) { | ||
std::string datatype = GetParam(); | ||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"" + datatype + "\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"" + datatype + "\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
int headerLength = request_body.length(); | ||
|
||
testInference(headerLength, request_body, handler); | ||
} | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipe, inferRequestFP16) { | ||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"FP16\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"FP16\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
int headerLength = request_body.length(); | ||
// Supported only when data is in binary extension | ||
testInferenceNegative(headerLength, request_body, handler, ovms::StatusCode::REST_COULD_NOT_PARSE_INPUT); | ||
} | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipe, inferRequestBF16) { | ||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"BF16\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"BF16\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
int headerLength = request_body.length(); | ||
// Supported only when data is in binary extension | ||
testInferenceNegative(headerLength, request_body, handler, ovms::StatusCode::REST_COULD_NOT_PARSE_INPUT); | ||
} | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipe, inferRequestBOOL) { | ||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"BOOL\", \"data\": [true,true,true,true,true,true,true,true,true,true]}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"BOOL\", \"data\": [true,true,true,true,true,true,true,true,true,true]}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
int headerLength = request_body.length(); | ||
|
||
testInference(headerLength, request_body, handler); | ||
} | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipe, inferRequestFP32DataInJsonAndBinaryExtension) { | ||
// 10 element array of floats: [1,1,1,1,1,1,1,1,1,1] | ||
std::string binaryData{0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F}; | ||
|
||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"FP32\",\"parameters\":{\"binary_data_size\":40}}"; | ||
std::string param = ",\"parameters\":{\"binary_data_output\":true}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"FP32\", \"data\": [1,1,1,1,1,1,1,1,1,1]}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
int headerLength = request_body.length(); | ||
|
||
request_body += binaryData; | ||
request_body += binaryData; | ||
|
||
testInferenceNegative(headerLength, request_body, handler, ovms::StatusCode::INVALID_MESSAGE_STRUCTURE); | ||
} | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipe, inferRequestFP32BinaryExtension) { | ||
std::string binaryData{0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F}; | ||
|
||
std::string tensor1 = "{\"name\":\"in1\",\"shape\":[1,10],\"datatype\":\"FP32\",\"parameters\":{\"binary_data_size\":40}}"; | ||
std::string tensor2 = "{\"name\":\"in2\",\"shape\":[1,10],\"datatype\":\"FP32\",\"parameters\":{\"binary_data_size\":40}}"; | ||
|
||
std::string request_body = "{\"inputs\":[" + tensor1 + ", " + tensor2 + "]}"; | ||
|
@@ -271,6 +348,40 @@ TEST_F(HttpRestApiHandlerWithMediapipeForkTest, inferRequestFP32) { | |
testInference(headerLength, request_body, handler); | ||
} | ||
|
||
std::vector<std::string> supportedDatatypes = {"FP32", "FP64", "INT8", "UINT8", "INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64"}; | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
TestDeserialize, | ||
HttpRestApiHandlerWithMediapipe, | ||
::testing::ValuesIn(supportedDatatypes), | ||
[](const ::testing::TestParamInfo<HttpRestApiHandlerWithMediapipe::ParamType>& info) { | ||
return info.param; | ||
}); | ||
|
||
TEST_F(HttpRestApiHandlerWithMediapipePassthrough, inferRequestBYTES) { | ||
std::string request = "/v2/models/mpPytensorPassthrough/versions/1/infer"; | ||
std::string request_body = "{\"inputs\":[{\"name\":\"in\",\"shape\":[3],\"datatype\":\"BYTES\", \"data\": [\"abc\", \"def\", \"ghi\"]}]}"; | ||
ovms::HttpRequestComponents comp; | ||
|
||
ASSERT_EQ(handler->parseRequestComponents(comp, "POST", request), ovms::StatusCode::OK); | ||
std::string response; | ||
ovms::HttpResponseComponents responseComponents; | ||
ASSERT_EQ(handler->dispatchToProcessor(request_body, &response, comp, responseComponents), ovms::StatusCode::OK); | ||
|
||
rapidjson::Document doc; | ||
doc.Parse(response.c_str()); | ||
ASSERT_FALSE(doc.HasParseError()); | ||
ASSERT_TRUE(doc["outputs"][0].GetObject().HasMember("data")); | ||
ASSERT_TRUE(doc["outputs"][0].GetObject()["data"].IsArray()); | ||
auto output = doc["outputs"].GetArray()[0].GetObject()["data"].GetArray(); | ||
std::vector<std::string> expectedStrings{"abc", "def", "ghi"}; | ||
ASSERT_EQ(output.Size(), expectedStrings.size()); | ||
for (size_t i = 0; i < expectedStrings.size(); i++) { | ||
ASSERT_TRUE(output[i].IsString()); | ||
ASSERT_EQ(output[i].GetString(), expectedStrings[i]); | ||
} | ||
} | ||
|
||
#pragma GCC diagnostic pop | ||
|
||
TEST_F(HttpRestApiHandlerTest, MetricsParameters) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"model_config_list": [], | ||
"mediapipe_config_list": [ | ||
{ | ||
"name":"mpPytensorPassthrough", | ||
"graph_path":"/ovms/src/test/mediapipe/graphpytensorpassthrough.pbtxt" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"model_config_list": [], | ||
"mediapipe_config_list": [ | ||
{ | ||
"name":"mediapipeAdd", | ||
"graph_path":"/ovms/src/test/mediapipe/graphpythonsummator.pbtxt" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only below as a buffer to copy from. Do we need that? If so, can we make it const and replace following
contents.size()
calls?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be const?