Project import generated by Copybara.

GitOrigin-RevId: f4b1fe3f15810450fb6539e733f6a260d3ee082c
This commit is contained in:
MediaPipe Team
2021-09-01 18:15:31 -07:00
committed by jqtang
parent 710fb3de58
commit 6abec128ed
64 changed files with 2384 additions and 161 deletions
+13 -9
View File
@@ -288,7 +288,10 @@ void CalculatorGraphSubmodule(pybind11::module* module) {
calculator_graph.def(
"wait_until_done",
[](CalculatorGraph* self) { RaisePyErrorIfNotOk(self->WaitUntilDone()); },
[](CalculatorGraph* self) {
py::gil_scoped_release gil_release;
RaisePyErrorIfNotOk(self->WaitUntilDone(), /**acquire_gil=*/true);
},
R"doc(Wait for the current run to finish.
A blocking call to wait for the current run to finish (block the current
@@ -313,7 +316,10 @@ void CalculatorGraphSubmodule(pybind11::module* module) {
calculator_graph.def(
"wait_until_idle",
[](CalculatorGraph* self) { RaisePyErrorIfNotOk(self->WaitUntilIdle()); },
[](CalculatorGraph* self) {
py::gil_scoped_release gil_release;
RaisePyErrorIfNotOk(self->WaitUntilIdle(), /**acquire_gil=*/true);
},
R"doc(Wait until the running graph is in the idle mode.
Wait until the running graph is in the idle mode, which is when nothing can
@@ -399,12 +405,9 @@ void CalculatorGraphSubmodule(pybind11::module* module) {
stream_name,
[callback_fn, stream_name](const Packet& packet) {
absl::MutexLock lock(&callback_mutex);
py::gil_scoped_release gil_release;
{
// Acquires GIL before calling Python callback.
py::gil_scoped_acquire gil_acquire;
callback_fn(stream_name, packet);
}
// Acquires GIL before calling Python callback.
py::gil_scoped_acquire gil_acquire;
callback_fn(stream_name, packet);
return absl::OkStatus();
},
observe_timestamp_bounds));
@@ -439,7 +442,8 @@ void CalculatorGraphSubmodule(pybind11::module* module) {
"close",
[](CalculatorGraph* self) {
RaisePyErrorIfNotOk(self->CloseAllPacketSources());
RaisePyErrorIfNotOk(self->WaitUntilDone());
py::gil_scoped_release gil_release;
RaisePyErrorIfNotOk(self->WaitUntilDone(), /**acquire_gil=*/true);
},
R"doc(Close all the input sources and shutdown the graph.)doc");
+11 -3
View File
@@ -19,6 +19,7 @@
#include "mediapipe/framework/port/file_helpers.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/timestamp.h"
#include "pybind11/gil.h"
#include "pybind11/pybind11.h"
namespace mediapipe {
@@ -45,10 +46,17 @@ inline PyObject* StatusCodeToPyError(const ::absl::StatusCode& code) {
}
}
inline void RaisePyErrorIfNotOk(const absl::Status& status) {
inline void RaisePyErrorIfNotOk(const absl::Status& status,
bool acquire_gil = false) {
if (!status.ok()) {
throw RaisePyError(StatusCodeToPyError(status.code()),
status.message().data());
if (acquire_gil) {
py::gil_scoped_acquire acquire;
throw RaisePyError(StatusCodeToPyError(status.code()),
status.message().data());
} else {
throw RaisePyError(StatusCodeToPyError(status.code()),
status.message().data());
}
}
}
+1 -1
View File
@@ -441,7 +441,7 @@ class SolutionBase:
else:
field_label = calculator_options.DESCRIPTOR.fields_by_name[
field_name].label
if field_label is descriptor.FieldDescriptor.LABEL_REPEATED:
if field_label == descriptor.FieldDescriptor.LABEL_REPEATED:
if not isinstance(field_value, Iterable):
raise ValueError(
f'{field_name} is a repeated proto field but the value '
+1 -1
View File
@@ -111,7 +111,7 @@ def draw_detection(
image_rows)
rect_end_point = _normalized_to_pixel_coordinates(
relative_bounding_box.xmin + relative_bounding_box.width,
relative_bounding_box.ymin + +relative_bounding_box.height, image_cols,
relative_bounding_box.ymin + relative_bounding_box.height, image_cols,
image_rows)
cv2.rectangle(image, rect_start_point, rect_end_point,
bbox_drawing_spec.color, bbox_drawing_spec.thickness)