Skip to content

Commit 6abec12

Browse files
MediaPipe Teamjqtang
MediaPipe Team
authored and
jqtang
committed
Project import generated by Copybara.
GitOrigin-RevId: f4b1fe3f15810450fb6539e733f6a260d3ee082c
1 parent 710fb3d commit 6abec12

File tree

64 files changed

+2384
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2384
-161
lines changed

Diff for: WORKSPACE

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ http_archive(
157157
http_archive(
158158
name = "pybind11",
159159
urls = [
160-
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/pybind/pybind11/archive/v2.4.3.tar.gz",
161-
"https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz",
160+
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/pybind/pybind11/archive/v2.7.1.tar.gz",
161+
"https://github.com/pybind/pybind11/archive/v2.7.1.tar.gz",
162162
],
163-
sha256 = "1eed57bc6863190e35637290f97a20c81cfe4d9090ac0a24f3bbf08f265eb71d",
164-
strip_prefix = "pybind11-2.4.3",
163+
sha256 = "616d1c42e4cf14fa27b2a4ff759d7d7b33006fdc5ad8fd603bb2c22622f27020",
164+
strip_prefix = "pybind11-2.7.1",
165165
build_file = "@pybind11_bazel//:pybind11.BUILD",
166166
)
167167

Diff for: docs/getting_started/hello_world_ios.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ bazel to build the iOS application. The content of the
113113
5. `Main.storyboard` and `Launch.storyboard`
114114
6. `Assets.xcassets` directory.
115115

116+
Note: In newer versions of Xcode, you may see additional files `SceneDelegate.h`
117+
and `SceneDelegate.m`. Make sure to copy them too and add them to the `BUILD`
118+
file mentioned below.
119+
116120
Copy these files to a directory named `HelloWorld` to a location that can access
117121
the MediaPipe source code. For example, the source code of the application that
118122
we will build in this tutorial is located in
@@ -247,6 +251,12 @@ We need to get frames from the `_cameraSource` into our application
247251
`MPPInputSourceDelegate`. So our application `ViewController` can be a delegate
248252
of `_cameraSource`.
249253

254+
Update the interface definition of `ViewController` accordingly:
255+
256+
```
257+
@interface ViewController () <MPPInputSourceDelegate>
258+
```
259+
250260
To handle camera setup and process incoming frames, we should use a queue
251261
different from the main queue. Add the following to the implementation block of
252262
the `ViewController`:
@@ -288,6 +298,12 @@ utility called `MPPLayerRenderer` to display images on the screen. This utility
288298
can be used to display `CVPixelBufferRef` objects, which is the type of the
289299
images provided by `MPPCameraInputSource` to its delegates.
290300

301+
In `ViewController.m`, add the following import line:
302+
303+
```
304+
#import "mediapipe/objc/MPPLayerRenderer.h"
305+
```
306+
291307
To display images of the screen, we need to add a new `UIView` object called
292308
`_liveView` to the `ViewController`.
293309

@@ -411,6 +427,12 @@ Objective-C++.
411427

412428
### Use the graph in `ViewController`
413429

430+
In `ViewController.m`, add the following import line:
431+
432+
```
433+
#import "mediapipe/objc/MPPGraph.h"
434+
```
435+
414436
Declare a static constant with the name of the graph, the input stream and the
415437
output stream:
416438

@@ -549,6 +571,12 @@ method to receive packets on this output stream and display them on the screen:
549571
}
550572
```
551573

574+
Update the interface definition of `ViewController` with `MPPGraphDelegate`:
575+
576+
```
577+
@interface ViewController () <MPPGraphDelegate, MPPInputSourceDelegate>
578+
```
579+
552580
And that is all! Build and run the app on your iOS device. You should see the
553581
results of running the edge detection graph on a live video feed. Congrats!
554582

@@ -560,5 +588,5 @@ appropriate `BUILD` file dependencies for the edge detection graph.
560588

561589
[Bazel]:https://bazel.build/
562590
[`edge_detection_mobile_gpu.pbtxt`]:https://github.com/google/mediapipe/tree/master/mediapipe/graphs/edge_detection/edge_detection_mobile_gpu.pbtxt
563-
[common]:(https://github.com/google/mediapipe/tree/master/mediapipe/examples/ios/common)
564-
[helloworld]:(https://github.com/google/mediapipe/tree/master/mediapipe/examples/ios/helloworld)
591+
[common]:https://github.com/google/mediapipe/tree/master/mediapipe/examples/ios/common
592+
[helloworld]:https://github.com/google/mediapipe/tree/master/mediapipe/examples/ios/helloworld

Diff for: docs/getting_started/install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ This will use a Docker image that will isolate mediapipe's installation from the
796796
```bash
797797
$ docker run -it --name mediapipe mediapipe:latest
798798
799-
root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
799+
root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazelisk run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
800800
801801
# Should print:
802802
# Hello World!

