Skip to content

Commit 137867d

Browse files
MediaPipe Teamjqtang
MediaPipe Team
authored and
jqtang
committed
Project import generated by Copybara.
GitOrigin-RevId: e3566e5029af25b0fc4b1071a49e49ae20aa5df6
1 parent 446d7cf commit 137867d

File tree

74 files changed

+908
-503
lines changed

Some content is hidden

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

74 files changed

+908
-503
lines changed

Diff for: Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3030
unzip \
3131
python \
3232
python-pip \
33+
python3-pip \
3334
libopencv-core-dev \
3435
libopencv-highgui-dev \
3536
libopencv-imgproc-dev \
@@ -42,9 +43,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
4243

4344
RUN pip install --upgrade setuptools
4445
RUN pip install future
46+
RUN pip3 install six
4547

4648
# Install bazel
47-
ARG BAZEL_VERSION=0.26.1
49+
ARG BAZEL_VERSION=1.1.0
4850
RUN mkdir /bazel && \
4951
wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
5052
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \

Diff for: WORKSPACE

+14-10
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ http_archive(
1212
load("@bazel_skylib//lib:versions.bzl", "versions")
1313
versions.check(minimum_bazel_version = "0.24.1")
1414

15-
# ABSL cpp library.
15+
# ABSL cpp library lts_2019_08_08.
1616
http_archive(
1717
name = "com_google_absl",
18-
# Head commit on 2019-04-12.
19-
# TODO: Switch to the latest absl version when the problem gets
20-
# fixed.
2118
urls = [
22-
"https://github.com/abseil/abseil-cpp/archive/a02f62f456f2c4a7ecf2be3104fe0c6e16fbad9a.tar.gz",
19+
"https://github.com/abseil/abseil-cpp/archive/20190808.tar.gz",
2320
],
24-
sha256 = "d437920d1434c766d22e85773b899c77c672b8b4865d5dc2cd61a29fdff3cf03",
25-
strip_prefix = "abseil-cpp-a02f62f456f2c4a7ecf2be3104fe0c6e16fbad9a",
21+
# Remove after https://github.com/abseil/abseil-cpp/issues/326 is solved.
22+
patches = [
23+
"@//third_party:com_google_absl_f863b622fe13612433fdf43f76547d5edda0c93001.diff"
24+
],
25+
patch_args = [
26+
"-p1",
27+
],
28+
strip_prefix = "abseil-cpp-20190808",
29+
sha256 = "8100085dada279bf3ee00cd064d43b5f55e5d913be0dfe2906f06f8f28d5b37e"
2630
)
2731

2832
http_archive(
@@ -103,9 +107,9 @@ http_archive(
103107
],
104108
)
105109

106-
# 2019-11-12
107-
_TENSORFLOW_GIT_COMMIT = "a5f9bcd64453ff3d1f64cb4da4786db3d2da7f82"
108-
_TENSORFLOW_SHA256= "f2b6f2ab2ffe63e86eccd3ce4bea6b7197383d726638dfeeebcdc1e7de73f075"
110+
# 2019-11-21
111+
_TENSORFLOW_GIT_COMMIT = "f482488b481a799ca07e7e2d153cf47b8e91a60c"
112+
_TENSORFLOW_SHA256= "8d9118c2ce186c7e1403f04b96982fe72c184060c7f7a93e30a28dca358694f0"
109113
http_archive(
110114
name = "org_tensorflow",
111115
urls = [

Diff for: mediapipe/calculators/core/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ cc_library(
691691
":split_vector_calculator_cc_proto",
692692
"//mediapipe/framework:calculator_framework",
693693
"//mediapipe/framework/formats:landmark_cc_proto",
694+
"//mediapipe/framework/formats:rect_cc_proto",
694695
"//mediapipe/framework/port:ret_check",
695696
"//mediapipe/framework/port:status",
696697
"//mediapipe/util:resource_util",

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121

2222
namespace mediapipe {
2323

24-
// A calculator to process std::vector<NormalizedLandmark>.
25-
typedef BeginLoopCalculator<std::vector<::mediapipe::NormalizedLandmark>>
26-
BeginLoopNormalizedLandmarkCalculator;
27-
REGISTER_CALCULATOR(BeginLoopNormalizedLandmarkCalculator);
28-
29-
// A calculator to process std::vector<std::vector<NormalizedLandmark>>.
30-
typedef BeginLoopCalculator<
31-
std::vector<std::vector<::mediapipe::NormalizedLandmark>>>
32-
BeginLoopNormalizedLandmarksVectorCalculator;
33-
REGISTER_CALCULATOR(BeginLoopNormalizedLandmarksVectorCalculator);
24+
// A calculator to process std::vector<NormalizedLandmarkList>.
25+
typedef BeginLoopCalculator<std::vector<::mediapipe::NormalizedLandmarkList>>
26+
BeginLoopNormalizedLandmarkListVectorCalculator;
27+
REGISTER_CALCULATOR(BeginLoopNormalizedLandmarkListVectorCalculator);
3428

3529
// A calculator to process std::vector<NormalizedRect>.
3630
typedef BeginLoopCalculator<std::vector<::mediapipe::NormalizedRect>>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mediapipe/framework/formats/landmark.pb.h"
2020
#include "tensorflow/lite/interpreter.h"
2121

22-
#if !defined(MEDIAPIPE_DISABLE_GPU) && !defined(__APPLE__)
22+
#if !defined(MEDIAPIPE_DISABLE_GL_COMPUTE)
2323
#include "tensorflow/lite/delegates/gpu/gl/gl_buffer.h"
2424
#endif // !MEDIAPIPE_DISABLE_GPU
2525

@@ -50,7 +50,7 @@ typedef ConcatenateVectorCalculator<::mediapipe::NormalizedLandmark>
5050
ConcatenateLandmarkVectorCalculator;
5151
REGISTER_CALCULATOR(ConcatenateLandmarkVectorCalculator);
5252

53-
#if !defined(MEDIAPIPE_DISABLE_GPU) && !defined(__APPLE__)
53+
#if !defined(MEDIAPIPE_DISABLE_GL_COMPUTE)
5454
typedef ConcatenateVectorCalculator<::tflite::gpu::gl::GlBuffer>
5555
ConcatenateGlBufferVectorCalculator;
5656
REGISTER_CALCULATOR(ConcatenateGlBufferVectorCalculator);

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

+3-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ typedef EndLoopCalculator<std::vector<::mediapipe::NormalizedRect>>
2626
EndLoopNormalizedRectCalculator;
2727
REGISTER_CALCULATOR(EndLoopNormalizedRectCalculator);
2828

29-
typedef EndLoopCalculator<std::vector<::mediapipe::NormalizedLandmark>>
30-
EndLoopNormalizedLandmarkCalculator;
31-
REGISTER_CALCULATOR(EndLoopNormalizedLandmarkCalculator);
32-
33-
typedef EndLoopCalculator<
34-
std::vector<std::vector<::mediapipe::NormalizedLandmark>>>
35-
EndLoopNormalizedLandmarksVectorCalculator;
36-
REGISTER_CALCULATOR(EndLoopNormalizedLandmarksVectorCalculator);
29+
typedef EndLoopCalculator<std::vector<::mediapipe::NormalizedLandmarkList>>
30+
EndLoopNormalizedLandmarkListVectorCalculator;
31+
REGISTER_CALCULATOR(EndLoopNormalizedLandmarkListVectorCalculator);
3732

3833
typedef EndLoopCalculator<std::vector<bool>> EndLoopBooleanCalculator;
3934
REGISTER_CALCULATOR(EndLoopBooleanCalculator);

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

+4-17
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class PreviousLoopbackCalculator : public CalculatorBase {
7474
}
7575

7676
::mediapipe::Status Process(CalculatorContext* cc) final {
77+
Packet& main_packet = cc->Inputs().Get(main_id_).Value();
78+
if (!main_packet.IsEmpty()) {
79+
main_ts_.push_back(main_packet.Timestamp());
80+
}
7781
Packet& loopback_packet = cc->Inputs().Get(loop_id_).Value();
7882
if (!loopback_packet.IsEmpty()) {
7983
loopback_packets_.push_back(loopback_packet);
@@ -83,23 +87,6 @@ class PreviousLoopbackCalculator : public CalculatorBase {
8387
}
8488
}
8589

86-
Packet& main_packet = cc->Inputs().Get(main_id_).Value();
87-
if (!main_packet.IsEmpty()) {
88-
main_ts_.push_back(main_packet.Timestamp());
89-
90-
// In case of an empty "LOOP" input, truncate timestamp is set to the
91-
// lowest possible timestamp for a successive non-empty "LOOP" input. This
92-
// truncates main_ts_ as soon as possible, and produces the highest legal
93-
// output timestamp bound.
94-
if (loopback_packet.IsEmpty() &&
95-
loopback_packet.Timestamp() != Timestamp::Unstarted()) {
96-
while (!main_ts_.empty() &&
97-
main_ts_.front() <= loopback_packet.Timestamp() + 1) {
98-
main_ts_.pop_front();
99-
}
100-
}
101-
}
102-
10390
while (!main_ts_.empty() && !loopback_packets_.empty()) {
10491
Timestamp main_timestamp = main_ts_.front();
10592
main_ts_.pop_front();

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

+15-65
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ TEST(PreviousLoopbackCalculator, CorrectTimestamps) {
9393
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1}));
9494
EXPECT_EQ(pair_values(in_prev.back()), std::make_pair(1, -1));
9595

96+
send_packet("in", 2);
97+
MP_EXPECT_OK(graph_.WaitUntilIdle());
98+
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1, 2}));
99+
EXPECT_EQ(pair_values(in_prev.back()), std::make_pair(2, 1));
100+
96101
send_packet("in", 5);
97102
MP_EXPECT_OK(graph_.WaitUntilIdle());
98-
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1, 5}));
99-
EXPECT_EQ(pair_values(in_prev.back()), std::make_pair(5, 1));
103+
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1, 2, 5}));
104+
EXPECT_EQ(pair_values(in_prev.back()), std::make_pair(5, 2));
100105