Diff for: docs/solutions/objectron.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ Example app bounding boxes are rendered with [GlAnimationOverlayCalculator](http
529529
> ```
530530
> and then run
531531
>
532-
> ```build
532+
> ```bash
533533
> bazel run -c opt mediapipe/graphs/object_detection_3d/obj_parser:ObjParser -- input_dir=[INTERMEDIATE_OUTPUT_DIR] output_dir=[OUTPUT_DIR]
534534
> ```
535535
> INPUT_DIR should be the folder with initial asset .obj files to be processed,

Diff for: docs/solutions/pose.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Optionally, MediaPipe Pose can predicts a full-body
141141
Please find more detail in the
142142
[BlazePose Google AI Blog](https://ai.googleblog.com/2020/08/on-device-real-time-body-pose-tracking.html),
143143
this [paper](https://arxiv.org/abs/2006.10204),
144-
[the model card](./models.md#pose) and the [Output](#Output) section below.
144+
[the model card](./models.md#pose) and the [Output](#output) section below.
145145

146146
## Solution APIs
147147

@@ -281,8 +281,8 @@ with mp_pose.Pose(
281281
continue
282282
print(
283283
f'Nose coordinates: ('
284-
f'{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].x * image_width}, '
285-
f'{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].y * image_height})'
284+
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.NOSE].x * image_width}, '
285+
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.NOSE].y * image_height})'
286286
)
287287

288288
annotated_image = image.copy()
@@ -369,6 +369,7 @@ Supported configuration options:
369369
<div class="container">
370370
<video class="input_video"></video>
371371
<canvas class="output_canvas" width="1280px" height="720px"></canvas>
372+
<div class="landmark-grid-container"></div>
372373
</div>
373374
</body>
374375
</html>

Diff for: docs/solutions/selfie_segmentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ to visualize its associated subgraphs, please see
262262
[(or download prebuilt ARM64 APK)](https://drive.google.com/file/d/1DoeyGzMmWUsjfVgZfGGecrn7GKzYcEAo/view?usp=sharing)
263263
[`mediapipe/examples/android/src/java/com/google/mediapipe/apps/selfiesegmentationgpu:selfiesegmentationgpu`](https://github.com/google/mediapipe/tree/master/mediapipe/examples/android/src/java/com/google/mediapipe/apps/selfiesegmentationgpu/BUILD)
264264
* iOS target:
265-
[`mediapipe/examples/ios/selfiesegmentationgpu:SelfieSegmentationGpuApp`](http:/mediapipe/examples/ios/selfiesegmentationgpu/BUILD)
265+
[`mediapipe/examples/ios/selfiesegmentationgpu:SelfieSegmentationGpuApp`](https://github.com/google/mediapipe/tree/master/mediapipe/examples/ios/selfiesegmentationgpu/BUILD)
266266

267267
### Desktop
268268

Diff for: docs/solutions/solutions.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ has_toc: false
1313
{:toc}
1414
---
1515

16+
MediaPipe offers open source cross-platform, customizable ML solutions for live
17+
and streaming media.
18+
1619
<!-- []() in the first cell is needed to preserve table formatting in GitHub Pages. -->
1720
<!-- Whenever this table is updated, paste a copy to ../external_index.md. -->
1821

Diff for: mediapipe/calculators/core/begin_loop_calculator.cc

+5
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ REGISTER_CALCULATOR(BeginLoopDetectionCalculator);
4242
typedef BeginLoopCalculator<std::vector<Matrix>> BeginLoopMatrixCalculator;
4343
REGISTER_CALCULATOR(BeginLoopMatrixCalculator);
4444

45+
// A calculator to process std::vector<std::vector<Matrix>>.
46+
typedef BeginLoopCalculator<std::vector<std::vector<Matrix>>>
47+
BeginLoopMatrixVectorCalculator;
48+
REGISTER_CALCULATOR(BeginLoopMatrixVectorCalculator);
49+
4550
} // namespace mediapipe

Diff for: mediapipe/calculators/tensor/inference_calculator_cpu.cc

+13-5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class InferenceCalculatorCpuImpl
7373
private:
7474
absl::Status LoadModel(CalculatorContext* cc);
7575
absl::Status LoadDelegate(CalculatorContext* cc);
76+
absl::Status LoadDelegateAndAllocateTensors(CalculatorContext* cc);
7677

7778
// TfLite requires us to keep the model alive as long as the interpreter is.
7879
Packet<TfLiteModelPtr> model_packet_;
@@ -91,8 +92,7 @@ absl::Status InferenceCalculatorCpuImpl::UpdateContract(
9192

9293
absl::Status InferenceCalculatorCpuImpl::Open(CalculatorContext* cc) {
9394
MP_RETURN_IF_ERROR(LoadModel(cc));
94-
MP_RETURN_IF_ERROR(LoadDelegate(cc));
95-
return absl::OkStatus();
95+
return LoadDelegateAndAllocateTensors(cc);
9696
}
9797

9898
absl::Status InferenceCalculatorCpuImpl::Process(CalculatorContext* cc) {
@@ -156,11 +156,19 @@ absl::Status InferenceCalculatorCpuImpl::LoadModel(CalculatorContext* cc) {
156156
cc->Options<mediapipe::InferenceCalculatorOptions>().cpu_num_thread());
157157
#endif // __EMSCRIPTEN__
158158

159+
return absl::OkStatus();
160+
}
161+
162+
absl::Status InferenceCalculatorCpuImpl::LoadDelegateAndAllocateTensors(
163+
CalculatorContext* cc) {
164+
MP_RETURN_IF_ERROR(LoadDelegate(cc));
165+
166+
// AllocateTensors() can be called only after ModifyGraphWithDelegate.
159167
RET_CHECK_EQ(interpreter_->AllocateTensors(), kTfLiteOk);
160168
// TODO: Support quantized tensors.
161-
CHECK(interpreter_->tensor(interpreter_->inputs()[0])->quantization.type !=
162-
kTfLiteAffineQuantization);
163-
169+
RET_CHECK_NE(
170+
interpreter_->tensor(interpreter_->inputs()[0])->quantization.type,
171+
kTfLiteAffineQuantization);
164172
return absl::OkStatus();
165173
}
166174

Diff for: mediapipe/calculators/tensor/inference_calculator_gl.cc

+17-7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class InferenceCalculatorGlImpl
5353
absl::Status WriteKernelsToFile();
5454
absl::Status LoadModel(CalculatorContext* cc);
5555
absl::Status LoadDelegate(CalculatorContext* cc);
56+
absl::Status LoadDelegateAndAllocateTensors(CalculatorContext* cc);
5657
absl::Status InitTFLiteGPURunner(CalculatorContext* cc);
5758

5859
// TfLite requires us to keep the model alive as long as the interpreter is.
@@ -119,10 +120,11 @@ absl::Status InferenceCalculatorGlImpl::Open(CalculatorContext* cc) {
119120
}
120121

121122
MP_RETURN_IF_ERROR(gpu_helper_.Open(cc));
122-
MP_RETURN_IF_ERROR(gpu_helper_.RunInGlContext([this,
123-
&cc]() -> ::mediapipe::Status {
124-
return use_advanced_gpu_api_ ? InitTFLiteGPURunner(cc) : LoadDelegate(cc);
125-
}));
123+
MP_RETURN_IF_ERROR(
124+
gpu_helper_.RunInGlContext([this, &cc]() -> ::mediapipe::Status {
125+
return use_advanced_gpu_api_ ? InitTFLiteGPURunner(cc)
126+
: LoadDelegateAndAllocateTensors(cc);
127+
}));
126128
return absl::OkStatus();
127129
}
128130

@@ -324,11 +326,19 @@ absl::Status InferenceCalculatorGlImpl::LoadModel(CalculatorContext* cc) {
324326
cc->Options<mediapipe::InferenceCalculatorOptions>().cpu_num_thread());
325327
#endif // __EMSCRIPTEN__
326328

329+
return absl::OkStatus();
330+
}
331+
332+
absl::Status InferenceCalculatorGlImpl::LoadDelegateAndAllocateTensors(
333+
CalculatorContext* cc) {
334+
MP_RETURN_IF_ERROR(LoadDelegate(cc));
335+
336+
// AllocateTensors() can be called only after ModifyGraphWithDelegate.
327337
RET_CHECK_EQ(interpreter_->AllocateTensors(), kTfLiteOk);
328338
// TODO: Support quantized tensors.
329-
CHECK(interpreter_->tensor(interpreter_->inputs()[0])->quantization.type !=
330-
kTfLiteAffineQuantization);
331-
339+
RET_CHECK_NE(
340+
interpreter_->tensor(interpreter_->inputs()[0])->quantization.type,
341+
kTfLiteAffineQuantization);
332342
return absl::OkStatus();
333343
}
334344

Diff for: mediapipe/calculators/tensor/inference_calculator_metal.cc

+14-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class InferenceCalculatorMetalImpl
9292
private:
9393
absl::Status LoadModel(CalculatorContext* cc);
9494
absl::Status LoadDelegate(CalculatorContext* cc);
95+
absl::Status LoadDelegateAndAllocateTensors(CalculatorContext* cc);
9596

9697
// TfLite requires us to keep the model alive as long as the interpreter is.
9798
Packet<TfLiteModelPtr> model_packet_;
@@ -130,8 +131,7 @@ absl::Status InferenceCalculatorMetalImpl::Open(CalculatorContext* cc) {
130131

131132
gpu_helper_ = [[MPPMetalHelper alloc] initWithCalculatorContext:cc];
132133
RET_CHECK(gpu_helper_);
133-
MP_RETURN_IF_ERROR(LoadDelegate(cc));
134-
return absl::OkStatus();
134+
return LoadDelegateAndAllocateTensors(cc);
135135
}
136136

137137
absl::Status InferenceCalculatorMetalImpl::Process(CalculatorContext* cc) {
@@ -212,11 +212,19 @@ absl::Status InferenceCalculatorMetalImpl::LoadModel(CalculatorContext* cc) {
212212
interpreter_->SetNumThreads(
213213
cc->Options<mediapipe::InferenceCalculatorOptions>().cpu_num_thread());
214214

215+
return absl::OkStatus();
216+
}
217+
218+
absl::Status InferenceCalculatorMetalImpl::LoadDelegateAndAllocateTensors(
219+
CalculatorContext* cc) {
220+
MP_RETURN_IF_ERROR(LoadDelegate(cc));
221+
222+
// AllocateTensors() can be called only after ModifyGraphWithDelegate.
215223
RET_CHECK_EQ(interpreter_->AllocateTensors(), kTfLiteOk);
216224
// TODO: Support quantized tensors.
217-
CHECK(interpreter_->tensor(interpreter_->inputs()[0])->quantization.type !=
218-
kTfLiteAffineQuantization);
219-
225+
RET_CHECK_NE(
226+
interpreter_->tensor(interpreter_->inputs()[0])->quantization.type,
227+
kTfLiteAffineQuantization);
220228
return absl::OkStatus();
221229
}
222230

@@ -236,6 +244,7 @@ absl::Status InferenceCalculatorMetalImpl::LoadDelegate(CalculatorContext* cc) {
236244
TfLiteDelegatePtr(TFLGpuDelegateCreate(&options), &TFLGpuDelegateDelete);
237245
RET_CHECK_EQ(interpreter_->ModifyGraphWithDelegate(delegate_.get()),
238246
kTfLiteOk);
247+
239248
id<MTLDevice> device = gpu_helper_.mtlDevice;
240249

241250
// Get input image sizes.

Diff for: mediapipe/calculators/tensor/tensors_to_detections_calculator.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ absl::Status TensorsToDetectionsCalculator::ConvertToDetections(
670670
detection_boxes[box_offset + 2], detection_boxes[box_offset + 3],
671671
detection_scores[i], detection_classes[i], options_.flip_vertically());
672672
const auto& bbox = detection.location_data().relative_bounding_box();
673-
if (bbox.width() < 0 || bbox.height() < 0) {
673+
if (bbox.width() < 0 || bbox.height() < 0 || std::isnan(bbox.width()) ||
674+
std::isnan(bbox.height())) {
674675
// Decoded detection boxes could have negative values for width/height due
675676
// to model prediction. Filter out those boxes since some downstream
676677
// calculators may assume non-negative values. (b/171391719)

Diff for: mediapipe/calculators/tensor/tensors_to_segmentation_calculator.cc

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ using ::tflite::gpu::gl::GlShader;
138138
// }
139139
// }
140140
//
141-
// Currently only OpenGLES 3.1 and CPU backends supported.
142141
// TODO Refactor and add support for other backends/platforms.
143142
//
144143
class TensorsToSegmentationCalculator : public CalculatorBase {

Diff for: mediapipe/calculators/tensorflow/unpack_media_sequence_calculator_test.cc

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ constexpr char kBboxTag[] = "BBOX";
5656
constexpr char kForwardFlowEncodedTag[] = "FORWARD_FLOW_ENCODED";
5757
constexpr char kImagePrefixTag[] = "IMAGE_PREFIX";
5858
constexpr char kImageTag[] = "IMAGE";
59+
constexpr char kFloatContextFeatureOtherTag[] = "FLOAT_CONTEXT_FEATURE_OTHER";
60+
constexpr char kFloatContextFeatureTestTag[] = "FLOAT_CONTEXT_FEATURE_TEST";
5961
constexpr char kSequenceExampleTag[] = "SEQUENCE_EXAMPLE";
6062

6163
class UnpackMediaSequenceCalculatorTest : public ::testing::Test {

Diff for: mediapipe/calculators/util/labels_to_render_data_calculator.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ absl::Status LabelsToRenderDataCalculator::Process(CalculatorContext* cc) {
175175

176176
auto* text = label_annotation->mutable_text();
177177
std::string display_text = labels[i];
178-
if (cc->Inputs().HasTag(kScoresTag)) {
178+
if (cc->Inputs().HasTag(kScoresTag) ||
179+
options_.display_classification_score()) {
179180
absl::StrAppend(&display_text, ":", scores[i]);
180181
}
181182
text->set_display_text(display_text);

Diff for: mediapipe/calculators/util/labels_to_render_data_calculator.proto

+3
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ message LabelsToRenderDataCalculatorOptions {
6262

6363
// Uses Classification.display_name field instead of Classification.label.
6464
optional bool use_display_name = 9 [default = false];
65+
66+
// Displays Classification score if enabled.
67+
optional bool display_classification_score = 10 [default = false];
6568
}

Diff for: mediapipe/framework/api2/node.h

+11-12
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,23 @@ class SubgraphImpl : public Subgraph, public Intf {
223223

224224
// This macro is used to register a calculator that does not use automatic
225225
// registration. Deprecated.
226-
#define MEDIAPIPE_NODE_IMPLEMENTATION(Impl) \
227-
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \
228-
REGISTRY_STATIC_VAR(calculator_registration, __LINE__)( \
229-
mediapipe::CalculatorBaseRegistry::Register( \
230-
Impl::kCalculatorName, \
231-
absl::make_unique< \
232-
mediapipe::internal::CalculatorBaseFactoryFor<Impl>>))
226+
#define MEDIAPIPE_NODE_IMPLEMENTATION(Impl) \
227+
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \
228+
REGISTRY_STATIC_VAR(calculator_registration, \
229+
__LINE__)(mediapipe::CalculatorBaseRegistry::Register( \
230+
Impl::kCalculatorName, \
231+
absl::make_unique<mediapipe::internal::CalculatorBaseFactoryFor<Impl>>))
233232

234233
// This macro is used to register a non-split-contract calculator. Deprecated.
235234
#define MEDIAPIPE_REGISTER_NODE(name) REGISTER_CALCULATOR(name)
236235

237236
// This macro is used to define a subgraph that does not use automatic
238237
// registration. Deprecated.
239-
#define MEDIAPIPE_SUBGRAPH_IMPLEMENTATION(Impl) \
240-
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \
241-
REGISTRY_STATIC_VAR(subgraph_registration, \
242-
__LINE__)(mediapipe::SubgraphRegistry::Register( \
243-
Impl::kCalculatorName, absl::make_unique<Impl>))
238+
#define MEDIAPIPE_SUBGRAPH_IMPLEMENTATION(Impl) \
239+
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \
240+
REGISTRY_STATIC_VAR(subgraph_registration, \
241+
__LINE__)(mediapipe::SubgraphRegistry::Register( \
242+
Impl::kCalculatorName, absl::make_unique<Impl>))
244243

245244
} // namespace api2
246245
} // namespace mediapipe

0 commit comments

Comments
 (0)