101106
send_packet("in", 15);
102107
MP_EXPECT_OK(graph_.WaitUntilIdle());
103-
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1, 5, 15}));
108+
EXPECT_EQ(TimestampValues(in_prev), (std::vector<int64>{1, 2, 5, 15}));
104109
EXPECT_EQ(pair_values(in_prev.back()), std::make_pair(15, 5));
105110

106111
MP_EXPECT_OK(graph_.CloseAllInputStreams());
@@ -182,78 +187,23 @@ TEST(PreviousLoopbackCalculator, ClosesCorrectly) {
182187
MP_EXPECT_OK(graph_.WaitUntilIdle());
183188
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1}));
184189

190+
send_packet("in", 2);
191+
MP_EXPECT_OK(graph_.WaitUntilIdle());
192+
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1, 2}));
193+
185194
send_packet("in", 5);
186195
MP_EXPECT_OK(graph_.WaitUntilIdle());
187-
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1, 5}));
196+
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1, 2, 5}));
188197

189198
send_packet("in", 15);
190199
MP_EXPECT_OK(graph_.WaitUntilIdle());
191-
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1, 5, 15}));
200+
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{1, 2, 5, 15}));
192201

193202
MP_EXPECT_OK(graph_.CloseAllInputStreams());
194203
MP_EXPECT_OK(graph_.WaitUntilIdle());
195204
EXPECT_EQ(TimestampValues(outputs),
196-
(std::vector<int64>{1, 5, 15, Timestamp::Max().Value()}));
197-
198-
MP_EXPECT_OK(graph_.WaitUntilDone());
199-
}
205+
(std::vector<int64>{1, 2, 5, 15, Timestamp::Max().Value()}));
200206

201-
// Demonstrates that downstream calculators won't be blocked by
202-
// always-empty-LOOP-stream.
203-
TEST(PreviousLoopbackCalculator, EmptyLoopForever) {
204-
std::vector<Packet> outputs;
205-
CalculatorGraphConfig graph_config_ =
206-
ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
207-
input_stream: 'in'
208-
node {
209-
calculator: 'PreviousLoopbackCalculator'
210-
input_stream: 'MAIN:in'
211-
input_stream: 'LOOP:previous'
212-
input_stream_info: { tag_index: 'LOOP' back_edge: true }
213-
output_stream: 'PREV_LOOP:previous'
214-
}
215-
# This calculator synchronizes its inputs as normal, so it is used
216-
# to check that both "in" and "previous" are ready.
217-
node {
218-
calculator: 'PassThroughCalculator'
219-
input_stream: 'in'
220-
input_stream: 'previous'
221-
output_stream: 'out'
222-
output_stream: 'previous2'
223-
}
224-
node {
225-
calculator: 'PacketOnCloseCalculator'
226-
input_stream: 'out'
227-
output_stream: 'close_out'
228-
}
229-
)");
230-
tool::AddVectorSink("close_out", &graph_config_, &outputs);
231-
232-
CalculatorGraph graph_;
233-
MP_ASSERT_OK(graph_.Initialize(graph_config_, {}));
234-
MP_ASSERT_OK(graph_.StartRun({}));
235-
236-
auto send_packet = [&graph_](const std::string& input_name, int n) {
237-
MP_EXPECT_OK(graph_.AddPacketToInputStream(
238-
input_name, MakePacket<int>(n).At(Timestamp(n))));
239-
};
240-
241-
send_packet("in", 0);
242-
MP_EXPECT_OK(graph_.WaitUntilIdle());
243-
EXPECT_EQ(TimestampValues(outputs), (std::vector<int64>{0}));
244-
245-
for (int main_ts = 1; main_ts < 50; ++main_ts) {
246-
send_packet("in", main_ts);
247-
MP_EXPECT_OK(graph_.WaitUntilIdle());
248-
std::vector<int64> ts_values = TimestampValues(outputs);
249-
EXPECT_EQ(ts_values.size(), main_ts);
250-
for (int j = 0; j < main_ts; ++j) {
251-
CHECK_EQ(ts_values[j], j);
252-
}
253-
}
254-
255-
MP_EXPECT_OK(graph_.CloseAllInputStreams());
256-
MP_EXPECT_OK(graph_.WaitUntilIdle());
257207
MP_EXPECT_OK(graph_.WaitUntilDone());
258208
}
259209

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

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <vector>
1818

1919
#include "mediapipe/framework/formats/landmark.pb.h"
20+
#include "mediapipe/framework/formats/rect.pb.h"
2021
#include "tensorflow/lite/interpreter.h"
2122

2223
namespace mediapipe {
@@ -41,4 +42,8 @@ REGISTER_CALCULATOR(SplitTfLiteTensorVectorCalculator);
4142
typedef SplitVectorCalculator<::mediapipe::NormalizedLandmark>
4243
SplitLandmarkVectorCalculator;
4344
REGISTER_CALCULATOR(SplitLandmarkVectorCalculator);
45+
46+
typedef SplitVectorCalculator<::mediapipe::NormalizedRect>
47+
SplitNormalizedRectVectorCalculator;
48+
REGISTER_CALCULATOR(SplitNormalizedRectVectorCalculator);
4449
} // namespace mediapipe

Diff for: mediapipe/calculators/image/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ cc_library(
356356
"//mediapipe/framework/port:opencv_imgproc",
357357
"//mediapipe/framework/port:ret_check",
358358
"//mediapipe/framework/port:status",
359-
"//mediapipe/gpu:gpu_buffer",
360359
] + select({
361360
"//mediapipe/gpu:disable_gpu": [],
362361
"//conditions:default": [
363362
"//mediapipe/gpu:gl_calculator_helper",
364363
"//mediapipe/gpu:gl_simple_shaders",
365364
"//mediapipe/gpu:gl_quad_renderer",
365+
"//mediapipe/gpu:gpu_buffer",
366366
"//mediapipe/gpu:shader_util",
367367
],
368368
}),

Diff for: mediapipe/calculators/image/image_transformation_calculator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ ::mediapipe::Status ImageTransformationCalculator::RenderGpu(
400400
QuadRenderer* renderer = nullptr;
401401
GlTexture src1;
402402

403-
#if defined(__APPLE__) && !TARGET_OS_OSX
403+
#if defined(MEDIAPIPE_IOS)
404404
if (input.format() == GpuBufferFormat::kBiPlanar420YpCbCr8VideoRange ||
405405
input.format() == GpuBufferFormat::kBiPlanar420YpCbCr8FullRange) {
406406
if (!yuv_renderer_) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "tensorflow/core/framework/tensor_shape.h"
3535
#include "tensorflow/core/framework/tensor_util.h"
3636

37-
#if !defined(__ANDROID__) && !defined(__APPLE__)
37+
#if !defined(MEDIAPIPE_MOBILE) && !defined(__APPLE__)
3838
#include "tensorflow/core/profiler/lib/traceme.h"
3939
#endif
4040

@@ -441,7 +441,7 @@ class TensorFlowInferenceCalculator : public CalculatorBase {
441441
const int64 run_start_time = absl::ToUnixMicros(clock_->TimeNow());
442442
tf::Status tf_status;
443443
{
444-
#if !defined(__ANDROID__) && !defined(__APPLE__)
444+
#if !defined(MEDIAPIPE_MOBILE) && !defined(__APPLE__)
445445
tensorflow::profiler::TraceMe trace(absl::string_view(cc->NodeName()));
446446
#endif
447447
tf_status = session_->Run(input_tensors, output_tensor_names,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
#include "mediapipe/framework/tool/status_util.h"
3232
#include "tensorflow/core/public/session_options.h"
3333

34-
#if defined(MEDIAPIPE_LITE) || defined(__ANDROID__) || \
35-
defined(__APPLE__) && !TARGET_OS_OSX
34+
#if defined(MEDIAPIPE_MOBILE)
3635
#include "mediapipe/util/android/file/base/helpers.h"
3736
#else
3837
#include "mediapipe/framework/port/file_helpers.h"

Diff for: mediapipe/calculators/tflite/BUILD

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# limitations under the License.
1414
#
1515

16+
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
17+
1618
licenses(["notice"]) # Apache 2.0
1719

1820
package(default_visibility = ["//visibility:private"])
1921

20-
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
21-
2222
proto_library(
2323
name = "ssd_anchors_calculator_proto",
2424
srcs = ["ssd_anchors_calculator.proto"],
@@ -249,6 +249,11 @@ cc_library(
249249
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:gl_program",
250250
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:gl_shader",
251251
],
252+
}) + select({
253+
"//conditions:default": [],
254+
"//mediapipe:android": [
255+
"@org_tensorflow//tensorflow/lite/delegates/nnapi:nnapi_delegate",
256+
],
252257
}),
253258
alwayslink = 1,
254259
)

0 commit comments

Comments
 (0)