hxrron commited on
Commit
dffe135
·
verified ·
1 Parent(s): de2405e

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. python_embeded/Lib/site-packages/mediapipe/calculators/__init__.py +0 -0
  3. python_embeded/Lib/site-packages/mediapipe/examples/__init__.py +14 -0
  4. python_embeded/Lib/site-packages/mediapipe/framework/__init__.py +0 -0
  5. python_embeded/Lib/site-packages/mediapipe/framework/calculator_options_pb2.py +29 -0
  6. python_embeded/Lib/site-packages/mediapipe/framework/calculator_pb2.py +59 -0
  7. python_embeded/Lib/site-packages/mediapipe/framework/calculator_profile_pb2.py +48 -0
  8. python_embeded/Lib/site-packages/mediapipe/framework/graph_runtime_info_pb2.py +31 -0
  9. python_embeded/Lib/site-packages/mediapipe/framework/mediapipe_options_pb2.py +27 -0
  10. python_embeded/Lib/site-packages/mediapipe/framework/packet_factory_pb2.py +31 -0
  11. python_embeded/Lib/site-packages/mediapipe/framework/packet_generator_pb2.py +33 -0
  12. python_embeded/Lib/site-packages/mediapipe/framework/status_handler_pb2.py +28 -0
  13. python_embeded/Lib/site-packages/mediapipe/framework/stream_handler_pb2.py +30 -0
  14. python_embeded/Lib/site-packages/mediapipe/framework/test_calculators_pb2.py +32 -0
  15. python_embeded/Lib/site-packages/mediapipe/framework/thread_pool_executor_pb2.py +30 -0
  16. python_embeded/Lib/site-packages/mediapipe/gpu/__init__.py +0 -0
  17. python_embeded/Lib/site-packages/mediapipe/gpu/copy_calculator_pb2.py +34 -0
  18. python_embeded/Lib/site-packages/mediapipe/gpu/gl_animation_overlay_calculator_pb2.py +32 -0
  19. python_embeded/Lib/site-packages/mediapipe/gpu/gl_context_options_pb2.py +32 -0
  20. python_embeded/Lib/site-packages/mediapipe/gpu/gl_scaler_calculator_pb2.py +33 -0
  21. python_embeded/Lib/site-packages/mediapipe/gpu/gl_surface_sink_calculator_pb2.py +33 -0
  22. python_embeded/Lib/site-packages/mediapipe/gpu/gpu_origin_pb2.py +29 -0
  23. python_embeded/Lib/site-packages/mediapipe/gpu/scale_mode_pb2.py +28 -0
  24. python_embeded/Lib/site-packages/mediapipe/model_maker/__init__.py +27 -0
  25. python_embeded/Lib/site-packages/mediapipe/model_maker/setup.py +107 -0
  26. python_embeded/Lib/site-packages/mediapipe/modules/__init__.py +0 -0
  27. python_embeded/Lib/site-packages/mediapipe/python/__init__.py +29 -0
  28. python_embeded/Lib/site-packages/mediapipe/python/calculator_graph_test.py +251 -0
  29. python_embeded/Lib/site-packages/mediapipe/python/image_frame_test.py +194 -0
  30. python_embeded/Lib/site-packages/mediapipe/python/image_test.py +218 -0
  31. python_embeded/Lib/site-packages/mediapipe/python/packet_creator.py +275 -0
  32. python_embeded/Lib/site-packages/mediapipe/python/packet_getter.py +120 -0
  33. python_embeded/Lib/site-packages/mediapipe/python/packet_test.py +533 -0
  34. python_embeded/Lib/site-packages/mediapipe/python/solution_base.py +604 -0
  35. python_embeded/Lib/site-packages/mediapipe/python/solution_base_test.py +396 -0
  36. python_embeded/Lib/site-packages/mediapipe/python/timestamp_test.py +78 -0
  37. python_embeded/Lib/site-packages/mediapipe/tasks/__init__.py +14 -0
  38. python_embeded/Lib/site-packages/mediapipe/tasks/cc/__init__.py +0 -0
  39. python_embeded/Lib/site-packages/mediapipe/tasks/cc/audio/__init__.py +0 -0
  40. python_embeded/Lib/site-packages/mediapipe/tasks/cc/components/__init__.py +0 -0
  41. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/__init__.py +0 -0
  42. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/__init__.py +0 -0
  43. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/acceleration_pb2.py +28 -0
  44. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/base_options_pb2.py +30 -0
  45. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/external_file_pb2.py +31 -0
  46. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/inference_subgraph_pb2.py +33 -0
  47. python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/model_resources_calculator_pb2.py +33 -0
  48. python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/__init__.py +0 -0
  49. python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/inference/__init__.py +0 -0
  50. python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/inference/c/__init__.py +0 -0
.gitattributes CHANGED
@@ -329,3 +329,5 @@ python_embeded/Lib/site-packages/pip/_vendor/distlib/t64-arm.exe filter=lfs diff
329
  python_embeded/Lib/site-packages/pip/_vendor/distlib/t64.exe filter=lfs diff=lfs merge=lfs -text
330
  python_embeded/Lib/site-packages/pip/_vendor/distlib/w64.exe filter=lfs diff=lfs merge=lfs -text
331
  python_embeded/Lib/site-packages/pip/_vendor/distlib/w64-arm.exe filter=lfs diff=lfs merge=lfs -text
 
 
 
329
  python_embeded/Lib/site-packages/pip/_vendor/distlib/t64.exe filter=lfs diff=lfs merge=lfs -text
330
  python_embeded/Lib/site-packages/pip/_vendor/distlib/w64.exe filter=lfs diff=lfs merge=lfs -text
331
  python_embeded/Lib/site-packages/pip/_vendor/distlib/w64-arm.exe filter=lfs diff=lfs merge=lfs -text
332
+ python_embeded/Lib/site-packages/numpy/random/lib/npyrandom.lib filter=lfs diff=lfs merge=lfs -text
333
+ python_embeded/Lib/site-packages/onnxruntime/capi/onnxruntime.dll filter=lfs diff=lfs merge=lfs -text
python_embeded/Lib/site-packages/mediapipe/calculators/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/examples/__init__.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Copyright 2019 The MediaPipe Authors.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ """
python_embeded/Lib/site-packages/mediapipe/framework/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/framework/calculator_options_pb2.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/calculator_options.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,mediapipe/framework/calculator_options.proto\x12\tmediapipe\"9\n\x11\x43\x61lculatorOptions\x12\x18\n\x0cmerge_fields\x18\x01 \x01(\x08\x42\x02\x18\x01*\n\x08\xa0\x9c\x01\x10\x80\x80\x80\x80\x02\x42\x34\n\x1a\x63om.google.mediapipe.protoB\x16\x43\x61lculatorOptionsProto')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.calculator_options_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\026CalculatorOptionsProto'
25
+ _CALCULATOROPTIONS.fields_by_name['merge_fields']._options = None
26
+ _CALCULATOROPTIONS.fields_by_name['merge_fields']._serialized_options = b'\030\001'
27
+ _globals['_CALCULATOROPTIONS']._serialized_start=59
28
+ _globals['_CALCULATOROPTIONS']._serialized_end=116
29
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/calculator_pb2.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_options_pb2 as mediapipe_dot_framework_dot_calculator__options__pb2
15
+ from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2
16
+ from mediapipe.framework import mediapipe_options_pb2 as mediapipe_dot_framework_dot_mediapipe__options__pb2
17
+ from mediapipe.framework import packet_factory_pb2 as mediapipe_dot_framework_dot_packet__factory__pb2
18
+ from mediapipe.framework import packet_generator_pb2 as mediapipe_dot_framework_dot_packet__generator__pb2
19
+ from mediapipe.framework import status_handler_pb2 as mediapipe_dot_framework_dot_status__handler__pb2
20
+ from mediapipe.framework import stream_handler_pb2 as mediapipe_dot_framework_dot_stream__handler__pb2
21
+
22
+ from mediapipe.framework.calculator_options_pb2 import *
23
+
24
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$mediapipe/framework/calculator.proto\x12\tmediapipe\x1a,mediapipe/framework/calculator_options.proto\x1a\x19google/protobuf/any.proto\x1a+mediapipe/framework/mediapipe_options.proto\x1a(mediapipe/framework/packet_factory.proto\x1a*mediapipe/framework/packet_generator.proto\x1a(mediapipe/framework/status_handler.proto\x1a(mediapipe/framework/stream_handler.proto\"Z\n\x0e\x45xecutorConfig\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04type\x18\x02 \x01(\t\x12,\n\x07options\x18\x03 \x01(\x0b\x32\x1b.mediapipe.MediaPipeOptions\"\x91\x02\n\x0fInputCollection\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x18\n\x10side_packet_name\x18\x02 \x03(\t\x12\x1c\n\x13\x65xternal_input_name\x18\xea\x07 \x03(\t\x12\x38\n\ninput_type\x18\x03 \x01(\x0e\x32$.mediapipe.InputCollection.InputType\x12\x11\n\tfile_name\x18\x04 \x01(\t\"k\n\tInputType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0c\n\x08RECORDIO\x10\x01\x12\x14\n\x10\x46OREIGN_RECORDIO\x10\x02\x12\x14\n\x10\x46OREIGN_CSV_TEXT\x10\x03\x12\x17\n\x13INVALID_UPPER_BOUND\x10\x04\"J\n\x12InputCollectionSet\x12\x34\n\x10input_collection\x18\x01 \x03(\x0b\x32\x1a.mediapipe.InputCollection\"7\n\x0fInputStreamInfo\x12\x11\n\ttag_index\x18\x01 \x01(\t\x12\x11\n\tback_edge\x18\x02 \x01(\x08\"\xd1\x04\n\x0eProfilerConfig\x12$\n\x1chistogram_interval_size_usec\x18\x01 \x01(\x03\x12\x1f\n\x17num_histogram_intervals\x18\x02 \x01(\x03\x12\'\n\x1b\x65nable_input_output_latency\x18\x03 \x01(\x08\x42\x02\x18\x01\x12\x17\n\x0f\x65nable_profiler\x18\x04 \x01(\x08\x12\x1d\n\x15\x65nable_stream_latency\x18\x05 \x01(\x08\x12-\n%use_packet_timestamp_for_added_packet\x18\x06 \x01(\x08\x12\x1a\n\x12trace_log_capacity\x18\x07 \x01(\x03\x12\"\n\x1atrace_event_types_disabled\x18\x08 \x03(\x05\x12\x16\n\x0etrace_log_path\x18\t \x01(\t\x12\x17\n\x0ftrace_log_count\x18\n \x01(\x05\x12\x1f\n\x17trace_log_interval_usec\x18\x0b \x01(\x03\x12\x1d\n\x15trace_log_margin_usec\x18\x0c \x01(\x03\x12%\n\x19trace_log_duration_events\x18\r \x01(\x08\x42\x02\x18\x01\x12 \n\x18trace_log_interval_count\x18\x0e \x01(\x05\x12\x1a\n\x12trace_log_disabled\x18\x0f \x01(\x08\x12\x15\n\rtrace_enabled\x18\x10 \x01(\x08\x12 \n\x18trace_log_instant_events\x18\x11 \x01(\x08\x12\x19\n\x11\x63\x61lculator_filter\x18\x12 \x01(\t\"X\n\x16GraphRuntimeInfoConfig\x12!\n\x19\x65nable_graph_runtime_info\x18\x01 \x01(\x08\x12\x1b\n\x13\x63\x61pture_period_msec\x18\x02 \x01(\r\"\xad\x0b\n\x15\x43\x61lculatorGraphConfig\x12\x33\n\x04node\x18\x01 \x03(\x0b\x32%.mediapipe.CalculatorGraphConfig.Node\x12\x36\n\x0epacket_factory\x18\x06 \x03(\x0b\x32\x1e.mediapipe.PacketFactoryConfig\x12>\n\x10packet_generator\x18\x07 \x03(\x0b\x32 .mediapipe.PacketGeneratorConfigB\x02\x18\x01\x12\x13\n\x0bnum_threads\x18\x08 \x01(\x05\x12\x36\n\x0estatus_handler\x18\t \x03(\x0b\x32\x1e.mediapipe.StatusHandlerConfig\x12\x14\n\x0cinput_stream\x18\n \x03(\t\x12\x15\n\routput_stream\x18\x0f \x03(\t\x12\x19\n\x11input_side_packet\x18\x10 \x03(\t\x12\x1a\n\x12output_side_packet\x18\x11 \x03(\t\x12\x16\n\x0emax_queue_size\x18\x0b \x01(\x05\x12\x17\n\x0freport_deadlock\x18\x15 \x01(\x08\x12\x37\n\x0cruntime_info\x18\x16 \x01(\x0b\x32!.mediapipe.GraphRuntimeInfoConfig\x12\x41\n\x14input_stream_handler\x18\x0c \x01(\x0b\x32#.mediapipe.InputStreamHandlerConfig\x12\x43\n\x15output_stream_handler\x18\r \x01(\x0b\x32$.mediapipe.OutputStreamHandlerConfig\x12+\n\x08\x65xecutor\x18\x0e \x03(\x0b\x32\x19.mediapipe.ExecutorConfig\x12\x32\n\x0fprofiler_config\x18\x12 \x01(\x0b\x32\x19.mediapipe.ProfilerConfig\x12\x0f\n\x07package\x18\x13 \x01(\t\x12\x0c\n\x04type\x18\x14 \x01(\t\x12-\n\x07options\x18\xe9\x07 \x01(\x0b\x32\x1b.mediapipe.MediaPipeOptions\x12,\n\rgraph_options\x18\xea\x07 \x03(\x0b\x32\x14.google.protobuf.Any\x1a\xe6\x04\n\x04Node\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x12\n\ncalculator\x18\x02 \x01(\t\x12\x14\n\x0cinput_stream\x18\x03 \x03(\t\x12\x15\n\routput_stream\x18\x04 \x03(\t\x12\x19\n\x11input_side_packet\x18\x05 \x03(\t\x12\x1a\n\x12output_side_packet\x18\x06 \x03(\t\x12-\n\x07options\x18\x07 \x01(\x0b\x32\x1c.mediapipe.CalculatorOptions\x12*\n\x0cnode_options\x18\x08 \x03(\x0b\x32\x14.google.protobuf.Any\x12\x14\n\x0csource_layer\x18\t \x01(\x05\x12\x18\n\x10\x62uffer_size_hint\x18\n \x01(\x05\x12\x41\n\x14input_stream_handler\x18\x0b \x01(\x0b\x32#.mediapipe.InputStreamHandlerConfig\x12\x43\n\x15output_stream_handler\x18\x0c \x01(\x0b\x32$.mediapipe.OutputStreamHandlerConfig\x12\x35\n\x11input_stream_info\x18\r \x03(\x0b\x32\x1a.mediapipe.InputStreamInfo\x12\x10\n\x08\x65xecutor\x18\x0e \x01(\t\x12\x36\n\x0fprofiler_config\x18\x0f \x01(\x0b\x32\x19.mediapipe.ProfilerConfigB\x02\x18\x01\x12\x15\n\rmax_in_flight\x18\x10 \x01(\x05\x12\x14\n\x0coption_value\x18\x11 \x03(\t\x12\x17\n\x0e\x65xternal_input\x18\xed\x07 \x03(\tB-\n\x1a\x63om.google.mediapipe.protoB\x0f\x43\x61lculatorProtoP\x00\x62\x06proto3')
25
+
26
+ _globals = globals()
27
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
28
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.calculator_pb2', _globals)
29
+ if _descriptor._USE_C_DESCRIPTORS == False:
30
+
31
+ DESCRIPTOR._options = None
32
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\017CalculatorProto'
33
+ _PROFILERCONFIG.fields_by_name['enable_input_output_latency']._options = None
34
+ _PROFILERCONFIG.fields_by_name['enable_input_output_latency']._serialized_options = b'\030\001'
35
+ _PROFILERCONFIG.fields_by_name['trace_log_duration_events']._options = None
36
+ _PROFILERCONFIG.fields_by_name['trace_log_duration_events']._serialized_options = b'\030\001'
37
+ _CALCULATORGRAPHCONFIG_NODE.fields_by_name['profiler_config']._options = None
38
+ _CALCULATORGRAPHCONFIG_NODE.fields_by_name['profiler_config']._serialized_options = b'\030\001'
39
+ _CALCULATORGRAPHCONFIG.fields_by_name['packet_generator']._options = None
40
+ _CALCULATORGRAPHCONFIG.fields_by_name['packet_generator']._serialized_options = b'\030\001'
41
+ _globals['_EXECUTORCONFIG']._serialized_start=339
42
+ _globals['_EXECUTORCONFIG']._serialized_end=429
43
+ _globals['_INPUTCOLLECTION']._serialized_start=432
44
+ _globals['_INPUTCOLLECTION']._serialized_end=705
45
+ _globals['_INPUTCOLLECTION_INPUTTYPE']._serialized_start=598
46
+ _globals['_INPUTCOLLECTION_INPUTTYPE']._serialized_end=705
47
+ _globals['_INPUTCOLLECTIONSET']._serialized_start=707
48
+ _globals['_INPUTCOLLECTIONSET']._serialized_end=781
49
+ _globals['_INPUTSTREAMINFO']._serialized_start=783
50
+ _globals['_INPUTSTREAMINFO']._serialized_end=838
51
+ _globals['_PROFILERCONFIG']._serialized_start=841
52
+ _globals['_PROFILERCONFIG']._serialized_end=1434
53
+ _globals['_GRAPHRUNTIMEINFOCONFIG']._serialized_start=1436
54
+ _globals['_GRAPHRUNTIMEINFOCONFIG']._serialized_end=1524
55
+ _globals['_CALCULATORGRAPHCONFIG']._serialized_start=1527
56
+ _globals['_CALCULATORGRAPHCONFIG']._serialized_end=2980
57
+ _globals['_CALCULATORGRAPHCONFIG_NODE']._serialized_start=2366
58
+ _globals['_CALCULATORGRAPHCONFIG_NODE']._serialized_end=2980
59
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/calculator_profile_pb2.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/calculator_profile.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+
20
+
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,mediapipe/framework/calculator_profile.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\"o\n\rTimeHistogram\x12\x10\n\x05total\x18\x01 \x01(\x03:\x01\x30\x12#\n\x12interval_size_usec\x18\x02 \x01(\x03:\x07\x31\x30\x30\x30\x30\x30\x30\x12\x18\n\rnum_intervals\x18\x03 \x01(\x03:\x01\x31\x12\r\n\x05\x63ount\x18\x04 \x03(\x03\"b\n\rStreamProfile\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x18\n\tback_edge\x18\x02 \x01(\x08:\x05\x66\x61lse\x12)\n\x07latency\x18\x03 \x01(\x0b\x32\x18.mediapipe.TimeHistogram\"\xb3\x02\n\x11\x43\x61lculatorProfile\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x17\n\x0copen_runtime\x18\x02 \x01(\x03:\x01\x30\x12\x18\n\rclose_runtime\x18\x03 \x01(\x03:\x01\x30\x12\x31\n\x0fprocess_runtime\x18\x04 \x01(\x0b\x32\x18.mediapipe.TimeHistogram\x12\x37\n\x15process_input_latency\x18\x05 \x01(\x0b\x32\x18.mediapipe.TimeHistogram\x12\x38\n\x16process_output_latency\x18\x06 \x01(\x0b\x32\x18.mediapipe.TimeHistogram\x12\x37\n\x15input_stream_profiles\x18\x07 \x03(\x0b\x32\x18.mediapipe.StreamProfile\"\xe1\x07\n\nGraphTrace\x12\x11\n\tbase_time\x18\x01 \x01(\x03\x12\x16\n\x0e\x62\x61se_timestamp\x18\x02 \x01(\x03\x12\x17\n\x0f\x63\x61lculator_name\x18\x03 \x03(\t\x12\x13\n\x0bstream_name\x18\x04 \x03(\t\x12?\n\x10\x63\x61lculator_trace\x18\x05 \x03(\x0b\x32%.mediapipe.GraphTrace.CalculatorTrace\x1a\x8e\x01\n\x0bStreamTrace\x12\x12\n\nstart_time\x18\x01 \x01(\x03\x12\x13\n\x0b\x66inish_time\x18\x02 \x01(\x03\x12\x18\n\x10packet_timestamp\x18\x03 \x01(\x03\x12\x11\n\tstream_id\x18\x04 \x01(\x05\x12\x15\n\tpacket_id\x18\x05 \x01(\x03\x42\x02\x18\x01\x12\x12\n\nevent_data\x18\x06 \x01(\x03\x1a\x9d\x02\n\x0f\x43\x61lculatorTrace\x12\x0f\n\x07node_id\x18\x01 \x01(\x05\x12\x17\n\x0finput_timestamp\x18\x02 \x01(\x03\x12\x33\n\nevent_type\x18\x03 \x01(\x0e\x32\x1f.mediapipe.GraphTrace.EventType\x12\x12\n\nstart_time\x18\x04 \x01(\x03\x12\x13\n\x0b\x66inish_time\x18\x05 \x01(\x03\x12\x36\n\x0binput_trace\x18\x06 \x03(\x0b\x32!.mediapipe.GraphTrace.StreamTrace\x12\x37\n\x0coutput_trace\x18\x07 \x03(\x0b\x32!.mediapipe.GraphTrace.StreamTrace\x12\x11\n\tthread_id\x18\x08 \x01(\x05\"\x87\x03\n\tEventType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x08\n\x04OPEN\x10\x01\x12\x0b\n\x07PROCESS\x10\x02\x12\t\n\x05\x43LOSE\x10\x03\x12\r\n\tNOT_READY\x10\x04\x12\x15\n\x11READY_FOR_PROCESS\x10\x05\x12\x13\n\x0fREADY_FOR_CLOSE\x10\x06\x12\r\n\tTHROTTLED\x10\x07\x12\x0f\n\x0bUNTHROTTLED\x10\x08\x12\x11\n\rCPU_TASK_USER\x10\t\x12\x13\n\x0f\x43PU_TASK_SYSTEM\x10\n\x12\x0c\n\x08GPU_TASK\x10\x0b\x12\x0c\n\x08\x44SP_TASK\x10\x0c\x12\x0c\n\x08TPU_TASK\x10\r\x12\x13\n\x0fGPU_CALIBRATION\x10\x0e\x12\x11\n\rPACKET_QUEUED\x10\x0f\x12\x13\n\x0fGPU_TASK_INVOKE\x10\x10\x12\x13\n\x0fTPU_TASK_INVOKE\x10\x11\x12\x13\n\x0f\x43PU_TASK_INVOKE\x10\x12\x12\x1c\n\x18GPU_TASK_INVOKE_ADVANCED\x10\x13\x12\x19\n\x15TPU_TASK_INVOKE_ASYNC\x10\x14\"\xa7\x01\n\x0cGraphProfile\x12*\n\x0bgraph_trace\x18\x01 \x03(\x0b\x32\x15.mediapipe.GraphTrace\x12\x39\n\x13\x63\x61lculator_profiles\x18\x02 \x03(\x0b\x32\x1c.mediapipe.CalculatorProfile\x12\x30\n\x06\x63onfig\x18\x03 \x01(\x0b\x32 .mediapipe.CalculatorGraphConfigB4\n\x1a\x63om.google.mediapipe.protoB\x16\x43\x61lculatorProfileProto')
22
+
23
+ _globals = globals()
24
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.calculator_profile_pb2', _globals)
26
+ if _descriptor._USE_C_DESCRIPTORS == False:
27
+
28
+ DESCRIPTOR._options = None
29
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\026CalculatorProfileProto'
30
+ _GRAPHTRACE_STREAMTRACE.fields_by_name['packet_id']._options = None
31
+ _GRAPHTRACE_STREAMTRACE.fields_by_name['packet_id']._serialized_options = b'\030\001'
32
+ _globals['_TIMEHISTOGRAM']._serialized_start=97
33
+ _globals['_TIMEHISTOGRAM']._serialized_end=208
34
+ _globals['_STREAMPROFILE']._serialized_start=210
35
+ _globals['_STREAMPROFILE']._serialized_end=308
36
+ _globals['_CALCULATORPROFILE']._serialized_start=311
37
+ _globals['_CALCULATORPROFILE']._serialized_end=618
38
+ _globals['_GRAPHTRACE']._serialized_start=621
39
+ _globals['_GRAPHTRACE']._serialized_end=1614
40
+ _globals['_GRAPHTRACE_STREAMTRACE']._serialized_start=790
41
+ _globals['_GRAPHTRACE_STREAMTRACE']._serialized_end=932
42
+ _globals['_GRAPHTRACE_CALCULATORTRACE']._serialized_start=935
43
+ _globals['_GRAPHTRACE_CALCULATORTRACE']._serialized_end=1220
44
+ _globals['_GRAPHTRACE_EVENTTYPE']._serialized_start=1223
45
+ _globals['_GRAPHTRACE_EVENTTYPE']._serialized_end=1614
46
+ _globals['_GRAPHPROFILE']._serialized_start=1617
47
+ _globals['_GRAPHPROFILE']._serialized_end=1784
48
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/graph_runtime_info_pb2.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/graph_runtime_info.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,mediapipe/framework/graph_runtime_info.proto\x12\tmediapipe\"\x81\x01\n\x11StreamRuntimeInfo\x12\x13\n\x0bstream_name\x18\x01 \x01(\t\x12\x12\n\nqueue_size\x18\x02 \x01(\x05\x12\x1f\n\x17number_of_packets_added\x18\x03 \x01(\x05\x12\"\n\x1aminimum_timestamp_or_bound\x18\x04 \x01(\x03\"\xcc\x01\n\x15\x43\x61lculatorRuntimeInfo\x12\x17\n\x0f\x63\x61lculator_name\x18\x01 \x01(\t\x12\"\n\x1alast_process_start_unix_us\x18\x02 \x01(\x03\x12#\n\x1blast_process_finish_unix_us\x18\x03 \x01(\x03\x12\x17\n\x0ftimestamp_bound\x18\x04 \x01(\x03\x12\x38\n\x12input_stream_infos\x18\x05 \x03(\x0b\x32\x1c.mediapipe.StreamRuntimeInfo\"l\n\x10GraphRuntimeInfo\x12\x1c\n\x14\x63\x61pture_time_unix_us\x18\x01 \x01(\x03\x12:\n\x10\x63\x61lculator_infos\x18\x02 \x03(\x0b\x32 .mediapipe.CalculatorRuntimeInfoB3\n\x1a\x63om.google.mediapipe.protoB\x15GraphRuntimeInfoProtob\x06proto3')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.graph_runtime_info_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\025GraphRuntimeInfoProto'
25
+ _globals['_STREAMRUNTIMEINFO']._serialized_start=60
26
+ _globals['_STREAMRUNTIMEINFO']._serialized_end=189
27
+ _globals['_CALCULATORRUNTIMEINFO']._serialized_start=192
28
+ _globals['_CALCULATORRUNTIMEINFO']._serialized_end=396
29
+ _globals['_GRAPHRUNTIMEINFO']._serialized_start=398
30
+ _globals['_GRAPHRUNTIMEINFO']._serialized_end=506
31
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/mediapipe_options_pb2.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/mediapipe_options.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n+mediapipe/framework/mediapipe_options.proto\x12\tmediapipe\"\x1e\n\x10MediaPipeOptions*\n\x08\xa0\x9c\x01\x10\x80\x80\x80\x80\x02\x42\x33\n\x1a\x63om.google.mediapipe.protoB\x15MediaPipeOptionsProto')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.mediapipe_options_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\025MediaPipeOptionsProto'
25
+ _globals['_MEDIAPIPEOPTIONS']._serialized_start=58
26
+ _globals['_MEDIAPIPEOPTIONS']._serialized_end=88
27
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/packet_factory_pb2.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/packet_factory.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(mediapipe/framework/packet_factory.proto\x12\tmediapipe\"\"\n\x14PacketFactoryOptions*\n\x08\xa0\x9c\x01\x10\x80\x80\x80\x80\x02\"\x95\x01\n\x13PacketFactoryConfig\x12\x16\n\x0epacket_factory\x18\x01 \x01(\t\x12\x1a\n\x12output_side_packet\x18\x02 \x01(\t\x12\x18\n\x0f\x65xternal_output\x18\xea\x07 \x01(\t\x12\x30\n\x07options\x18\x03 \x01(\x0b\x32\x1f.mediapipe.PacketFactoryOptions\"E\n\x13PacketManagerConfig\x12.\n\x06packet\x18\x01 \x03(\x0b\x32\x1e.mediapipe.PacketFactoryConfigB0\n\x1a\x63om.google.mediapipe.protoB\x12PacketFactoryProto')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.packet_factory_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\022PacketFactoryProto'
25
+ _globals['_PACKETFACTORYOPTIONS']._serialized_start=55
26
+ _globals['_PACKETFACTORYOPTIONS']._serialized_end=89
27
+ _globals['_PACKETFACTORYCONFIG']._serialized_start=92
28
+ _globals['_PACKETFACTORYCONFIG']._serialized_end=241
29
+ _globals['_PACKETMANAGERCONFIG']._serialized_start=243
30
+ _globals['_PACKETMANAGERCONFIG']._serialized_end=312
31
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/packet_generator_pb2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/packet_generator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n*mediapipe/framework/packet_generator.proto\x12\tmediapipe\"D\n\x16PacketGeneratorOptions\x12\x1a\n\x0cmerge_fields\x18\x01 \x01(\x08:\x04true*\n\x08\xa0\x9c\x01\x10\x80\x80\x80\x80\x02:\x02\x18\x01\"\xd3\x01\n\x15PacketGeneratorConfig\x12\x18\n\x10packet_generator\x18\x01 \x01(\t\x12\x19\n\x11input_side_packet\x18\x02 \x03(\t\x12\x17\n\x0e\x65xternal_input\x18\xea\x07 \x03(\t\x12\x1a\n\x12output_side_packet\x18\x03 \x03(\t\x12\x18\n\x0f\x65xternal_output\x18\xeb\x07 \x03(\t\x12\x32\n\x07options\x18\x04 \x01(\x0b\x32!.mediapipe.PacketGeneratorOptions:\x02\x18\x01\x42\x32\n\x1a\x63om.google.mediapipe.protoB\x14PacketGeneratorProto')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.packet_generator_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\024PacketGeneratorProto'
25
+ _PACKETGENERATOROPTIONS._options = None
26
+ _PACKETGENERATOROPTIONS._serialized_options = b'\030\001'
27
+ _PACKETGENERATORCONFIG._options = None
28
+ _PACKETGENERATORCONFIG._serialized_options = b'\030\001'
29
+ _globals['_PACKETGENERATOROPTIONS']._serialized_start=57
30
+ _globals['_PACKETGENERATOROPTIONS']._serialized_end=125
31
+ _globals['_PACKETGENERATORCONFIG']._serialized_start=128
32
+ _globals['_PACKETGENERATORCONFIG']._serialized_end=339
33
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/status_handler_pb2.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/status_handler.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import mediapipe_options_pb2 as mediapipe_dot_framework_dot_mediapipe__options__pb2
15
+
16
+
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(mediapipe/framework/status_handler.proto\x12\tmediapipe\x1a+mediapipe/framework/mediapipe_options.proto\"\x8f\x01\n\x13StatusHandlerConfig\x12\x16\n\x0estatus_handler\x18\x01 \x01(\t\x12\x19\n\x11input_side_packet\x18\x02 \x03(\t\x12\x17\n\x0e\x65xternal_input\x18\xea\x07 \x03(\t\x12,\n\x07options\x18\x03 \x01(\x0b\x32\x1b.mediapipe.MediaPipeOptionsB0\n\x1a\x63om.google.mediapipe.protoB\x12StatusHandlerProto')
18
+
19
+ _globals = globals()
20
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
21
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.status_handler_pb2', _globals)
22
+ if _descriptor._USE_C_DESCRIPTORS == False:
23
+
24
+ DESCRIPTOR._options = None
25
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\022StatusHandlerProto'
26
+ _globals['_STATUSHANDLERCONFIG']._serialized_start=101
27
+ _globals['_STATUSHANDLERCONFIG']._serialized_end=244
28
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/stream_handler_pb2.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/stream_handler.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import mediapipe_options_pb2 as mediapipe_dot_framework_dot_mediapipe__options__pb2
15
+
16
+
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(mediapipe/framework/stream_handler.proto\x12\tmediapipe\x1a+mediapipe/framework/mediapipe_options.proto\"\x81\x01\n\x18InputStreamHandlerConfig\x12\x37\n\x14input_stream_handler\x18\x01 \x01(\t:\x19\x44\x65\x66\x61ultInputStreamHandler\x12,\n\x07options\x18\x03 \x01(\x0b\x32\x1b.mediapipe.MediaPipeOptions\"\x9f\x01\n\x19OutputStreamHandlerConfig\x12\x39\n\x15output_stream_handler\x18\x01 \x01(\t:\x1aInOrderOutputStreamHandler\x12\x19\n\x11input_side_packet\x18\x02 \x03(\t\x12,\n\x07options\x18\x03 \x01(\x0b\x32\x1b.mediapipe.MediaPipeOptionsB0\n\x1a\x63om.google.mediapipe.protoB\x12StreamHandlerProto')
18
+
19
+ _globals = globals()
20
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
21
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.stream_handler_pb2', _globals)
22
+ if _descriptor._USE_C_DESCRIPTORS == False:
23
+
24
+ DESCRIPTOR._options = None
25
+ DESCRIPTOR._serialized_options = b'\n\032com.google.mediapipe.protoB\022StreamHandlerProto'
26
+ _globals['_INPUTSTREAMHANDLERCONFIG']._serialized_start=101
27
+ _globals['_INPUTSTREAMHANDLERCONFIG']._serialized_end=230
28
+ _globals['_OUTPUTSTREAMHANDLERCONFIG']._serialized_start=233
29
+ _globals['_OUTPUTSTREAMHANDLERCONFIG']._serialized_end=392
30
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/test_calculators_pb2.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/test_calculators.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+
20
+
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n*mediapipe/framework/test_calculators.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\"\xdd\x01\n\x1dRandomMatrixCalculatorOptions\x12\x0c\n\x04rows\x18\x01 \x01(\x05\x12\x0c\n\x04\x63ols\x18\x02 \x01(\x05\x12\x17\n\x0fstart_timestamp\x18\x03 \x01(\x03\x12\x17\n\x0flimit_timestamp\x18\x04 \x01(\x03\x12\x16\n\x0etimestamp_step\x18\x05 \x01(\x03\x32V\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\xc8\xa0\xe9\x18 \x01(\x0b\x32(.mediapipe.RandomMatrixCalculatorOptions')
22
+
23
+ _globals = globals()
24
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.test_calculators_pb2', _globals)
26
+ if _descriptor._USE_C_DESCRIPTORS == False:
27
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_RANDOMMATRIXCALCULATOROPTIONS.extensions_by_name['ext'])
28
+
29
+ DESCRIPTOR._options = None
30
+ _globals['_RANDOMMATRIXCALCULATOROPTIONS']._serialized_start=96
31
+ _globals['_RANDOMMATRIXCALCULATOROPTIONS']._serialized_end=317
32
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/framework/thread_pool_executor_pb2.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/framework/thread_pool_executor.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import mediapipe_options_pb2 as mediapipe_dot_framework_dot_mediapipe__options__pb2
15
+
16
+
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n.mediapipe/framework/thread_pool_executor.proto\x12\tmediapipe\x1a+mediapipe/framework/mediapipe_options.proto\"\xe9\x02\n\x19ThreadPoolExecutorOptions\x12\x13\n\x0bnum_threads\x18\x01 \x01(\x05\x12\x12\n\nstack_size\x18\x02 \x01(\x05\x12\x1b\n\x13nice_priority_level\x18\x03 \x01(\x05\x12`\n\x1drequire_processor_performance\x18\x04 \x01(\x0e\x32\x39.mediapipe.ThreadPoolExecutorOptions.ProcessorPerformance\x12\x1a\n\x12thread_name_prefix\x18\x05 \x01(\t\"5\n\x14ProcessorPerformance\x12\n\n\x06NORMAL\x10\x00\x12\x07\n\x03LOW\x10\x01\x12\x08\n\x04HIGH\x10\x02\x32Q\n\x03\x65xt\x12\x1b.mediapipe.MediaPipeOptions\x18\x93\xd3\xf5J \x01(\x0b\x32$.mediapipe.ThreadPoolExecutorOptions')
18
+
19
+ _globals = globals()
20
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
21
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.framework.thread_pool_executor_pb2', _globals)
22
+ if _descriptor._USE_C_DESCRIPTORS == False:
23
+ mediapipe_dot_framework_dot_mediapipe__options__pb2.MediaPipeOptions.RegisterExtension(_THREADPOOLEXECUTOROPTIONS.extensions_by_name['ext'])
24
+
25
+ DESCRIPTOR._options = None
26
+ _globals['_THREADPOOLEXECUTOROPTIONS']._serialized_start=107
27
+ _globals['_THREADPOOLEXECUTOROPTIONS']._serialized_end=468
28
+ _globals['_THREADPOOLEXECUTOROPTIONS_PROCESSORPERFORMANCE']._serialized_start=332
29
+ _globals['_THREADPOOLEXECUTOROPTIONS_PROCESSORPERFORMANCE']._serialized_end=385
30
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/gpu/copy_calculator_pb2.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/copy_calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+
20
+
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n#mediapipe/gpu/copy_calculator.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\"\xd7\x01\n\x15\x43opyCalculatorOptions\x12\x41\n\x08rotation\x18\x01 \x01(\x0e\x32).mediapipe.CopyCalculatorOptions.Rotation:\x04NONE\"+\n\x08Rotation\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x43\x43W\x10\x01\x12\x0c\n\x08\x43\x43W_FLIP\x10\x02\x32N\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\xb4\xf2\x91M \x01(\x0b\x32 .mediapipe.CopyCalculatorOptions')
22
+
23
+ _globals = globals()
24
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.copy_calculator_pb2', _globals)
26
+ if _descriptor._USE_C_DESCRIPTORS == False:
27
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_COPYCALCULATOROPTIONS.extensions_by_name['ext'])
28
+
29
+ DESCRIPTOR._options = None
30
+ _globals['_COPYCALCULATOROPTIONS']._serialized_start=89
31
+ _globals['_COPYCALCULATOROPTIONS']._serialized_end=304
32
+ _globals['_COPYCALCULATOROPTIONS_ROTATION']._serialized_start=181
33
+ _globals['_COPYCALCULATOROPTIONS_ROTATION']._serialized_end=224
34
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/gl_animation_overlay_calculator_pb2.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/gl_animation_overlay_calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+
20
+
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n3mediapipe/gpu/gl_animation_overlay_calculator.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\"\xaa\x02\n#GlAnimationOverlayCalculatorOptions\x12\x1a\n\x0c\x61spect_ratio\x18\x01 \x01(\x02:\x04\x30.75\x12 \n\x14vertical_fov_degrees\x18\x02 \x01(\x02:\x02\x37\x30\x12\"\n\x15z_clipping_plane_near\x18\x03 \x01(\x02:\x03\x30.1\x12\"\n\x14z_clipping_plane_far\x18\x04 \x01(\x02:\x04\x31\x30\x30\x30\x12\x1f\n\x13\x61nimation_speed_fps\x18\x05 \x01(\x02:\x02\x32\x35\x32\\\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\xfd\xc4\xaaS \x01(\x0b\x32..mediapipe.GlAnimationOverlayCalculatorOptions')
22
+
23
+ _globals = globals()
24
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.gl_animation_overlay_calculator_pb2', _globals)
26
+ if _descriptor._USE_C_DESCRIPTORS == False:
27
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_GLANIMATIONOVERLAYCALCULATOROPTIONS.extensions_by_name['ext'])
28
+
29
+ DESCRIPTOR._options = None
30
+ _globals['_GLANIMATIONOVERLAYCALCULATOROPTIONS']._serialized_start=105
31
+ _globals['_GLANIMATIONOVERLAYCALCULATOROPTIONS']._serialized_end=403
32
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/gl_context_options_pb2.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/gl_context_options.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+
20
+
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n&mediapipe/gpu/gl_context_options.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\"v\n\x10GlContextOptions\x12\x17\n\x0fgl_context_name\x18\x01 \x01(\t2I\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\x82\x89\x82j \x01(\x0b\x32\x1b.mediapipe.GlContextOptions')
22
+
23
+ _globals = globals()
24
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.gl_context_options_pb2', _globals)
26
+ if _descriptor._USE_C_DESCRIPTORS == False:
27
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_GLCONTEXTOPTIONS.extensions_by_name['ext'])
28
+
29
+ DESCRIPTOR._options = None
30
+ _globals['_GLCONTEXTOPTIONS']._serialized_start=91
31
+ _globals['_GLCONTEXTOPTIONS']._serialized_end=209
32
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/gl_scaler_calculator_pb2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/gl_scaler_calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+ from mediapipe.gpu import scale_mode_pb2 as mediapipe_dot_gpu_dot_scale__mode__pb2
20
+
21
+
22
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(mediapipe/gpu/gl_scaler_calculator.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\x1a\x1emediapipe/gpu/scale_mode.proto\"\x85\x03\n\x19GlScalerCalculatorOptions\x12\x14\n\x0coutput_width\x18\x01 \x01(\x05\x12\x15\n\routput_height\x18\x02 \x01(\x05\x12\x17\n\x0coutput_scale\x18\x07 \x01(\x02:\x01\x31\x12\x10\n\x08rotation\x18\x03 \x01(\x05\x12\x15\n\rflip_vertical\x18\x04 \x01(\x08\x12\x17\n\x0f\x66lip_horizontal\x18\x05 \x01(\x08\x12-\n\nscale_mode\x18\x06 \x01(\x0e\x32\x19.mediapipe.ScaleMode.Mode\x12\x31\n\"use_nearest_neighbor_interpolation\x18\x08 \x01(\x08:\x05\x66\x61lse\x12*\n\x1buse_input_format_for_output\x18\t \x01(\x08:\x05\x66\x61lse2R\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\x96\xcd\xaaO \x01(\x0b\x32$.mediapipe.GlScalerCalculatorOptions')
23
+
24
+ _globals = globals()
25
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
26
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.gl_scaler_calculator_pb2', _globals)
27
+ if _descriptor._USE_C_DESCRIPTORS == False:
28
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_GLSCALERCALCULATOROPTIONS.extensions_by_name['ext'])
29
+
30
+ DESCRIPTOR._options = None
31
+ _globals['_GLSCALERCALCULATOROPTIONS']._serialized_start=126
32
+ _globals['_GLSCALERCALCULATOROPTIONS']._serialized_end=515
33
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/gl_surface_sink_calculator_pb2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/gl_surface_sink_calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+ from mediapipe.gpu import scale_mode_pb2 as mediapipe_dot_gpu_dot_scale__mode__pb2
20
+
21
+
22
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n.mediapipe/gpu/gl_surface_sink_calculator.proto\x12\tmediapipe\x1a$mediapipe/framework/calculator.proto\x1a\x1emediapipe/gpu/scale_mode.proto\"\xae\x01\n\x1eGlSurfaceSinkCalculatorOptions\x12\x33\n\x10\x66rame_scale_mode\x18\x01 \x01(\x0e\x32\x19.mediapipe.ScaleMode.Mode2W\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\x8a\xfb\x83t \x01(\x0b\x32).mediapipe.GlSurfaceSinkCalculatorOptions')
23
+
24
+ _globals = globals()
25
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
26
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.gl_surface_sink_calculator_pb2', _globals)
27
+ if _descriptor._USE_C_DESCRIPTORS == False:
28
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_GLSURFACESINKCALCULATOROPTIONS.extensions_by_name['ext'])
29
+
30
+ DESCRIPTOR._options = None
31
+ _globals['_GLSURFACESINKCALCULATOROPTIONS']._serialized_start=132
32
+ _globals['_GLSURFACESINKCALCULATOROPTIONS']._serialized_end=306
33
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/gpu_origin_pb2.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/gpu_origin.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1emediapipe/gpu/gpu_origin.proto\x12\tmediapipe\"@\n\tGpuOrigin\"3\n\x04Mode\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x10\n\x0c\x43ONVENTIONAL\x10\x01\x12\x0c\n\x08TOP_LEFT\x10\x02\x42*\n\x18\x63om.google.mediapipe.gpuB\x0eGpuOriginProtob\x06proto3')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.gpu_origin_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n\030com.google.mediapipe.gpuB\016GpuOriginProto'
25
+ _globals['_GPUORIGIN']._serialized_start=45
26
+ _globals['_GPUORIGIN']._serialized_end=109
27
+ _globals['_GPUORIGIN_MODE']._serialized_start=58
28
+ _globals['_GPUORIGIN_MODE']._serialized_end=109
29
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/gpu/scale_mode_pb2.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/gpu/scale_mode.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1emediapipe/gpu/scale_mode.proto\x12\tmediapipe\"I\n\tScaleMode\"<\n\x04Mode\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x0b\n\x07STRETCH\x10\x01\x12\x07\n\x03\x46IT\x10\x02\x12\x11\n\rFILL_AND_CROP\x10\x03')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.gpu.scale_mode_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ _globals['_SCALEMODE']._serialized_start=45
25
+ _globals['_SCALEMODE']._serialized_end=118
26
+ _globals['_SCALEMODE_MODE']._serialized_start=58
27
+ _globals['_SCALEMODE_MODE']._serialized_end=118
28
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/model_maker/__init__.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from mediapipe.model_maker.python.vision.core import image_utils
17
+ from mediapipe.model_maker.python.core.utils import quantization
18
+ from mediapipe.model_maker.python.core.utils import model_util
19
+
20
+ from mediapipe.model_maker.python.vision import image_classifier
21
+ from mediapipe.model_maker.python.vision import gesture_recognizer
22
+ from mediapipe.model_maker.python.text import text_classifier
23
+ from mediapipe.model_maker.python.vision import object_detector
24
+ from mediapipe.model_maker.python.vision import face_stylizer
25
+
26
+ # Remove duplicated and non-public API
27
+ del python
python_embeded/Lib/site-packages/mediapipe/model_maker/setup.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Copyright 2020-2022 The MediaPipe Authors.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ Setup for Mediapipe-Model-Maker package with setuptools.
16
+ """
17
+
18
+ import glob
19
+ import os
20
+ import shutil
21
+ import setuptools
22
+
23
+
24
+ __version__ = 'dev'
25
+ MM_ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
26
+ # Build dir to copy all necessary files and build package
27
+ SRC_NAME = 'pip_src'
28
+ BUILD_DIR = os.path.join(MM_ROOT_PATH, SRC_NAME)
29
+ BUILD_MM_DIR = os.path.join(BUILD_DIR, 'mediapipe_model_maker')
30
+
31
+
32
+ def _parse_requirements(path):
33
+ with open(os.path.join(MM_ROOT_PATH, path)) as f:
34
+ return [
35
+ line.rstrip()
36
+ for line in f
37
+ if not (line.isspace() or line.startswith('#'))
38
+ ]
39
+
40
+
41
+ def _setup_build_dir():
42
+ """Setup the BUILD_DIR directory to build the mediapipe_model_maker package.
43
+
44
+ We need to create a new BUILD_DIR directory because any references to the path
45
+ `mediapipe/model_maker` needs to be renamed to `mediapipe_model_maker` to
46
+ avoid conflicting with the mediapipe package name.
47
+ This setup function performs the following actions:
48
+ 1. Copy python source code into BUILD_DIR and rename imports to
49
+ mediapipe_model_maker
50
+ 2. Download models from GCS into BUILD_DIR
51
+ """
52
+ # Copy python source code into BUILD_DIR
53
+ if os.path.exists(BUILD_DIR):
54
+ shutil.rmtree(BUILD_DIR)
55
+ python_files = glob.glob('python/**/*.py', recursive=True)
56
+ python_files.append('__init__.py')
57
+ for python_file in python_files:
58
+ # Exclude test files from pip package
59
+ if '_test.py' in python_file:
60
+ continue
61
+ build_target_file = os.path.join(BUILD_MM_DIR, python_file)
62
+ with open(python_file, 'r') as file:
63
+ filedata = file.read()
64
+ # Rename all mediapipe.model_maker imports to mediapipe_model_maker
65
+ filedata = filedata.replace('from mediapipe.model_maker',
66
+ 'from mediapipe_model_maker')
67
+ os.makedirs(os.path.dirname(build_target_file), exist_ok=True)
68
+ with open(build_target_file, 'w') as file:
69
+ file.write(filedata)
70
+
71
+ _setup_build_dir()
72
+
73
+ setuptools.setup(
74
+ name='mediapipe-model-maker',
75
+ version=__version__,
76
+ url='https://github.com/google/mediapipe/tree/master/mediapipe/model_maker',
77
+ description='MediaPipe Model Maker is a simple, low-code solution for customizing on-device ML models',
78
+ author='The MediaPipe Authors',
79
+ author_email='mediapipe@google.com',
80
+ long_description='',
81
+ long_description_content_type='text/markdown',
82
+ packages=setuptools.find_packages(where=SRC_NAME),
83
+ package_dir={'': SRC_NAME},
84
+ install_requires=_parse_requirements('requirements.txt'),
85
+ include_package_data=True,
86
+ classifiers=[
87
+ 'Development Status :: 3 - Alpha',
88
+ 'Intended Audience :: Developers',
89
+ 'Intended Audience :: Education',
90
+ 'Intended Audience :: Science/Research',
91
+ 'License :: OSI Approved :: Apache Software License',
92
+ 'Operating System :: MacOS :: MacOS X',
93
+ 'Operating System :: Microsoft :: Windows',
94
+ 'Operating System :: POSIX :: Linux',
95
+ 'Programming Language :: Python :: 3.8',
96
+ 'Programming Language :: Python :: 3.9',
97
+ 'Programming Language :: Python :: 3.10',
98
+ 'Programming Language :: Python :: 3 :: Only',
99
+ 'Topic :: Scientific/Engineering',
100
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
101
+ 'Topic :: Software Development',
102
+ 'Topic :: Software Development :: Libraries',
103
+ 'Topic :: Software Development :: Libraries :: Python Modules',
104
+ ],
105
+ license='Apache 2.0',
106
+ keywords=['mediapipe', 'model', 'maker'],
107
+ )
python_embeded/Lib/site-packages/mediapipe/modules/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/python/__init__.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020-2021 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """MediaPipe Python API."""
16
+
17
+ from mediapipe.python._framework_bindings import model_ckpt_util
18
+ from mediapipe.python._framework_bindings import resource_util
19
+ from mediapipe.python._framework_bindings.calculator_graph import CalculatorGraph
20
+ from mediapipe.python._framework_bindings.calculator_graph import GraphInputStreamAddMode
21
+ from mediapipe.python._framework_bindings.image import Image
22
+ from mediapipe.python._framework_bindings.image_frame import ImageFormat
23
+ from mediapipe.python._framework_bindings.image_frame import ImageFrame
24
+ from mediapipe.python._framework_bindings.matrix import Matrix
25
+ from mediapipe.python._framework_bindings.packet import Packet
26
+ from mediapipe.python._framework_bindings.timestamp import Timestamp
27
+ from mediapipe.python._framework_bindings.validated_graph_config import ValidatedGraphConfig
28
+ import mediapipe.python.packet_creator
29
+ import mediapipe.python.packet_getter
python_embeded/Lib/site-packages/mediapipe/python/calculator_graph_test.py ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python._framework_bindings.calculator_graph."""
16
+
17
+ from absl.testing import absltest
18
+
19
+ from google.protobuf import text_format
20
+ from mediapipe.framework import calculator_pb2
21
+ from mediapipe.python import packet_creator
22
+ from mediapipe.python import packet_getter
23
+ from mediapipe.python._framework_bindings import calculator_graph
24
+ from mediapipe.python._framework_bindings import validated_graph_config
25
+
26
+ CalculatorGraph = calculator_graph.CalculatorGraph
27
+ ValidatedGraphConfig = validated_graph_config.ValidatedGraphConfig
28
+
29
+
30
+ class GraphTest(absltest.TestCase):
31
+
32
+ def test_invalid_binary_graph_file(self):
33
+ with self.assertRaisesRegex(
34
+ FileNotFoundError,
35
+ '(No such file or directory|The path does not exist)'):
36
+ CalculatorGraph(binary_graph_path='/tmp/abc.binarypb')
37
+
38
+ def test_invalid_node_config(self):
39
+ text_config = """
40
+ node {
41
+ calculator: 'PassThroughCalculator'
42
+ input_stream: 'in'
43
+ input_stream: 'in'
44
+ output_stream: 'out'
45
+ }
46
+ """
47
+ config_proto = calculator_pb2.CalculatorGraphConfig()
48
+ text_format.Parse(text_config, config_proto)
49
+ with self.assertRaisesRegex(
50
+ ValueError,
51
+ 'Input and output streams to PassThroughCalculator must use matching tags and indexes.'
52
+ ):
53
+ CalculatorGraph(graph_config=config_proto)
54
+
55
+ def test_invalid_calculator_type(self):
56
+ text_config = """
57
+ node {
58
+ calculator: 'SomeUnknownCalculator'
59
+ input_stream: 'in'
60
+ output_stream: 'out'
61
+ }
62
+ """
63
+ config_proto = calculator_pb2.CalculatorGraphConfig()
64
+ text_format.Parse(text_config, config_proto)
65
+ with self.assertRaisesRegex(
66
+ RuntimeError, 'Unable to find Calculator \"SomeUnknownCalculator\"'):
67
+ CalculatorGraph(graph_config=config_proto)
68
+
69
+ def test_graph_initialized_with_proto_config(self):
70
+ text_config = """
71
+ max_queue_size: 1
72
+ input_stream: 'in'
73
+ output_stream: 'out'
74
+ node {
75
+ calculator: 'PassThroughCalculator'
76
+ input_stream: 'in'
77
+ output_stream: 'out'
78
+ }
79
+ """
80
+ config_proto = calculator_pb2.CalculatorGraphConfig()
81
+ text_format.Parse(text_config, config_proto)
82
+ graph = CalculatorGraph(graph_config=config_proto)
83
+
84
+ hello_world_packet = packet_creator.create_string('hello world')
85
+ out = []
86
+ graph = CalculatorGraph(graph_config=config_proto)
87
+ graph.observe_output_stream('out', lambda _, packet: out.append(packet))
88
+ graph.start_run()
89
+ graph.add_packet_to_input_stream(
90
+ stream='in', packet=hello_world_packet, timestamp=0)
91
+ graph.add_packet_to_input_stream(
92
+ stream='in', packet=hello_world_packet.at(1))
93
+ graph.close()
94
+ self.assertEqual(
95
+ graph.graph_input_stream_add_mode,
96
+ calculator_graph.GraphInputStreamAddMode.WAIT_TILL_NOT_FULL)
97
+ self.assertEqual(graph.max_queue_size, 1)
98
+ self.assertFalse(graph.has_error())
99
+ self.assertLen(out, 2)
100
+ self.assertEqual(out[0].timestamp, 0)
101
+ self.assertEqual(out[1].timestamp, 1)
102
+ self.assertEqual(packet_getter.get_str(out[0]), 'hello world')
103
+ self.assertEqual(packet_getter.get_str(out[1]), 'hello world')
104
+
105
+ def test_graph_initialized_with_text_config(self):
106
+ text_config = """
107
+ max_queue_size: 1
108
+ input_stream: 'in'
109
+ output_stream: 'out'
110
+ node {
111
+ calculator: 'PassThroughCalculator'
112
+ input_stream: 'in'
113
+ output_stream: 'out'
114
+ }
115
+ """
116
+
117
+ hello_world_packet = packet_creator.create_string('hello world')
118
+ out = []
119
+ graph = CalculatorGraph(graph_config=text_config)
120
+ graph.observe_output_stream('out', lambda _, packet: out.append(packet))
121
+ graph.start_run()
122
+ graph.add_packet_to_input_stream(
123
+ stream='in', packet=hello_world_packet.at(0))
124
+ graph.add_packet_to_input_stream(
125
+ stream='in', packet=hello_world_packet, timestamp=1)
126
+ graph.close()
127
+ self.assertEqual(
128
+ graph.graph_input_stream_add_mode,
129
+ calculator_graph.GraphInputStreamAddMode.WAIT_TILL_NOT_FULL)
130
+ self.assertEqual(graph.max_queue_size, 1)
131
+ self.assertFalse(graph.has_error())
132
+ self.assertLen(out, 2)
133
+ self.assertEqual(out[0].timestamp, 0)
134
+ self.assertEqual(out[1].timestamp, 1)
135
+ self.assertEqual(packet_getter.get_str(out[0]), 'hello world')
136
+ self.assertEqual(packet_getter.get_str(out[1]), 'hello world')
137
+
138
+ def test_graph_validation_and_initialization(self):
139
+ text_config = """
140
+ max_queue_size: 1
141
+ input_stream: 'in'
142
+ output_stream: 'out'
143
+ node {
144
+ calculator: 'PassThroughCalculator'
145
+ input_stream: 'in'
146
+ output_stream: 'out'
147
+ }
148
+ """
149
+
150
+ hello_world_packet = packet_creator.create_string('hello world')
151
+ out = []
152
+ validated_graph = ValidatedGraphConfig()
153
+ self.assertFalse(validated_graph.initialized())
154
+ validated_graph.initialize(graph_config=text_config)
155
+ self.assertTrue(validated_graph.initialized())
156
+
157
+ graph = CalculatorGraph(validated_graph_config=validated_graph)
158
+ graph.observe_output_stream('out', lambda _, packet: out.append(packet))
159
+ graph.start_run()
160
+ graph.add_packet_to_input_stream(
161
+ stream='in', packet=hello_world_packet.at(0))
162
+ graph.add_packet_to_input_stream(
163
+ stream='in', packet=hello_world_packet, timestamp=1)
164
+ graph.close()
165
+ self.assertEqual(
166
+ graph.graph_input_stream_add_mode,
167
+ calculator_graph.GraphInputStreamAddMode.WAIT_TILL_NOT_FULL)
168
+ self.assertEqual(graph.max_queue_size, 1)
169
+ self.assertFalse(graph.has_error())
170
+ self.assertLen(out, 2)
171
+ self.assertEqual(out[0].timestamp, 0)
172
+ self.assertEqual(out[1].timestamp, 1)
173
+ self.assertEqual(packet_getter.get_str(out[0]), 'hello world')
174
+ self.assertEqual(packet_getter.get_str(out[1]), 'hello world')
175
+
176
+ def test_insert_packets_with_same_timestamp(self):
177
+ text_config = """
178
+ max_queue_size: 1
179
+ input_stream: 'in'
180
+ output_stream: 'out'
181
+ node {
182
+ calculator: 'PassThroughCalculator'
183
+ input_stream: 'in'
184
+ output_stream: 'out'
185
+ }
186
+ """
187
+ config_proto = calculator_pb2.CalculatorGraphConfig()
188
+ text_format.Parse(text_config, config_proto)
189
+
190
+ hello_world_packet = packet_creator.create_string('hello world')
191
+ out = []
192
+ graph = CalculatorGraph(graph_config=config_proto)
193
+ graph.observe_output_stream('out', lambda _, packet: out.append(packet))
194
+ graph.start_run()
195
+ graph.add_packet_to_input_stream(
196
+ stream='in', packet=hello_world_packet.at(0))
197
+ graph.wait_until_idle()
198
+ graph.add_packet_to_input_stream(
199
+ stream='in', packet=hello_world_packet.at(0))
200
+ with self.assertRaisesRegex(
201
+ ValueError, 'Current minimum expected timestamp is 1 but received 0.'):
202
+ graph.wait_until_idle()
203
+
204
+ def test_side_packet_graph(self):
205
+ text_config = """
206
+ node {
207
+ calculator: 'StringToUint64Calculator'
208
+ input_side_packet: "string"
209
+ output_side_packet: "number"
210
+ }
211
+ """
212
+ config_proto = calculator_pb2.CalculatorGraphConfig()
213
+ text_format.Parse(text_config, config_proto)
214
+ graph = CalculatorGraph(graph_config=config_proto)
215
+ graph.start_run(
216
+ input_side_packets={'string': packet_creator.create_string('42')})
217
+ graph.wait_until_done()
218
+ self.assertFalse(graph.has_error())
219
+ self.assertEqual(
220
+ packet_getter.get_uint(graph.get_output_side_packet('number')), 42)
221
+
222
+ def test_sequence_input(self):
223
+ text_config = """
224
+ max_queue_size: 1
225
+ input_stream: 'in'
226
+ output_stream: 'out'
227
+ node {
228
+ calculator: 'PassThroughCalculator'
229
+ input_stream: 'in'
230
+ output_stream: 'out'
231
+ }
232
+ """
233
+ hello_world_packet = packet_creator.create_string('hello world')
234
+ out = []
235
+ graph = CalculatorGraph(graph_config=text_config)
236
+ graph.observe_output_stream('out', lambda _, packet: out.append(packet))
237
+ graph.start_run()
238
+
239
+ sequence_size = 1000
240
+ for i in range(sequence_size):
241
+ graph.add_packet_to_input_stream(
242
+ stream='in', packet=hello_world_packet, timestamp=i)
243
+ graph.wait_until_idle()
244
+ self.assertLen(out, sequence_size)
245
+ for i in range(sequence_size):
246
+ self.assertEqual(out[i].timestamp, i)
247
+ self.assertEqual(packet_getter.get_str(out[i]), 'hello world')
248
+
249
+
250
+ if __name__ == '__main__':
251
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/python/image_frame_test.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python._framework_bindings.image_frame."""
16
+
17
+ import gc
18
+ import random
19
+ import sys
20
+
21
+ from absl.testing import absltest
22
+ import cv2
23
+ import numpy as np
24
+ import PIL.Image
25
+
26
+ from mediapipe.python._framework_bindings import image_frame
27
+
28
+ ImageFormat = image_frame.ImageFormat
29
+ ImageFrame = image_frame.ImageFrame
30
+
31
+
32
+ # TODO: Add unit tests specifically for memory management.
33
+ class ImageFrameTest(absltest.TestCase):
34
+
35
+ def test_create_image_frame_from_gray_cv_mat(self):
36
+ w, h = random.randrange(3, 100), random.randrange(3, 100)
37
+ mat = cv2.cvtColor(
38
+ np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8),
39
+ cv2.COLOR_RGB2GRAY)
40
+ mat[2, 2] = 42
41
+ gray8_image_frame = ImageFrame(image_format=ImageFormat.GRAY8, data=mat)
42
+ self.assertTrue(np.array_equal(mat, gray8_image_frame.numpy_view()))
43
+ with self.assertRaisesRegex(IndexError, 'index dimension mismatch'):
44
+ print(gray8_image_frame[w, h, 1])
45
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
46
+ print(gray8_image_frame[w, h])
47
+ self.assertEqual(42, gray8_image_frame[2, 2])
48
+
49
+ def test_create_image_frame_from_rgb_cv_mat(self):
50
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
51
+ mat = cv2.cvtColor(
52
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
53
+ cv2.COLOR_RGB2BGR)
54
+ mat[2, 2, 1] = 42
55
+ rgb_image_frame = ImageFrame(image_format=ImageFormat.SRGB, data=mat)
56
+ self.assertTrue(np.array_equal(mat, rgb_image_frame.numpy_view()))
57
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
58
+ print(rgb_image_frame[w, h, channels])
59
+ self.assertEqual(42, rgb_image_frame[2, 2, 1])
60
+
61
+ def test_create_image_frame_from_rgb48_cv_mat(self):
62
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
63
+ mat = cv2.cvtColor(
64
+ np.random.randint(2**16 - 1, size=(h, w, channels), dtype=np.uint16),
65
+ cv2.COLOR_RGB2BGR)
66
+ mat[2, 2, 1] = 42
67
+ rgb48_image_frame = ImageFrame(image_format=ImageFormat.SRGB48, data=mat)
68
+ self.assertTrue(np.array_equal(mat, rgb48_image_frame.numpy_view()))
69
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
70
+ print(rgb48_image_frame[w, h, channels])
71
+ self.assertEqual(42, rgb48_image_frame[2, 2, 1])
72
+
73
+ def test_create_image_frame_from_gray_pil_image(self):
74
+ w, h = random.randrange(3, 100), random.randrange(3, 100)
75
+ img = PIL.Image.fromarray(
76
+ np.random.randint(2**8 - 1, size=(h, w), dtype=np.uint8), 'L')
77
+ gray8_image_frame = ImageFrame(
78
+ image_format=ImageFormat.GRAY8, data=np.asarray(img))
79
+ self.assertTrue(
80
+ np.array_equal(np.asarray(img), gray8_image_frame.numpy_view()))
81
+ with self.assertRaisesRegex(IndexError, 'index dimension mismatch'):
82
+ print(gray8_image_frame[w, h, 1])
83
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
84
+ print(gray8_image_frame[w, h])
85
+
86
+ def test_create_image_frame_from_rgb_pil_image(self):
87
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
88
+ img = PIL.Image.fromarray(
89
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
90
+ 'RGB')
91
+ rgb_image_frame = ImageFrame(
92
+ image_format=ImageFormat.SRGB, data=np.asarray(img))
93
+ self.assertTrue(
94
+ np.array_equal(np.asarray(img), rgb_image_frame.numpy_view()))
95
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
96
+ print(rgb_image_frame[w, h, channels])
97
+
98
+ def test_create_image_frame_from_rgba64_pil_image(self):
99
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 4
100
+ img = PIL.Image.fromarray(
101
+ np.random.randint(2**16 - 1, size=(h, w, channels), dtype=np.uint16),
102
+ 'RGBA')
103
+ rgba_image_frame = ImageFrame(
104
+ image_format=ImageFormat.SRGBA64,
105
+ data=np.asarray(img).astype(np.uint16))
106
+ self.assertTrue(
107
+ np.array_equal(np.asarray(img), rgba_image_frame.numpy_view()))
108
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
109
+ print(rgba_image_frame[1000, 1000, 1000])
110
+
111
+ def test_image_frame_numby_view(self):
112
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
113
+ mat = cv2.cvtColor(
114
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
115
+ cv2.COLOR_RGB2BGR)
116
+ rgb_image_frame = ImageFrame(image_format=ImageFormat.SRGB, data=mat)
117
+ output_ndarray = rgb_image_frame.numpy_view()
118
+ self.assertTrue(np.array_equal(mat, rgb_image_frame.numpy_view()))
119
+ # The output of numpy_view() is a reference to the internal data and it's
120
+ # unwritable after creation.
121
+ with self.assertRaisesRegex(ValueError,
122
+ 'assignment destination is read-only'):
123
+ output_ndarray[0, 0, 0] = 0
124
+ copied_ndarray = np.copy(output_ndarray)
125
+ copied_ndarray[0, 0, 0] = 0
126
+
127
+ def test_cropped_gray8_image(self):
128
+ w, h = random.randrange(20, 100), random.randrange(20, 100)
129
+ channels, offset = 3, 10
130
+ mat = cv2.cvtColor(
131
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
132
+ cv2.COLOR_RGB2GRAY)
133
+ gray8_image_frame = ImageFrame(
134
+ image_format=ImageFormat.GRAY8,
135
+ data=np.ascontiguousarray(mat[offset:-offset, offset:-offset]))
136
+ self.assertTrue(
137
+ np.array_equal(mat[offset:-offset, offset:-offset],
138
+ gray8_image_frame.numpy_view()))
139
+
140
+ def test_cropped_rgb_image(self):
141
+ w, h = random.randrange(20, 100), random.randrange(20, 100)
142
+ channels, offset = 3, 10
143
+ mat = cv2.cvtColor(
144
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
145
+ cv2.COLOR_RGB2BGR)
146
+ rgb_image_frame = ImageFrame(
147
+ image_format=ImageFormat.SRGB,
148
+ data=np.ascontiguousarray(mat[offset:-offset, offset:-offset, :]))
149
+ self.assertTrue(
150
+ np.array_equal(mat[offset:-offset, offset:-offset, :],
151
+ rgb_image_frame.numpy_view()))
152
+
153
+ # For image frames that store contiguous data, the output of numpy_view()
154
+ # points to the pixel data of the original image frame object. The life cycle
155
+ # of the data array should tie to the image frame object.
156
+ def test_image_frame_numpy_view_with_contiguous_data(self):
157
+ w, h = 640, 480
158
+ mat = np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8)
159
+ rgb_image_frame = ImageFrame(image_format=ImageFormat.SRGB, data=mat)
160
+ self.assertTrue(rgb_image_frame.is_contiguous())
161
+ initial_ref_count = sys.getrefcount(rgb_image_frame)
162
+ self.assertTrue(np.array_equal(mat, rgb_image_frame.numpy_view()))
163
+ # Get 2 data array objects and verify that the image frame's ref count is
164
+ # increased by 2.
165
+ np_view = rgb_image_frame.numpy_view()
166
+ self.assertEqual(sys.getrefcount(rgb_image_frame), initial_ref_count + 1)
167
+ np_view2 = rgb_image_frame.numpy_view()
168
+ self.assertEqual(sys.getrefcount(rgb_image_frame), initial_ref_count + 2)
169
+ del np_view
170
+ del np_view2
171
+ gc.collect()
172
+ # After the two data array objects getting destroyed, the current ref count
173
+ # should euqal to the initial ref count.
174
+ self.assertEqual(sys.getrefcount(rgb_image_frame), initial_ref_count)
175
+
176
+ # For image frames that store non contiguous data, the output of numpy_view()
177
+ # stores a copy of the pixel data of the image frame object. The life cycle of
178
+ # the data array doesn't tie to the image frame object.
179
+ def test_image_frame_numpy_view_with_non_contiguous_data(self):
180
+ w, h = 641, 481
181
+ mat = np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8)
182
+ rgb_image_frame = ImageFrame(image_format=ImageFormat.SRGB, data=mat)
183
+ self.assertFalse(rgb_image_frame.is_contiguous())
184
+ initial_ref_count = sys.getrefcount(rgb_image_frame)
185
+ self.assertTrue(np.array_equal(mat, rgb_image_frame.numpy_view()))
186
+ np_view = rgb_image_frame.numpy_view()
187
+ self.assertEqual(sys.getrefcount(rgb_image_frame), initial_ref_count)
188
+ del np_view
189
+ gc.collect()
190
+ self.assertEqual(sys.getrefcount(rgb_image_frame), initial_ref_count)
191
+
192
+
193
+ if __name__ == '__main__':
194
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/python/image_test.py ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python._framework_bindings.image."""
16
+
17
+ import gc
18
+ import os
19
+ import random
20
+ import sys
21
+
22
+ from absl.testing import absltest
23
+ import cv2
24
+ import numpy as np
25
+ import PIL.Image
26
+
27
+ # resources dependency
28
+ from mediapipe.python._framework_bindings import image
29
+ from mediapipe.python._framework_bindings import image_frame
30
+
31
+ TEST_IMAGE_PATH = 'mediapipe/python/solutions/testdata'
32
+
33
+ Image = image.Image
34
+ ImageFormat = image_frame.ImageFormat
35
+
36
+
37
+ # TODO: Add unit tests specifically for memory management.
38
+ class ImageTest(absltest.TestCase):
39
+
40
+ def test_create_image_from_gray_cv_mat(self):
41
+ w, h = random.randrange(3, 100), random.randrange(3, 100)
42
+ mat = cv2.cvtColor(
43
+ np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8),
44
+ cv2.COLOR_RGB2GRAY)
45
+ mat[2, 2] = 42
46
+ gray8_image = Image(image_format=ImageFormat.GRAY8, data=mat)
47
+ self.assertTrue(np.array_equal(mat, gray8_image.numpy_view()))
48
+ with self.assertRaisesRegex(IndexError, 'index dimension mismatch'):
49
+ print(gray8_image[w, h, 1])
50
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
51
+ print(gray8_image[w, h])
52
+ self.assertEqual(42, gray8_image[2, 2])
53
+
54
+ def test_create_image_from_rgb_cv_mat(self):
55
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
56
+ mat = cv2.cvtColor(
57
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
58
+ cv2.COLOR_RGB2BGR)
59
+ mat[2, 2, 1] = 42
60
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=mat)
61
+ self.assertTrue(np.array_equal(mat, rgb_image.numpy_view()))
62
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
63
+ print(rgb_image[w, h, channels])
64
+ self.assertEqual(42, rgb_image[2, 2, 1])
65
+
66
+ def test_create_image_from_rgb48_cv_mat(self):
67
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
68
+ mat = cv2.cvtColor(
69
+ np.random.randint(2**16 - 1, size=(h, w, channels), dtype=np.uint16),
70
+ cv2.COLOR_RGB2BGR)
71
+ mat[2, 2, 1] = 42
72
+ rgb48_image = Image(image_format=ImageFormat.SRGB48, data=mat)
73
+ self.assertTrue(np.array_equal(mat, rgb48_image.numpy_view()))
74
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
75
+ print(rgb48_image[w, h, channels])
76
+ self.assertEqual(42, rgb48_image[2, 2, 1])
77
+
78
+ def test_create_image_from_gray_pil_image(self):
79
+ w, h = random.randrange(3, 100), random.randrange(3, 100)
80
+ img = PIL.Image.fromarray(
81
+ np.random.randint(2**8 - 1, size=(h, w), dtype=np.uint8), 'L')
82
+ gray8_image = Image(image_format=ImageFormat.GRAY8, data=np.asarray(img))
83
+ self.assertTrue(np.array_equal(np.asarray(img), gray8_image.numpy_view()))
84
+ with self.assertRaisesRegex(IndexError, 'index dimension mismatch'):
85
+ print(gray8_image[w, h, 1])
86
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
87
+ print(gray8_image[w, h])
88
+
89
+ def test_create_image_from_rgb_pil_image(self):
90
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
91
+ img = PIL.Image.fromarray(
92
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
93
+ 'RGB')
94
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=np.asarray(img))
95
+ self.assertTrue(np.array_equal(np.asarray(img), rgb_image.numpy_view()))
96
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
97
+ print(rgb_image[w, h, channels])
98
+
99
+ def test_create_image_from_rgba64_pil_image(self):
100
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 4
101
+ img = PIL.Image.fromarray(
102
+ np.random.randint(2**16 - 1, size=(h, w, channels), dtype=np.uint16),
103
+ 'RGBA')
104
+ rgba_image = Image(
105
+ image_format=ImageFormat.SRGBA64,
106
+ data=np.asarray(img).astype(np.uint16))
107
+ self.assertTrue(np.array_equal(np.asarray(img), rgba_image.numpy_view()))
108
+ with self.assertRaisesRegex(IndexError, 'out of bounds'):
109
+ print(rgba_image[1000, 1000, 1000])
110
+
111
+ def test_image_numby_view(self):
112
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
113
+ mat = cv2.cvtColor(
114
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
115
+ cv2.COLOR_RGB2BGR)
116
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=mat)
117
+ output_ndarray = rgb_image.numpy_view()
118
+ self.assertTrue(np.array_equal(mat, rgb_image.numpy_view()))
119
+ # The output of numpy_view() is a reference to the internal data and it's
120
+ # unwritable after creation.
121
+ with self.assertRaisesRegex(ValueError,
122
+ 'assignment destination is read-only'):
123
+ output_ndarray[0, 0, 0] = 0
124
+ copied_ndarray = np.copy(output_ndarray)
125
+ copied_ndarray[0, 0, 0] = 0
126
+
127
+ def test_cropped_gray8_image(self):
128
+ w, h = random.randrange(20, 100), random.randrange(20, 100)
129
+ channels, offset = 3, 10
130
+ mat = cv2.cvtColor(
131
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
132
+ cv2.COLOR_RGB2GRAY)
133
+ gray8_image = Image(
134
+ image_format=ImageFormat.GRAY8,
135
+ data=np.ascontiguousarray(mat[offset:-offset, offset:-offset]))
136
+ self.assertTrue(
137
+ np.array_equal(mat[offset:-offset, offset:-offset],
138
+ gray8_image.numpy_view()))
139
+
140
+ def test_cropped_rgb_image(self):
141
+ w, h = random.randrange(20, 100), random.randrange(20, 100)
142
+ channels, offset = 3, 10
143
+ mat = cv2.cvtColor(
144
+ np.random.randint(2**8 - 1, size=(h, w, channels), dtype=np.uint8),
145
+ cv2.COLOR_RGB2BGR)
146
+ rgb_image = Image(
147
+ image_format=ImageFormat.SRGB,
148
+ data=np.ascontiguousarray(mat[offset:-offset, offset:-offset, :]))
149
+ self.assertTrue(
150
+ np.array_equal(mat[offset:-offset, offset:-offset, :],
151
+ rgb_image.numpy_view()))
152
+
153
+ # For image frames that store contiguous data, the output of numpy_view()
154
+ # points to the pixel data of the original image frame object. The life cycle
155
+ # of the data array should tie to the image frame object.
156
+ def test_image_numpy_view_with_contiguous_data(self):
157
+ w, h = 640, 480
158
+ mat = np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8)
159
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=mat)
160
+ self.assertTrue(rgb_image.is_contiguous())
161
+ initial_ref_count = sys.getrefcount(rgb_image)
162
+ self.assertTrue(np.array_equal(mat, rgb_image.numpy_view()))
163
+ # Get 2 data array objects and verify that the image frame's ref count is
164
+ # increased by 2.
165
+ np_view = rgb_image.numpy_view()
166
+ self.assertEqual(sys.getrefcount(rgb_image), initial_ref_count + 1)
167
+ np_view2 = rgb_image.numpy_view()
168
+ self.assertEqual(sys.getrefcount(rgb_image), initial_ref_count + 2)
169
+ del np_view
170
+ del np_view2
171
+ gc.collect()
172
+ # After the two data array objects getting destroyed, the current ref count
173
+ # should euqal to the initial ref count.
174
+ self.assertEqual(sys.getrefcount(rgb_image), initial_ref_count)
175
+
176
+ # For image frames that store non contiguous data, the output of numpy_view()
177
+ # stores a copy of the pixel data of the image frame object. The life cycle of
178
+ # the data array doesn't tie to the image frame object.
179
+ def test_image_numpy_view_with_non_contiguous_data(self):
180
+ w, h = 641, 481
181
+ mat = np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8)
182
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=mat)
183
+ self.assertFalse(rgb_image.is_contiguous())
184
+ initial_ref_count = sys.getrefcount(rgb_image)
185
+ self.assertTrue(np.array_equal(mat, rgb_image.numpy_view()))
186
+ np_view = rgb_image.numpy_view()
187
+ self.assertEqual(sys.getrefcount(rgb_image), initial_ref_count)
188
+ del np_view
189
+ gc.collect()
190
+ self.assertEqual(sys.getrefcount(rgb_image), initial_ref_count)
191
+
192
+ def test_image_create_from_cvmat(self):
193
+ image_path = os.path.join(os.path.dirname(__file__),
194
+ 'solutions/testdata/hands.jpg')
195
+ mat = cv2.imread(image_path).astype(np.uint8)
196
+ mat = cv2.cvtColor(mat, cv2.COLOR_BGR2RGB)
197
+ rgb_image = Image(image_format=ImageFormat.SRGB, data=mat)
198
+ self.assertEqual(rgb_image.width, 720)
199
+ self.assertEqual(rgb_image.height, 382)
200
+ self.assertEqual(rgb_image.channels, 3)
201
+ self.assertEqual(rgb_image.image_format, ImageFormat.SRGB)
202
+ self.assertTrue(np.array_equal(mat, rgb_image.numpy_view()))
203
+
204
+ def test_image_create_from_file(self):
205
+ image_path = os.path.join(os.path.dirname(__file__),
206
+ 'solutions/testdata/hands.jpg')
207
+ loaded_image = Image.create_from_file(image_path)
208
+ self.assertEqual(loaded_image.width, 720)
209
+ self.assertEqual(loaded_image.height, 382)
210
+ # On Mac w/ GPU support, images use 4 channels (SRGBA). Otherwise, all
211
+ # images use 3 channels (SRGB).
212
+ self.assertIn(loaded_image.channels, [3, 4])
213
+ self.assertIn(
214
+ loaded_image.image_format, [ImageFormat.SRGB, ImageFormat.SRGBA]
215
+ )
216
+
217
+ if __name__ == '__main__':
218
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/python/packet_creator.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """The public facing packet creator APIs."""
16
+
17
+ from typing import List, Union
18
+ import warnings
19
+
20
+ import numpy as np
21
+
22
+ from google.protobuf import message
23
+ from mediapipe.python._framework_bindings import _packet_creator
24
+ from mediapipe.python._framework_bindings import image
25
+ from mediapipe.python._framework_bindings import image_frame
26
+ from mediapipe.python._framework_bindings import packet
27
+
28
+
29
+ create_string = _packet_creator.create_string
30
+ create_bool = _packet_creator.create_bool
31
+ create_int = _packet_creator.create_int
32
+ create_int8 = _packet_creator.create_int8
33
+ create_int16 = _packet_creator.create_int16
34
+ create_int32 = _packet_creator.create_int32
35
+ create_int64 = _packet_creator.create_int64
36
+ create_uint8 = _packet_creator.create_uint8
37
+ create_uint16 = _packet_creator.create_uint16
38
+ create_uint32 = _packet_creator.create_uint32
39
+ create_uint64 = _packet_creator.create_uint64
40
+ create_float = _packet_creator.create_float
41
+ create_double = _packet_creator.create_double
42
+ create_int_array = _packet_creator.create_int_array
43
+ create_float_array = _packet_creator.create_float_array
44
+ create_int_vector = _packet_creator.create_int_vector
45
+ create_bool_vector = _packet_creator.create_bool_vector
46
+ create_float_vector = _packet_creator.create_float_vector
47
+ create_string_vector = _packet_creator.create_string_vector
48
+ create_image_vector = _packet_creator.create_image_vector
49
+ create_packet_vector = _packet_creator.create_packet_vector
50
+ create_string_to_packet_map = _packet_creator.create_string_to_packet_map
51
+ create_matrix = _packet_creator.create_matrix
52
+
53
+
54
+ def create_image_frame(data: Union[image_frame.ImageFrame, np.ndarray], # pytype: disable=annotation-type-mismatch
55
+ *,
56
+ image_format: image_frame.ImageFormat = None,
57
+ copy: bool = None) -> packet.Packet:
58
+ """Create a MediaPipe ImageFrame packet.
59
+
60
+ A MediaPipe ImageFrame packet can be created from an existing MediaPipe
61
+ ImageFrame object and the data will be realigned and copied into a new
62
+ ImageFrame object inside of the packet.
63
+
64
+ A MediaPipe ImageFrame packet can also be created from the raw pixel data
65
+ represented as a numpy array with one of the uint8, uint16, and float data
66
+ types. There are three data ownership modes depending on how the 'copy' arg
67
+ is set.
68
+
69
+ i) Default mode
70
+ If copy is not set, mutable data is always copied while the immutable data
71
+ is by reference.
72
+
73
+ ii) Copy mode (safe)
74
+ If copy is set to True, the data will be realigned and copied into an
75
+ ImageFrame object inside of the packet regardless the immutablity of the
76
+ original data.
77
+
78
+ iii) Reference mode (dangerous)
79
+ If copy is set to False, the data will be forced to be shared. If the data is
80
+ mutable (data.flags.writeable is True), a warning will be raised.
81
+
82
+ Args:
83
+ data: A MediaPipe ImageFrame object or the raw pixel data that is
84
+ represnted as a numpy ndarray.
85
+ image_format: One of the image_frame.ImageFormat enum types.
86
+ copy: Indicate if the packet should copy the data from the numpy nparray.
87
+
88
+ Returns:
89
+ A MediaPipe ImageFrame Packet.
90
+
91
+ Raises:
92
+ ValueError:
93
+ i) When "data" is a numpy ndarray, "image_format" is not provided or
94
+ the "data" array is not c_contiguous in the reference mode.
95
+ ii) When "data" is an ImageFrame object, the "image_format" arg doesn't
96
+ match the image format of the "data" ImageFrame object or "copy" is
97
+ explicitly set to False.
98
+ TypeError: If "image format" doesn't match "data" array's data type.
99
+
100
+ Examples:
101
+ np_array = np.random.randint(255, size=(321, 123, 3), dtype=np.uint8)
102
+ # Copy mode by default if the data array is writable.
103
+ image_frame_packet = mp.packet_creator.create_image_frame(
104
+ image_format=mp.ImageFormat.SRGB, data=np_array)
105
+
106
+ # Make the array unwriteable to trigger the reference mode.
107
+ np_array.flags.writeable = False
108
+ image_frame_packet = mp.packet_creator.create_image_frame(
109
+ image_format=mp.ImageFormat.SRGB, data=np_array)
110
+
111
+ image_frame = mp.ImageFrame(image_format=mp.ImageFormat.SRGB, data=np_array)
112
+ image_frame_packet = mp.packet_creator.create_image_frame(image_frame)
113
+
114
+ """
115
+ if isinstance(data, image_frame.ImageFrame):
116
+ if image_format is not None and data.image_format != image_format:
117
+ raise ValueError(
118
+ 'The provided image_format doesn\'t match the one from the data arg.')
119
+ if copy is not None and not copy:
120
+ # Taking a reference will make the created packet be mutable since the
121
+ # ImageFrame object can still be manipulated in Python, which voids packet
122
+ # immutability.
123
+ raise ValueError(
124
+ 'Creating ImageFrame packet by taking a reference of another ImageFrame object is not supported yet.'
125
+ )
126
+ # pylint:disable=protected-access
127
+ return _packet_creator._create_image_frame_from_image_frame(data)
128
+ # pylint:enable=protected-access
129
+ else:
130
+ if image_format is None:
131
+ raise ValueError('Please provide \'image_format\' with \'data\'.')
132
+ # If copy arg is not set, copying the data if it's immutable. Otherwise,
133
+ # take a reference of the immutable data to avoid data copy.
134
+ if copy is None:
135
+ copy = True if data.flags.writeable else False
136
+ if not copy:
137
+ # TODO: Investigate why the first 2 bytes of the data has data
138
+ # corruption when "data" is not c_contiguous.
139
+ if not data.flags.c_contiguous:
140
+ raise ValueError(
141
+ 'Reference mode is unavailable if \'data\' is not c_contiguous.')
142
+ if data.flags.writeable:
143
+ warnings.warn(
144
+ '\'data\' is still writeable. Taking a reference of the data to create ImageFrame packet is dangerous.',
145
+ RuntimeWarning, 2)
146
+ # pylint:disable=protected-access
147
+ return _packet_creator._create_image_frame_from_pixel_data(
148
+ image_format, data, copy)
149
+ # pylint:enable=protected-access
150
+
151
+
152
+ def create_image(data: Union[image.Image, np.ndarray], # pytype: disable=annotation-type-mismatch
153
+ *,
154
+ image_format: image_frame.ImageFormat = None,
155
+ copy: bool = None) -> packet.Packet:
156
+ """Create a MediaPipe Image packet.
157
+
158
+ A MediaPipe Image packet can be created from an existing MediaPipe
159
+ Image object and the data will be realigned and copied into a new
160
+ Image object inside of the packet.
161
+
162
+ A MediaPipe Image packet can also be created from the raw pixel data
163
+ represented as a numpy array with one of the uint8, uint16, and float data
164
+ types. There are three data ownership modes depending on how the 'copy' arg
165
+ is set.
166
+
167
+ i) Default mode
168
+ If copy is not set, mutable data is always copied while the immutable data
169
+ is by reference.
170
+
171
+ ii) Copy mode (safe)
172
+ If copy is set to True, the data will be realigned and copied into an
173
+ Image object inside of the packet regardless the immutablity of the
174
+ original data.
175
+
176
+ iii) Reference mode (dangerous)
177
+ If copy is set to False, the data will be forced to be shared. If the data is
178
+ mutable (data.flags.writeable is True), a warning will be raised.
179
+
180
+ Args:
181
+ data: A MediaPipe Image object or the raw pixel data that is represnted as a
182
+ numpy ndarray.
183
+ image_format: One of the mp.ImageFormat enum types.
184
+ copy: Indicate if the packet should copy the data from the numpy nparray.
185
+
186
+ Returns:
187
+ A MediaPipe Image Packet.
188
+
189
+ Raises:
190
+ ValueError:
191
+ i) When "data" is a numpy ndarray, "image_format" is not provided or
192
+ the "data" array is not c_contiguous in the reference mode.
193
+ ii) When "data" is an Image object, the "image_format" arg doesn't
194
+ match the image format of the "data" Image object or "copy" is
195
+ explicitly set to False.
196
+ TypeError: If "image format" doesn't match "data" array's data type.
197
+
198
+ Examples:
199
+ np_array = np.random.randint(255, size=(321, 123, 3), dtype=np.uint8)
200
+ # Copy mode by default if the data array is writable.
201
+ image_packet = mp.packet_creator.create_image(
202
+ image_format=mp.ImageFormat.SRGB, data=np_array)
203
+
204
+ # Make the array unwriteable to trigger the reference mode.
205
+ np_array.flags.writeable = False
206
+ image_packet = mp.packet_creator.create_image(
207
+ image_format=mp.ImageFormat.SRGB, data=np_array)
208
+
209
+ image = mp.Image(image_format=mp.ImageFormat.SRGB, data=np_array)
210
+ image_packet = mp.packet_creator.create_image(image)
211
+
212
+ """
213
+ if isinstance(data, image.Image):
214
+ if image_format is not None and data.image_format != image_format:
215
+ raise ValueError(
216
+ 'The provided image_format doesn\'t match the one from the data arg.')
217
+ if copy is not None and not copy:
218
+ # Taking a reference will make the created packet be mutable since the
219
+ # Image object can still be manipulated in Python, which voids packet
220
+ # immutability.
221
+ raise ValueError(
222
+ 'Creating Image packet by taking a reference of another Image object is not supported yet.'
223
+ )
224
+ # pylint:disable=protected-access
225
+ return _packet_creator._create_image_from_image(data)
226
+ # pylint:enable=protected-access
227
+ else:
228
+ if image_format is None:
229
+ raise ValueError('Please provide \'image_format\' with \'data\'.')
230
+ # If copy arg is not set, copying the data if it's immutable. Otherwise,
231
+ # take a reference of the immutable data to avoid data copy.
232
+ if copy is None:
233
+ copy = True if data.flags.writeable else False
234
+ if not copy:
235
+ # TODO: Investigate why the first 2 bytes of the data has data
236
+ # corruption when "data" is not c_contiguous.
237
+ if not data.flags.c_contiguous:
238
+ raise ValueError(
239
+ 'Reference mode is unavailable if \'data\' is not c_contiguous.')
240
+ if data.flags.writeable:
241
+ warnings.warn(
242
+ '\'data\' is still writeable. Taking a reference of the data to create Image packet is dangerous.',
243
+ RuntimeWarning, 2)
244
+ # pylint:disable=protected-access
245
+ return _packet_creator._create_image_from_pixel_data(
246
+ image_format, data, copy)
247
+ # pylint:enable=protected-access
248
+
249
+
250
+ def create_proto(proto_message: message.Message) -> packet.Packet:
251
+ """Create a MediaPipe protobuf message packet.
252
+
253
+ Args:
254
+ proto_message: A Python protobuf message.
255
+
256
+ Returns:
257
+ A MediaPipe protobuf message Packet.
258
+
259
+ Raises:
260
+ RuntimeError: If the protobuf message type is not registered in MediaPipe.
261
+
262
+ Examples:
263
+ detection = detection_pb2.Detection()
264
+ text_format.Parse('score: 0.5', detection)
265
+ packet = mp.packet_creator.create_proto(detection)
266
+ output_detection = mp.packet_getter.get_proto(packet)
267
+ """
268
+ # pylint:disable=protected-access
269
+ return _packet_creator._create_proto(proto_message.DESCRIPTOR.full_name,
270
+ proto_message.SerializeToString())
271
+ # pylint:enable=protected-access
272
+
273
+
274
+ def create_proto_vector(message_list: List[message.Message]) -> packet.Packet:
275
+ raise NotImplementedError('create_proto_vector is not implemented.')
python_embeded/Lib/site-packages/mediapipe/python/packet_getter.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """The public facing packet getter APIs."""
16
+
17
+ from typing import List
18
+
19
+ from google.protobuf import message
20
+ from google.protobuf import message_factory
21
+ from google.protobuf import symbol_database
22
+ from mediapipe.python._framework_bindings import _packet_getter
23
+ from mediapipe.python._framework_bindings import packet as mp_packet
24
+
25
+ get_str = _packet_getter.get_str
26
+ get_bytes = _packet_getter.get_bytes
27
+ get_bool = _packet_getter.get_bool
28
+ get_int = _packet_getter.get_int
29
+ get_uint = _packet_getter.get_uint
30
+ get_float = _packet_getter.get_float
31
+ get_int_list = _packet_getter.get_int_list
32
+ get_bool_list = _packet_getter.get_bool_list
33
+ get_float_list = _packet_getter.get_float_list
34
+ get_str_list = _packet_getter.get_str_list
35
+ get_image_list = _packet_getter.get_image_list
36
+ get_packet_list = _packet_getter.get_packet_list
37
+ get_str_to_packet_dict = _packet_getter.get_str_to_packet_dict
38
+ get_image = _packet_getter.get_image
39
+ get_image_frame = _packet_getter.get_image_frame
40
+ get_matrix = _packet_getter.get_matrix
41
+
42
+
43
+ def get_proto(packet: mp_packet.Packet) -> message.Message:
44
+ """Get the content of a MediaPipe proto Packet as a proto message.
45
+
46
+ Args:
47
+ packet: A MediaPipe proto Packet.
48
+
49
+ Returns:
50
+ A proto message.
51
+
52
+ Raises:
53
+ TypeError: If the message descriptor can't be found by type name.
54
+
55
+ Examples:
56
+ detection = detection_pb2.Detection()
57
+ text_format.Parse('score: 0.5', detection)
58
+ proto_packet = mp.packet_creator.create_proto(detection)
59
+ output_proto = mp.packet_getter.get_proto(proto_packet)
60
+ """
61
+ # pylint:disable=protected-access
62
+ proto_type_name = _packet_getter._get_proto_type_name(packet)
63
+ # pylint:enable=protected-access
64
+ try:
65
+ descriptor = symbol_database.Default().pool.FindMessageTypeByName(
66
+ proto_type_name)
67
+ except KeyError:
68
+ raise TypeError('Can not find message descriptor by type name: %s' %
69
+ proto_type_name)
70
+
71
+ message_class = message_factory.GetMessageClass(descriptor)
72
+ # pylint:disable=protected-access
73
+ serialized_proto = _packet_getter._get_serialized_proto(packet)
74
+ # pylint:enable=protected-access
75
+ proto_message = message_class()
76
+ proto_message.ParseFromString(serialized_proto)
77
+ return proto_message
78
+
79
+
80
+ def get_proto_list(packet: mp_packet.Packet) -> List[message.Message]:
81
+ """Get the content of a MediaPipe proto vector Packet as a proto message list.
82
+
83
+ Args:
84
+ packet: A MediaPipe proto vector Packet.
85
+
86
+ Returns:
87
+ A proto message list.
88
+
89
+ Raises:
90
+ TypeError: If the message descriptor can't be found by type name.
91
+
92
+ Examples:
93
+ proto_list = mp.packet_getter.get_proto_list(protos_packet)
94
+ """
95
+ # pylint:disable=protected-access
96
+ vector_size = _packet_getter._get_proto_vector_size(packet)
97
+ # pylint:enable=protected-access
98
+ # Return empty list if the proto vector is empty.
99
+ if vector_size == 0:
100
+ return []
101
+
102
+ # pylint:disable=protected-access
103
+ proto_type_name = _packet_getter._get_proto_vector_element_type_name(packet)
104
+ # pylint:enable=protected-access
105
+ try:
106
+ descriptor = symbol_database.Default().pool.FindMessageTypeByName(
107
+ proto_type_name)
108
+ except KeyError:
109
+ raise TypeError('Can not find message descriptor by type name: %s' %
110
+ proto_type_name)
111
+ message_class = message_factory.GetMessageClass(descriptor)
112
+ # pylint:disable=protected-access
113
+ serialized_protos = _packet_getter._get_serialized_proto_list(packet)
114
+ # pylint:enable=protected-access
115
+ proto_message_list = []
116
+ for serialized_proto in serialized_protos:
117
+ proto_message = message_class()
118
+ proto_message.ParseFromString(serialized_proto)
119
+ proto_message_list.append(proto_message)
120
+ return proto_message_list
python_embeded/Lib/site-packages/mediapipe/python/packet_test.py ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python._framework_bindings.packet."""
16
+
17
+ import gc
18
+ import random
19
+ import sys
20
+ from absl.testing import absltest
21
+ import numpy as np
22
+
23
+ from google.protobuf import text_format
24
+ from mediapipe.framework.formats import detection_pb2
25
+ from mediapipe.python import packet_creator
26
+ from mediapipe.python import packet_getter
27
+ from mediapipe.python._framework_bindings import calculator_graph
28
+ from mediapipe.python._framework_bindings import image
29
+ from mediapipe.python._framework_bindings import image_frame
30
+ from mediapipe.python._framework_bindings import packet
31
+
32
+ CalculatorGraph = calculator_graph.CalculatorGraph
33
+ Image = image.Image
34
+ ImageFormat = image_frame.ImageFormat
35
+ ImageFrame = image_frame.ImageFrame
36
+
37
+
38
+ class PacketTest(absltest.TestCase):
39
+
40
+ def test_empty_packet(self):
41
+ p = packet.Packet()
42
+ self.assertTrue(p.is_empty())
43
+
44
+ def test_boolean_packet(self):
45
+ p = packet_creator.create_bool(True)
46
+ p.timestamp = 0
47
+ self.assertEqual(packet_getter.get_bool(p), True)
48
+ self.assertEqual(p.timestamp, 0)
49
+
50
+ def test_int_packet(self):
51
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
52
+ p = packet_creator.create_int(2**32)
53
+ p = packet_creator.create_int(42)
54
+ p.timestamp = 0
55
+ self.assertEqual(packet_getter.get_int(p), 42)
56
+ self.assertEqual(p.timestamp, 0)
57
+ p2 = packet_creator.create_int(np.intc(1))
58
+ p2.timestamp = 0
59
+ self.assertEqual(packet_getter.get_int(p2), 1)
60
+ self.assertEqual(p2.timestamp, 0)
61
+
62
+ def test_int8_packet(self):
63
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
64
+ p = packet_creator.create_int8(2**7)
65
+ p = packet_creator.create_int8(2**7 - 1)
66
+ p.timestamp = 0
67
+ self.assertEqual(packet_getter.get_int(p), 2**7 - 1)
68
+ self.assertEqual(p.timestamp, 0)
69
+ p2 = packet_creator.create_int8(np.int8(1))
70
+ p2.timestamp = 0
71
+ self.assertEqual(packet_getter.get_int(p2), 1)
72
+ self.assertEqual(p2.timestamp, 0)
73
+
74
+ def test_int16_packet(self):
75
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
76
+ p = packet_creator.create_int16(2**15)
77
+ p = packet_creator.create_int16(2**15 - 1)
78
+ p.timestamp = 0
79
+ self.assertEqual(packet_getter.get_int(p), 2**15 - 1)
80
+ self.assertEqual(p.timestamp, 0)
81
+ p2 = packet_creator.create_int16(np.int16(1))
82
+ p2.timestamp = 0
83
+ self.assertEqual(packet_getter.get_int(p2), 1)
84
+ self.assertEqual(p2.timestamp, 0)
85
+
86
+ def test_int32_packet(self):
87
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
88
+ p = packet_creator.create_int32(2**31)
89
+
90
+ p = packet_creator.create_int32(2**31 - 1)
91
+ p.timestamp = 0
92
+ self.assertEqual(packet_getter.get_int(p), 2**31 - 1)
93
+ self.assertEqual(p.timestamp, 0)
94
+ p2 = packet_creator.create_int32(np.int32(1))
95
+ p2.timestamp = 0
96
+ self.assertEqual(packet_getter.get_int(p2), 1)
97
+ self.assertEqual(p2.timestamp, 0)
98
+
99
+ def test_int64_packet(self):
100
+ p = packet_creator.create_int64(2**63 - 1)
101
+ p.timestamp = 0
102
+ self.assertEqual(packet_getter.get_int(p), 2**63 - 1)
103
+ self.assertEqual(p.timestamp, 0)
104
+ p2 = packet_creator.create_int64(np.int64(1))
105
+ p2.timestamp = 0
106
+ self.assertEqual(packet_getter.get_int(p2), 1)
107
+ self.assertEqual(p2.timestamp, 0)
108
+
109
+ def test_uint8_packet(self):
110
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
111
+ p = packet_creator.create_uint8(2**8)
112
+ p = packet_creator.create_uint8(2**8 - 1)
113
+ p.timestamp = 0
114
+ self.assertEqual(packet_getter.get_uint(p), 2**8 - 1)
115
+ self.assertEqual(p.timestamp, 0)
116
+ p2 = packet_creator.create_uint8(np.uint8(1))
117
+ p2.timestamp = 0
118
+ self.assertEqual(packet_getter.get_uint(p2), 1)
119
+ self.assertEqual(p2.timestamp, 0)
120
+
121
+ def test_uint16_packet(self):
122
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
123
+ p = packet_creator.create_uint16(2**16)
124
+ p = packet_creator.create_uint16(2**16 - 1)
125
+ p.timestamp = 0
126
+ self.assertEqual(packet_getter.get_uint(p), 2**16 - 1)
127
+ self.assertEqual(p.timestamp, 0)
128
+ p2 = packet_creator.create_uint16(np.uint16(1))
129
+ p2.timestamp = 0
130
+ self.assertEqual(packet_getter.get_uint(p2), 1)
131
+ self.assertEqual(p2.timestamp, 0)
132
+
133
+ def test_uint32_packet(self):
134
+ with self.assertRaisesRegex(OverflowError, 'execeeds the maximum value'):
135
+ p = packet_creator.create_uint32(2**32)
136
+ p = packet_creator.create_uint32(2**32 - 1)
137
+ p.timestamp = 0
138
+ self.assertEqual(packet_getter.get_uint(p), 2**32 - 1)
139
+ self.assertEqual(p.timestamp, 0)
140
+ p2 = packet_creator.create_uint32(np.uint32(1))
141
+ p2.timestamp = 0
142
+ self.assertEqual(packet_getter.get_uint(p2), 1)
143
+ self.assertEqual(p2.timestamp, 0)
144
+
145
+ def test_uint64_packet(self):
146
+ p = packet_creator.create_uint64(2**64 - 1)
147
+ p.timestamp = 0
148
+ self.assertEqual(packet_getter.get_uint(p), 2**64 - 1)
149
+ self.assertEqual(p.timestamp, 0)
150
+ p2 = packet_creator.create_uint64(np.uint64(1))
151
+ p2.timestamp = 0
152
+ self.assertEqual(packet_getter.get_uint(p2), 1)
153
+ self.assertEqual(p2.timestamp, 0)
154
+
155
+ def test_float_packet(self):
156
+ p = packet_creator.create_float(0.42)
157
+ p.timestamp = 0
158
+ self.assertAlmostEqual(packet_getter.get_float(p), 0.42)
159
+ self.assertEqual(p.timestamp, 0)
160
+ p2 = packet_creator.create_float(float(0.42))
161
+ p2.timestamp = 0
162
+ self.assertAlmostEqual(packet_getter.get_float(p2), 0.42)
163
+ self.assertEqual(p2.timestamp, 0)
164
+
165
+ def test_double_packet(self):
166
+ p = packet_creator.create_double(0.42)
167
+ p.timestamp = 0
168
+ self.assertAlmostEqual(packet_getter.get_float(p), 0.42)
169
+ self.assertEqual(p.timestamp, 0)
170
+ p2 = packet_creator.create_double(np.double(0.42))
171
+ p2.timestamp = 0
172
+ self.assertAlmostEqual(packet_getter.get_float(p2), 0.42)
173
+ self.assertEqual(p2.timestamp, 0)
174
+
175
+ def test_detection_proto_packet(self):
176
+ detection = detection_pb2.Detection()
177
+ text_format.Parse('score: 0.5', detection)
178
+ p = packet_creator.create_proto(detection).at(100)
179
+
180
+ def test_string_packet(self):
181
+ p = packet_creator.create_string('abc').at(100)
182
+ self.assertEqual(packet_getter.get_str(p), 'abc')
183
+ self.assertEqual(p.timestamp, 100)
184
+ p.timestamp = 200
185
+ self.assertEqual(p.timestamp, 200)
186
+
187
+ def test_bytes_packet(self):
188
+ p = packet_creator.create_string(b'xd0\xba\xd0').at(300)
189
+ self.assertEqual(packet_getter.get_bytes(p), b'xd0\xba\xd0')
190
+ self.assertEqual(p.timestamp, 300)
191
+
192
+ def test_int_array_packet(self):
193
+ p = packet_creator.create_int_array([1, 2, 3]).at(100)
194
+ self.assertEqual(p.timestamp, 100)
195
+
196
+ def test_float_array_packet(self):
197
+ p = packet_creator.create_float_array([0.1, 0.2, 0.3]).at(100)
198
+ self.assertEqual(p.timestamp, 100)
199
+
200
+ def test_int_vector_packet(self):
201
+ p = packet_creator.create_int_vector([1, 2, 3]).at(100)
202
+ self.assertEqual(packet_getter.get_int_list(p), [1, 2, 3])
203
+ self.assertEqual(p.timestamp, 100)
204
+
205
+ def test_float_vector_packet(self):
206
+ p = packet_creator.create_float_vector([0.1, 0.2, 0.3]).at(100)
207
+ output_list = packet_getter.get_float_list(p)
208
+ self.assertAlmostEqual(output_list[0], 0.1)
209
+ self.assertAlmostEqual(output_list[1], 0.2)
210
+ self.assertAlmostEqual(output_list[2], 0.3)
211
+ self.assertEqual(p.timestamp, 100)
212
+
213
+ def test_image_vector_packet(self):
214
+ w, h, offset = 80, 40, 10
215
+ mat = np.random.randint(2**8 - 1, size=(h, w, 3), dtype=np.uint8)
216
+ p = packet_creator.create_image_vector([
217
+ Image(image_format=ImageFormat.SRGB, data=mat),
218
+ Image(
219
+ image_format=ImageFormat.SRGB,
220
+ data=np.ascontiguousarray(mat[offset:-offset, offset:-offset, :]))
221
+ ]).at(100)
222
+ output_list = packet_getter.get_image_list(p)
223
+ self.assertLen(output_list, 2)
224
+ self.assertTrue(np.array_equal(output_list[0].numpy_view(), mat))
225
+ self.assertTrue(
226
+ np.array_equal(output_list[1].numpy_view(), mat[offset:-offset,
227
+ offset:-offset, :]))
228
+ self.assertEqual(p.timestamp, 100)
229
+
230
+ def test_string_vector_packet(self):
231
+ p = packet_creator.create_string_vector(['a', 'b', 'c']).at(100)
232
+ output_list = packet_getter.get_str_list(p)
233
+ self.assertEqual(output_list[0], 'a')
234
+ self.assertEqual(output_list[1], 'b')
235
+ self.assertEqual(output_list[2], 'c')
236
+ self.assertEqual(p.timestamp, 100)
237
+
238
+ def test_packet_vector_packet(self):
239
+ p = packet_creator.create_packet_vector([
240
+ packet_creator.create_float(0.42),
241
+ packet_creator.create_int(42),
242
+ packet_creator.create_string('42')
243
+ ]).at(100)
244
+ output_list = packet_getter.get_packet_list(p)
245
+ self.assertAlmostEqual(packet_getter.get_float(output_list[0]), 0.42)
246
+ self.assertEqual(packet_getter.get_int(output_list[1]), 42)
247
+ self.assertEqual(packet_getter.get_str(output_list[2]), '42')
248
+ self.assertEqual(p.timestamp, 100)
249
+
250
+ def test_string_to_packet_map_packet(self):
251
+ p = packet_creator.create_string_to_packet_map({
252
+ 'float': packet_creator.create_float(0.42),
253
+ 'int': packet_creator.create_int(42),
254
+ 'string': packet_creator.create_string('42')
255
+ }).at(100)
256
+ output_list = packet_getter.get_str_to_packet_dict(p)
257
+ self.assertAlmostEqual(packet_getter.get_float(output_list['float']), 0.42)
258
+ self.assertEqual(packet_getter.get_int(output_list['int']), 42)
259
+ self.assertEqual(packet_getter.get_str(output_list['string']), '42')
260
+ self.assertEqual(p.timestamp, 100)
261
+
262
+ def test_uint8_image_packet(self):
263
+ uint8_img = np.random.randint(
264
+ 2**8 - 1,
265
+ size=(random.randrange(3, 100), random.randrange(3, 100), 3),
266
+ dtype=np.uint8)
267
+ image_frame_packet = packet_creator.create_image_frame(
268
+ image_frame.ImageFrame(
269
+ image_format=image_frame.ImageFormat.SRGB, data=uint8_img))
270
+ output_image_frame = packet_getter.get_image_frame(image_frame_packet)
271
+ self.assertTrue(np.array_equal(output_image_frame.numpy_view(), uint8_img))
272
+ image_packet = packet_creator.create_image(
273
+ Image(image_format=ImageFormat.SRGB, data=uint8_img))
274
+ output_image = packet_getter.get_image(image_packet)
275
+ self.assertTrue(np.array_equal(output_image.numpy_view(), uint8_img))
276
+
277
+ def test_uint16_image_packet(self):
278
+ uint16_img = np.random.randint(
279
+ 2**16 - 1,
280
+ size=(random.randrange(3, 100), random.randrange(3, 100), 4),
281
+ dtype=np.uint16)
282
+ image_frame_packet = packet_creator.create_image_frame(
283
+ ImageFrame(image_format=ImageFormat.SRGBA64, data=uint16_img))
284
+ output_image_frame = packet_getter.get_image_frame(image_frame_packet)
285
+ self.assertTrue(np.array_equal(output_image_frame.numpy_view(), uint16_img))
286
+ image_packet = packet_creator.create_image(
287
+ Image(image_format=ImageFormat.SRGBA64, data=uint16_img))
288
+ output_image = packet_getter.get_image(image_packet)
289
+ self.assertTrue(np.array_equal(output_image.numpy_view(), uint16_img))
290
+
291
+ def test_float_image_frame_packet(self):
292
+ float_img = np.float32(
293
+ np.random.random_sample(
294
+ (random.randrange(3, 100), random.randrange(3, 100), 2)))
295
+ image_frame_packet = packet_creator.create_image_frame(
296
+ ImageFrame(image_format=ImageFormat.VEC32F2, data=float_img))
297
+ output_image_frame = packet_getter.get_image_frame(image_frame_packet)
298
+ self.assertTrue(np.allclose(output_image_frame.numpy_view(), float_img))
299
+ image_packet = packet_creator.create_image(
300
+ Image(image_format=ImageFormat.VEC32F2, data=float_img))
301
+ output_image = packet_getter.get_image(image_packet)
302
+ self.assertTrue(np.array_equal(output_image.numpy_view(), float_img))
303
+
304
+ def test_image_frame_packet_creation_copy_mode(self):
305
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
306
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
307
+ # rgb_data is c_contiguous.
308
+ self.assertTrue(rgb_data.flags.c_contiguous)
309
+ initial_ref_count = sys.getrefcount(rgb_data)
310
+ p = packet_creator.create_image_frame(
311
+ image_format=ImageFormat.SRGB, data=rgb_data)
312
+ # copy mode doesn't increase the ref count of the data.
313
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
314
+
315
+ rgb_data = rgb_data[:, :, ::-1]
316
+ # rgb_data is now not c_contiguous. But, copy mode shouldn't be affected.
317
+ self.assertFalse(rgb_data.flags.c_contiguous)
318
+ initial_ref_count = sys.getrefcount(rgb_data)
319
+ p = packet_creator.create_image_frame(
320
+ image_format=ImageFormat.SRGB, data=rgb_data)
321
+ # copy mode doesn't increase the ref count of the data.
322
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
323
+
324
+ output_frame = packet_getter.get_image_frame(p)
325
+ self.assertEqual(output_frame.height, h)
326
+ self.assertEqual(output_frame.width, w)
327
+ self.assertEqual(output_frame.channels, channels)
328
+ self.assertTrue(np.array_equal(output_frame.numpy_view(), rgb_data))
329
+
330
+ del p
331
+ del output_frame
332
+ gc.collect()
333
+ # Destroying the packet also doesn't affect the ref count becuase of the
334
+ # copy mode.
335
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
336
+
337
+ def test_image_frame_packet_creation_reference_mode(self):
338
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
339
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
340
+ rgb_data.flags.writeable = False
341
+ initial_ref_count = sys.getrefcount(rgb_data)
342
+ image_frame_packet = packet_creator.create_image_frame(
343
+ image_format=ImageFormat.SRGB, data=rgb_data)
344
+ # Reference mode increase the ref count of the rgb_data by 1.
345
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count + 1)
346
+ del image_frame_packet
347
+ gc.collect()
348
+ # Deleting image_frame_packet should decrese the ref count of rgb_data by 1.
349
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
350
+ rgb_data_copy = np.copy(rgb_data)
351
+ # rgb_data_copy is a copy of rgb_data and should not increase the ref count.
352
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
353
+ text_config = """
354
+ node {
355
+ calculator: 'PassThroughCalculator'
356
+ input_side_packet: "in"
357
+ output_side_packet: "out"
358
+ }
359
+ """
360
+ graph = CalculatorGraph(graph_config=text_config)
361
+ graph.start_run(
362
+ input_side_packets={
363
+ 'in':
364
+ packet_creator.create_image_frame(
365
+ image_format=ImageFormat.SRGB, data=rgb_data)
366
+ })
367
+ # reference mode increase the ref count of the rgb_data by 1.
368
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count + 1)
369
+ graph.wait_until_done()
370
+ output_packet = graph.get_output_side_packet('out')
371
+ del rgb_data
372
+ del graph
373
+ gc.collect()
374
+ # The pixel data of the output image frame packet should still be valid
375
+ # after the graph and the original rgb_data data are deleted.
376
+ self.assertTrue(
377
+ np.array_equal(
378
+ packet_getter.get_image_frame(output_packet).numpy_view(),
379
+ rgb_data_copy))
380
+
381
+ def test_image_frame_packet_copy_creation_with_cropping(self):
382
+ w, h, channels = random.randrange(40, 100), random.randrange(40, 100), 3
383
+ channels, offset = 3, 10
384
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
385
+ initial_ref_count = sys.getrefcount(rgb_data)
386
+ p = packet_creator.create_image_frame(
387
+ image_format=ImageFormat.SRGB,
388
+ data=rgb_data[offset:-offset, offset:-offset, :])
389
+ # copy mode doesn't increase the ref count of the data.
390
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
391
+ output_frame = packet_getter.get_image_frame(p)
392
+ self.assertEqual(output_frame.height, h - 2 * offset)
393
+ self.assertEqual(output_frame.width, w - 2 * offset)
394
+ self.assertEqual(output_frame.channels, channels)
395
+ self.assertTrue(
396
+ np.array_equal(rgb_data[offset:-offset, offset:-offset, :],
397
+ output_frame.numpy_view()))
398
+ del p
399
+ del output_frame
400
+ gc.collect()
401
+ # Destroying the packet also doesn't affect the ref count becuase of the
402
+ # copy mode.
403
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
404
+
405
+ def test_image_packet_creation_copy_mode(self):
406
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
407
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
408
+ # rgb_data is c_contiguous.
409
+ self.assertTrue(rgb_data.flags.c_contiguous)
410
+ initial_ref_count = sys.getrefcount(rgb_data)
411
+ p = packet_creator.create_image(
412
+ image_format=ImageFormat.SRGB, data=rgb_data)
413
+ # copy mode doesn't increase the ref count of the data.
414
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
415
+
416
+ rgb_data = rgb_data[:, :, ::-1]
417
+ # rgb_data is now not c_contiguous. But, copy mode shouldn't be affected.
418
+ self.assertFalse(rgb_data.flags.c_contiguous)
419
+ initial_ref_count = sys.getrefcount(rgb_data)
420
+ p = packet_creator.create_image(
421
+ image_format=ImageFormat.SRGB, data=rgb_data)
422
+ # copy mode doesn't increase the ref count of the data.
423
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
424
+
425
+ output_image = packet_getter.get_image(p)
426
+ self.assertEqual(output_image.height, h)
427
+ self.assertEqual(output_image.width, w)
428
+ self.assertEqual(output_image.channels, channels)
429
+ self.assertTrue(np.array_equal(output_image.numpy_view(), rgb_data))
430
+
431
+ del p
432
+ del output_image
433
+ gc.collect()
434
+ # Destroying the packet also doesn't affect the ref count becuase of the
435
+ # copy mode.
436
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
437
+
438
+ def test_image_packet_creation_reference_mode(self):
439
+ w, h, channels = random.randrange(3, 100), random.randrange(3, 100), 3
440
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
441
+ rgb_data.flags.writeable = False
442
+ initial_ref_count = sys.getrefcount(rgb_data)
443
+ image_packet = packet_creator.create_image(
444
+ image_format=ImageFormat.SRGB, data=rgb_data)
445
+ # Reference mode increase the ref count of the rgb_data by 1.
446
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count + 1)
447
+ del image_packet
448
+ gc.collect()
449
+ # Deleting image_packet should decrese the ref count of rgb_data by 1.
450
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
451
+ rgb_data_copy = np.copy(rgb_data)
452
+ # rgb_data_copy is a copy of rgb_data and should not increase the ref count.
453
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
454
+ text_config = """
455
+ node {
456
+ calculator: 'PassThroughCalculator'
457
+ input_side_packet: "in"
458
+ output_side_packet: "out"
459
+ }
460
+ """
461
+ graph = CalculatorGraph(graph_config=text_config)
462
+ graph.start_run(
463
+ input_side_packets={
464
+ 'in':
465
+ packet_creator.create_image(
466
+ image_format=ImageFormat.SRGB, data=rgb_data)
467
+ })
468
+ # reference mode increase the ref count of the rgb_data by 1.
469
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count + 1)
470
+ graph.wait_until_done()
471
+ output_packet = graph.get_output_side_packet('out')
472
+ del rgb_data
473
+ del graph
474
+ gc.collect()
475
+ # The pixel data of the output image frame packet should still be valid
476
+ # after the graph and the original rgb_data data are deleted.
477
+ self.assertTrue(
478
+ np.array_equal(
479
+ packet_getter.get_image(output_packet).numpy_view(), rgb_data_copy))
480
+
481
+ def test_image_packet_copy_creation_with_cropping(self):
482
+ w, h, channels = random.randrange(40, 100), random.randrange(40, 100), 3
483
+ channels, offset = 3, 10
484
+ rgb_data = np.random.randint(255, size=(h, w, channels), dtype=np.uint8)
485
+ initial_ref_count = sys.getrefcount(rgb_data)
486
+ p = packet_creator.create_image(
487
+ image_format=ImageFormat.SRGB,
488
+ data=rgb_data[offset:-offset, offset:-offset, :])
489
+ # copy mode doesn't increase the ref count of the data.
490
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
491
+ output_image = packet_getter.get_image(p)
492
+ self.assertEqual(output_image.height, h - 2 * offset)
493
+ self.assertEqual(output_image.width, w - 2 * offset)
494
+ self.assertEqual(output_image.channels, channels)
495
+ self.assertTrue(
496
+ np.array_equal(rgb_data[offset:-offset, offset:-offset, :],
497
+ output_image.numpy_view()))
498
+ del p
499
+ del output_image
500
+ gc.collect()
501
+ # Destroying the packet also doesn't affect the ref count becuase of the
502
+ # copy mode.
503
+ self.assertEqual(sys.getrefcount(rgb_data), initial_ref_count)
504
+
505
+ def test_matrix_packet(self):
506
+ np_matrix = np.array([[.1, .2, .3], [.4, .5, .6]])
507
+ initial_ref_count = sys.getrefcount(np_matrix)
508
+ p = packet_creator.create_matrix(np_matrix)
509
+ # Copy mode should not increase the ref count of np_matrix.
510
+ self.assertEqual(initial_ref_count, sys.getrefcount(np_matrix))
511
+ output_matrix = packet_getter.get_matrix(p)
512
+ del np_matrix
513
+ gc.collect()
514
+ self.assertTrue(
515
+ np.allclose(output_matrix, np.array([[.1, .2, .3], [.4, .5, .6]])))
516
+
517
+ def test_matrix_packet_with_non_c_contiguous_data(self):
518
+ np_matrix = np.array([[.1, .2, .3], [.4, .5, .6]])[:, ::-1]
519
+ # np_matrix is not c_contiguous.
520
+ self.assertFalse(np_matrix.flags.c_contiguous)
521
+ p = packet_creator.create_matrix(np_matrix)
522
+ initial_ref_count = sys.getrefcount(np_matrix)
523
+ # Copy mode should not increase the ref count of np_matrix.
524
+ self.assertEqual(initial_ref_count, sys.getrefcount(np_matrix))
525
+ output_matrix = packet_getter.get_matrix(p)
526
+ del np_matrix
527
+ gc.collect()
528
+ self.assertTrue(
529
+ np.allclose(output_matrix,
530
+ np.array([[.1, .2, .3], [.4, .5, .6]])[:, ::-1]))
531
+
532
+ if __name__ == '__main__':
533
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/python/solution_base.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """MediaPipe SolutionBase module.
15
+
16
+ MediaPipe SolutionBase is the common base class for the high-level MediaPipe
17
+ Solution APIs such as BlazeFace, hand tracking, and BlazePose. The SolutionBase
18
+ class contains the shared logic among the high-level Solution APIs including
19
+ graph initialization, processing image/audio data, and graph shutdown. Thus,
20
+ users can easily create new MediaPipe Solution APIs on top of the SolutionBase
21
+ class.
22
+ """
23
+
24
+ import collections
25
+ import enum
26
+ import os
27
+ from typing import Any, Iterable, List, Mapping, NamedTuple, Optional, Union
28
+
29
+ import numpy as np
30
+
31
+ from google.protobuf.internal import containers
32
+ from google.protobuf import descriptor
33
+ from google.protobuf import message
34
+ # resources dependency
35
+ # pylint: disable=unused-import
36
+ from mediapipe.calculators.core import constant_side_packet_calculator_pb2
37
+ from mediapipe.calculators.image import image_transformation_calculator_pb2
38
+ from mediapipe.calculators.tensor import tensors_to_detections_calculator_pb2
39
+ from mediapipe.calculators.util import landmarks_smoothing_calculator_pb2
40
+ from mediapipe.calculators.util import logic_calculator_pb2
41
+ from mediapipe.calculators.util import thresholding_calculator_pb2
42
+ from mediapipe.framework import calculator_pb2
43
+ from mediapipe.framework.formats import body_rig_pb2
44
+ from mediapipe.framework.formats import classification_pb2
45
+ from mediapipe.framework.formats import detection_pb2
46
+ from mediapipe.framework.formats import landmark_pb2
47
+ from mediapipe.framework.formats import rect_pb2
48
+ from mediapipe.modules.objectron.calculators import annotation_data_pb2
49
+ from mediapipe.modules.objectron.calculators import lift_2d_frame_annotation_to_3d_calculator_pb2
50
+ # pylint: enable=unused-import
51
+ from mediapipe.python import packet_creator
52
+ from mediapipe.python import packet_getter
53
+ from mediapipe.python._framework_bindings import calculator_graph
54
+ from mediapipe.python._framework_bindings import image_frame
55
+ from mediapipe.python._framework_bindings import packet
56
+ from mediapipe.python._framework_bindings import resource_util
57
+ from mediapipe.python._framework_bindings import validated_graph_config
58
+
59
+ RGB_CHANNELS = 3
60
+ # TODO: Enable calculator options modification for more calculators.
61
+ CALCULATOR_TO_OPTIONS = {
62
+ 'ConstantSidePacketCalculator':
63
+ constant_side_packet_calculator_pb2.ConstantSidePacketCalculatorOptions,
64
+ 'ImageTransformationCalculator':
65
+ image_transformation_calculator_pb2
66
+ .ImageTransformationCalculatorOptions,
67
+ 'LandmarksSmoothingCalculator':
68
+ landmarks_smoothing_calculator_pb2.LandmarksSmoothingCalculatorOptions,
69
+ 'LogicCalculator':
70
+ logic_calculator_pb2.LogicCalculatorOptions,
71
+ 'ThresholdingCalculator':
72
+ thresholding_calculator_pb2.ThresholdingCalculatorOptions,
73
+ 'TensorsToDetectionsCalculator':
74
+ tensors_to_detections_calculator_pb2
75
+ .TensorsToDetectionsCalculatorOptions,
76
+ 'Lift2DFrameAnnotationTo3DCalculator':
77
+ lift_2d_frame_annotation_to_3d_calculator_pb2
78
+ .Lift2DFrameAnnotationTo3DCalculatorOptions,
79
+ }
80
+
81
+
82
+ def type_names_from_oneof(oneof_type_name: str) -> Optional[List[str]]:
83
+ if oneof_type_name.startswith('OneOf<') and oneof_type_name.endswith('>'):
84
+ comma_separated_types = oneof_type_name[len('OneOf<'):-len('>')]
85
+ return [n.strip() for n in comma_separated_types.split(',')]
86
+ return None
87
+
88
+
89
+ # TODO: Support more packet data types, such as "Any" type.
90
+ @enum.unique
91
+ class PacketDataType(enum.Enum):
92
+ """The packet data types supported by the SolutionBase class."""
93
+ STRING = 'string'
94
+ BOOL = 'bool'
95
+ BOOL_LIST = 'bool_list'
96
+ INT = 'int'
97
+ INT_LIST = 'int_list'
98
+ FLOAT = 'float'
99
+ FLOAT_LIST = 'float_list'
100
+ AUDIO = 'matrix'
101
+ IMAGE = 'image'
102
+ IMAGE_LIST = 'image_list'
103
+ IMAGE_FRAME = 'image_frame'
104
+ PROTO = 'proto'
105
+ PROTO_LIST = 'proto_list'
106
+
107
+ @staticmethod
108
+ def from_registered_name(registered_name: str) -> 'PacketDataType':
109
+ try:
110
+ return NAME_TO_TYPE[registered_name]
111
+ except KeyError as e:
112
+ names = type_names_from_oneof(registered_name)
113
+ if names:
114
+ for n in names:
115
+ if n in NAME_TO_TYPE.keys():
116
+ return NAME_TO_TYPE[n]
117
+ raise e
118
+
119
+ NAME_TO_TYPE: Mapping[str, 'PacketDataType'] = {
120
+ 'string': PacketDataType.STRING,
121
+ 'bool': PacketDataType.BOOL,
122
+ '::std::vector<bool>': PacketDataType.BOOL_LIST,
123
+ 'int': PacketDataType.INT,
124
+ '::std::vector<int>': PacketDataType.INT_LIST,
125
+ 'int64': PacketDataType.INT,
126
+ 'int64_t': PacketDataType.INT,
127
+ '::std::vector<int64>': PacketDataType.INT_LIST,
128
+ '::std::vector<int64_t>': PacketDataType.INT_LIST,
129
+ 'float': PacketDataType.FLOAT,
130
+ '::std::vector<float>': PacketDataType.FLOAT_LIST,
131
+ '::mediapipe::Matrix': PacketDataType.AUDIO,
132
+ '::mediapipe::ImageFrame': PacketDataType.IMAGE_FRAME,
133
+ '::mediapipe::Classification': PacketDataType.PROTO,
134
+ '::mediapipe::ClassificationList': PacketDataType.PROTO,
135
+ '::mediapipe::ClassificationListCollection': PacketDataType.PROTO,
136
+ '::mediapipe::Detection': PacketDataType.PROTO,
137
+ '::mediapipe::DetectionList': PacketDataType.PROTO,
138
+ '::mediapipe::Landmark': PacketDataType.PROTO,
139
+ '::mediapipe::LandmarkList': PacketDataType.PROTO,
140
+ '::mediapipe::LandmarkListCollection': PacketDataType.PROTO,
141
+ '::mediapipe::NormalizedLandmark': PacketDataType.PROTO,
142
+ '::mediapipe::FrameAnnotation': PacketDataType.PROTO,
143
+ '::mediapipe::Trigger': PacketDataType.PROTO,
144
+ '::mediapipe::Rect': PacketDataType.PROTO,
145
+ '::mediapipe::NormalizedRect': PacketDataType.PROTO,
146
+ '::mediapipe::NormalizedLandmarkList': PacketDataType.PROTO,
147
+ '::mediapipe::NormalizedLandmarkListCollection': PacketDataType.PROTO,
148
+ '::mediapipe::Image': PacketDataType.IMAGE,
149
+ '::std::vector<::mediapipe::Image>': PacketDataType.IMAGE_LIST,
150
+ '::std::vector<::mediapipe::Classification>': PacketDataType.PROTO_LIST,
151
+ '::std::vector<::mediapipe::ClassificationList>': PacketDataType.PROTO_LIST,
152
+ '::std::vector<::mediapipe::Detection>': PacketDataType.PROTO_LIST,
153
+ '::std::vector<::mediapipe::DetectionList>': PacketDataType.PROTO_LIST,
154
+ '::std::vector<::mediapipe::Landmark>': PacketDataType.PROTO_LIST,
155
+ '::std::vector<::mediapipe::LandmarkList>': PacketDataType.PROTO_LIST,
156
+ '::std::vector<::mediapipe::NormalizedLandmark>': PacketDataType.PROTO_LIST,
157
+ '::std::vector<::mediapipe::NormalizedLandmarkList>': (
158
+ PacketDataType.PROTO_LIST
159
+ ),
160
+ '::std::vector<::mediapipe::Rect>': PacketDataType.PROTO_LIST,
161
+ '::std::vector<::mediapipe::NormalizedRect>': PacketDataType.PROTO_LIST,
162
+ '::mediapipe::Joint': PacketDataType.PROTO,
163
+ '::mediapipe::JointList': PacketDataType.PROTO,
164
+ '::std::vector<::mediapipe::JointList>': PacketDataType.PROTO_LIST,
165
+ }
166
+
167
+
168
+ class SolutionBase:
169
+ """The common base class for the high-level MediaPipe Solution APIs.
170
+
171
+ The SolutionBase class contains the shared logic among the high-level solution
172
+ APIs including graph initialization, processing image/audio data, and graph
173
+ shutdown.
174
+
175
+ Example usage:
176
+ with solution_base.SolutionBase(
177
+ binary_graph_path='mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb',
178
+ side_inputs={'num_hands': 2}) as hand_tracker:
179
+ # Read an image and convert the BGR image to RGB.
180
+ input_image = cv2.cvtColor(cv2.imread('/tmp/hand.png'), COLOR_BGR2RGB)
181
+ results = hand_tracker.process(input_image)
182
+ print(results.palm_detections)
183
+ print(results.multi_hand_landmarks)
184
+ """
185
+
186
+ def __init__(
187
+ self,
188
+ binary_graph_path: Optional[str] = None,
189
+ graph_config: Optional[calculator_pb2.CalculatorGraphConfig] = None,
190
+ calculator_params: Optional[Mapping[str, Any]] = None,
191
+ graph_options: Optional[message.Message] = None,
192
+ side_inputs: Optional[Mapping[str, Any]] = None,
193
+ outputs: Optional[List[str]] = None,
194
+ stream_type_hints: Optional[Mapping[str, PacketDataType]] = None):
195
+ """Initializes the SolutionBase object.
196
+
197
+ Args:
198
+ binary_graph_path: The path to a binary mediapipe graph file (.binarypb).
199
+ graph_config: A CalculatorGraphConfig proto message or its text proto
200
+ format.
201
+ calculator_params: A mapping from the
202
+ {calculator_name}.{options_field_name} str to the field value.
203
+ graph_options: The graph options protobuf for the mediapipe graph.
204
+ side_inputs: A mapping from the side packet name to the packet raw data.
205
+ outputs: A list of the graph output stream names to observe. If the list
206
+ is empty, all the output streams listed in the graph config will be
207
+ automatically observed by default.
208
+ stream_type_hints: A mapping from the stream name to its packet type hint.
209
+
210
+ Raises:
211
+ FileNotFoundError: If the binary graph file can't be found.
212
+ RuntimeError: If the underlying calculator graph can't be successfully
213
+ initialized or started.
214
+ ValueError: If any of the following:
215
+ a) If not exactly one of 'binary_graph_path' or 'graph_config' arguments
216
+ is provided.
217
+ b) If the graph validation process contains error.
218
+ c) If the registered type name of the streams and side packets can't be
219
+ found.
220
+ d) If the calculator options of the calculator listed in
221
+ calculator_params is not allowed to be modified.
222
+ e) If the calculator options field is a repeated field but the field
223
+ value to be set is not iterable.
224
+ f) If not all calculator params are valid.
225
+ """
226
+ if bool(binary_graph_path) == bool(graph_config):
227
+ raise ValueError(
228
+ "Must provide exactly one of 'binary_graph_path' or 'graph_config'.")
229
+ # MediaPipe package root path
230
+ root_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-3])
231
+ resource_util.set_resource_dir(root_path)
232
+ validated_graph = validated_graph_config.ValidatedGraphConfig()
233
+ if binary_graph_path:
234
+ validated_graph.initialize(
235
+ binary_graph_path=os.path.join(root_path, binary_graph_path))
236
+ else:
237
+ validated_graph.initialize(graph_config=graph_config)
238
+
239
+ canonical_graph_config_proto = self._initialize_graph_interface(
240
+ validated_graph, side_inputs, outputs, stream_type_hints)
241
+ if calculator_params:
242
+ self._modify_calculator_options(canonical_graph_config_proto,
243
+ calculator_params)
244
+ if graph_options:
245
+ self._set_extension(canonical_graph_config_proto.graph_options,
246
+ graph_options)
247
+
248
+ self._graph = calculator_graph.CalculatorGraph(
249
+ graph_config=canonical_graph_config_proto)
250
+ self._simulated_timestamp = 0
251
+ self._graph_outputs = {}
252
+
253
+ def callback(stream_name: str, output_packet: packet.Packet) -> None:
254
+ self._graph_outputs[stream_name] = output_packet
255
+
256
+ for stream_name in self._output_stream_type_info.keys():
257
+ self._graph.observe_output_stream(stream_name, callback, True)
258
+
259
+ self._input_side_packets = {
260
+ name: self._make_packet(self._side_input_type_info[name], data)
261
+ for name, data in (side_inputs or {}).items()
262
+ }
263
+ self._graph.start_run(self._input_side_packets)
264
+
265
+ # TODO: Use "inspect.Parameter" to fetch the input argument names and
266
+ # types from "_input_stream_type_info" and then auto generate the process
267
+ # method signature by "inspect.Signature" in __init__.
268
+ def process(
269
+ self, input_data: Union[np.ndarray, Mapping[str, Union[np.ndarray,
270
+ message.Message]]]
271
+ ) -> NamedTuple:
272
+ """Processes a set of RGB image data and output SolutionOutputs.
273
+
274
+ Args:
275
+ input_data: Either a single numpy ndarray object representing the solo
276
+ image input of a graph or a mapping from the stream name to the image or
277
+ proto data that represents every input streams of a graph.
278
+
279
+ Raises:
280
+ NotImplementedError: If input_data contains audio data or a list of proto
281
+ objects.
282
+ RuntimeError: If the underlying graph occurs any error.
283
+ ValueError: If the input image data is not three channel RGB.
284
+
285
+ Returns:
286
+ A NamedTuple object that contains the output data of a graph run.
287
+ The field names in the NamedTuple object are mapping to the graph output
288
+ stream names.
289
+
290
+ Examples:
291
+ solution = solution_base.SolutionBase(graph_config=hand_landmark_graph)
292
+ results = solution.process(cv2.imread('/tmp/hand0.png')[:, :, ::-1])
293
+ print(results.detection)
294
+ results = solution.process(
295
+ {'video_in' : cv2.imread('/tmp/hand1.png')[:, :, ::-1]})
296
+ print(results.hand_landmarks)
297
+ """
298
+ self._graph_outputs.clear()
299
+
300
+ if isinstance(input_data, np.ndarray):
301
+ if self._input_stream_type_info is None:
302
+ raise ValueError('_input_stream_type_info is None in SolutionBase')
303
+ if len(self._input_stream_type_info.keys()) != 1:
304
+ raise ValueError(
305
+ "Can't process single image input since the graph has more than one"
306
+ ' input streams.'
307
+ )
308
+ input_dict = {next(iter(self._input_stream_type_info)): input_data}
309
+ else:
310
+ input_dict = input_data
311
+
312
+ # Set the timestamp increment to 33333 us to simulate the 30 fps video
313
+ # input.
314
+ self._simulated_timestamp += 33333
315
+ if self._graph is None:
316
+ raise ValueError('_graph is None in SolutionBase')
317
+ for stream_name, data in input_dict.items():
318
+ input_stream_type = self._input_stream_type_info[stream_name]
319
+ if (input_stream_type == PacketDataType.PROTO_LIST or
320
+ input_stream_type == PacketDataType.AUDIO):
321
+ # TODO: Support audio data.
322
+ raise NotImplementedError(
323
+ f'SolutionBase can only process non-audio and non-proto-list data. '
324
+ f'{self._input_stream_type_info[stream_name].name} '
325
+ f'type is not supported yet.')
326
+ elif (input_stream_type == PacketDataType.IMAGE_FRAME or
327
+ input_stream_type == PacketDataType.IMAGE):
328
+ if data.shape[2] != RGB_CHANNELS:
329
+ raise ValueError('Input image must contain three channel rgb data.')
330
+ self._graph.add_packet_to_input_stream(
331
+ stream=stream_name,
332
+ packet=self._make_packet(input_stream_type,
333
+ data).at(self._simulated_timestamp))
334
+ else:
335
+ self._graph.add_packet_to_input_stream(
336
+ stream=stream_name,
337
+ packet=self._make_packet(input_stream_type,
338
+ data).at(self._simulated_timestamp))
339
+
340
+ self._graph.wait_until_idle()
341
+ # Create a NamedTuple object where the field names are mapping to the graph
342
+ # output stream names.
343
+ if self._output_stream_type_info is None:
344
+ raise ValueError('_output_stream_type_info is None in SolutionBase')
345
+ solution_outputs = collections.namedtuple(
346
+ 'SolutionOutputs', self._output_stream_type_info.keys())
347
+ for stream_name in self._output_stream_type_info.keys():
348
+ if stream_name in self._graph_outputs:
349
+ setattr(
350
+ solution_outputs, stream_name,
351
+ self._get_packet_content(self._output_stream_type_info[stream_name],
352
+ self._graph_outputs[stream_name]))
353
+ else:
354
+ setattr(solution_outputs, stream_name, None)
355
+
356
+ return solution_outputs
357
+
358
+ def close(self) -> None:
359
+ """Closes all the input sources and the graph."""
360
+ if self._graph is None:
361
+ raise ValueError('Closing SolutionBase._graph which is already None')
362
+ self._graph.close()
363
+ self._graph = None
364
+ self._input_stream_type_info = None
365
+ self._output_stream_type_info = None
366
+
367
+ def reset(self) -> None:
368
+ """Resets the graph for another run."""
369
+ if self._graph:
370
+ self._graph.close()
371
+ self._graph.start_run(self._input_side_packets)
372
+
373
+ def _initialize_graph_interface(
374
+ self,
375
+ validated_graph: validated_graph_config.ValidatedGraphConfig,
376
+ side_inputs: Optional[Mapping[str, Any]] = None,
377
+ outputs: Optional[List[str]] = None,
378
+ stream_type_hints: Optional[Mapping[str, PacketDataType]] = None):
379
+ """Gets graph interface type information and returns the canonical graph config proto."""
380
+
381
+ canonical_graph_config_proto = calculator_pb2.CalculatorGraphConfig()
382
+ canonical_graph_config_proto.ParseFromString(validated_graph.binary_config)
383
+
384
+ # Gets name from a 'TAG:index:name' str.
385
+ def get_name(tag_index_name):
386
+ return tag_index_name.split(':')[-1]
387
+
388
+ # Gets the packet type information of the input streams and output streams
389
+ # from the user provided stream_type_hints field or validated calculator
390
+ # graph. The mappings from the stream names to the packet data types is
391
+ # for deciding which packet creator and getter methods to call in the
392
+ # process() method.
393
+ def get_stream_packet_type(packet_tag_index_name):
394
+ stream_name = get_name(packet_tag_index_name)
395
+ if stream_type_hints and stream_name in stream_type_hints.keys():
396
+ return stream_type_hints[stream_name]
397
+ return PacketDataType.from_registered_name(
398
+ validated_graph.registered_stream_type_name(stream_name))
399
+
400
+ self._input_stream_type_info = {
401
+ get_name(tag_index_name): get_stream_packet_type(tag_index_name)
402
+ for tag_index_name in canonical_graph_config_proto.input_stream
403
+ }
404
+
405
+ if not outputs:
406
+ output_streams = canonical_graph_config_proto.output_stream
407
+ else:
408
+ output_streams = outputs
409
+ self._output_stream_type_info = {
410
+ get_name(tag_index_name): get_stream_packet_type(tag_index_name)
411
+ for tag_index_name in output_streams
412
+ }
413
+
414
+ # Gets the packet type information of the input side packets from the
415
+ # validated calculator graph. The mappings from the side packet names to the
416
+ # packet data types is for making the input_side_packets dict for graph
417
+ # start_run().
418
+ def get_side_packet_type(packet_tag_index_name):
419
+ return PacketDataType.from_registered_name(
420
+ validated_graph.registered_side_packet_type_name(
421
+ get_name(packet_tag_index_name)))
422
+
423
+ self._side_input_type_info = {
424
+ get_name(tag_index_name): get_side_packet_type(tag_index_name)
425
+ for tag_index_name, _ in (side_inputs or {}).items()
426
+ }
427
+ return canonical_graph_config_proto
428
+
429
+ def _modify_calculator_options(
430
+ self, calculator_graph_config: calculator_pb2.CalculatorGraphConfig,
431
+ calculator_params: Mapping[str, Any]) -> None:
432
+ """Modifies the CalculatorOptions of the calculators listed in calculator_params."""
433
+
434
+ # Reorganizes the calculator options field data by calculator name and puts
435
+ # all the field data of the same calculator in a list.
436
+ def generate_nested_calculator_params(flat_map):
437
+ nested_map = {}
438
+ for compound_name, field_value in flat_map.items():
439
+ calculator_and_field_name = compound_name.split('.')
440
+ if len(calculator_and_field_name) != 2:
441
+ raise ValueError(
442
+ f'The key "{compound_name}" in the calculator_params is invalid.')
443
+ calculator_name = calculator_and_field_name[0]
444
+ field_name = calculator_and_field_name[1]
445
+ if calculator_name in nested_map:
446
+ nested_map[calculator_name].append((field_name, field_value))
447
+ else:
448
+ nested_map[calculator_name] = [(field_name, field_value)]
449
+ return nested_map
450
+
451
+ def modify_options_fields(calculator_options, options_field_list):
452
+ for field_name, field_value in options_field_list:
453
+ if field_value is None:
454
+ calculator_options.ClearField(field_name)
455
+ else:
456
+ field_label = calculator_options.DESCRIPTOR.fields_by_name[
457
+ field_name].label
458
+ if field_label == descriptor.FieldDescriptor.LABEL_REPEATED:
459
+ if not isinstance(field_value, Iterable):
460
+ raise ValueError(
461
+ f'{field_name} is a repeated proto field but the value '
462
+ f'to be set is {type(field_value)}, which is not iterable.')
463
+ # TODO: Support resetting the entire repeated field
464
+ # (array-option) and changing the individual values in the repeated
465
+ # field (array-element-option).
466
+ calculator_options.ClearField(field_name)
467
+ for elem in field_value:
468
+ getattr(calculator_options, field_name).append(elem)
469
+ else:
470
+ setattr(calculator_options, field_name, field_value)
471
+
472
+ nested_calculator_params = generate_nested_calculator_params(
473
+ calculator_params)
474
+
475
+ num_modified = 0
476
+ for node in calculator_graph_config.node:
477
+ if node.name not in nested_calculator_params:
478
+ continue
479
+ options_type = CALCULATOR_TO_OPTIONS.get(node.calculator)
480
+ if options_type is None:
481
+ raise ValueError(
482
+ f'Modifying the calculator options of {node.name} is not supported.'
483
+ )
484
+ options_field_list = nested_calculator_params[node.name]
485
+ if node.HasField('options') and node.node_options:
486
+ raise ValueError(
487
+ f'Cannot modify the calculator options of {node.name} because it '
488
+ f'has both options and node_options fields.')
489
+ if node.node_options:
490
+ # The "node_options" case for the proto3 syntax.
491
+ node_options_modified = False
492
+ for elem in node.node_options:
493
+ type_name = elem.type_url.split('/')[-1]
494
+ if type_name == options_type.DESCRIPTOR.full_name:
495
+ calculator_options = options_type.FromString(elem.value)
496
+ modify_options_fields(calculator_options, options_field_list)
497
+ elem.value = calculator_options.SerializeToString()
498
+ node_options_modified = True
499
+ break
500
+ # There is no existing node_options being modified. Add a new
501
+ # node_options instead.
502
+ if not node_options_modified:
503
+ calculator_options = options_type()
504
+ modify_options_fields(calculator_options, options_field_list)
505
+ node.node_options.add().Pack(calculator_options)
506
+ else:
507
+ # The "options" case for the proto2 syntax as well as the fallback
508
+ # when the calculator doesn't have either "options" or "node_options".
509
+ modify_options_fields(node.options.Extensions[options_type.ext],
510
+ options_field_list)
511
+
512
+ num_modified += 1
513
+ # Exits the loop early when every elements in nested_calculator_params
514
+ # have been visited.
515
+ if num_modified == len(nested_calculator_params):
516
+ break
517
+ if num_modified < len(nested_calculator_params):
518
+ raise ValueError('Not all calculator params are valid.')
519
+
520
+ def create_graph_options(self, options_message: message.Message,
521
+ values: Mapping[str, Any]) -> message.Message:
522
+ """Sets protobuf field values.
523
+
524
+ Args:
525
+ options_message: the options protobuf message.
526
+ values: field value pairs, where each field may be a "." separated path.
527
+
528
+ Returns:
529
+ the options protobuf message.
530
+ """
531
+
532
+ if hasattr(values, 'items'):
533
+ values = values.items()
534
+ for pair in values:
535
+ (field, value) = pair
536
+ fields = field.split('.')
537
+ m = options_message
538
+ while len(fields) > 1:
539
+ m = getattr(m, fields[0])
540
+ del fields[0]
541
+ v = getattr(m, fields[0])
542
+ if hasattr(v, 'append'):
543
+ del v[:]
544
+ v.extend(value)
545
+ elif hasattr(v, 'CopyFrom'):
546
+ v.CopyFrom(value)
547
+ else:
548
+ setattr(m, fields[0], value)
549
+ return options_message
550
+
551
+ def _set_extension(self,
552
+ extension_list: containers.RepeatedCompositeFieldContainer,
553
+ extension_value: message.Message) -> None:
554
+ """Sets one value in a repeated protobuf.Any extension field."""
555
+ for extension_any in extension_list:
556
+ if extension_any.Is(extension_value.DESCRIPTOR):
557
+ v = type(extension_value)()
558
+ extension_any.Unpack(v)
559
+ v.MergeFrom(extension_value)
560
+ extension_any.Pack(v)
561
+ return
562
+ extension_list.add().Pack(extension_value)
563
+
564
+ def _make_packet(self, packet_data_type: PacketDataType,
565
+ data: Any) -> packet.Packet:
566
+ if (packet_data_type == PacketDataType.IMAGE_FRAME or
567
+ packet_data_type == PacketDataType.IMAGE):
568
+ return getattr(packet_creator, 'create_' + packet_data_type.value)(
569
+ data, image_format=image_frame.ImageFormat.SRGB)
570
+ else:
571
+ return getattr(packet_creator, 'create_' + packet_data_type.value)(data)
572
+
573
+ def _get_packet_content(self, packet_data_type: PacketDataType,
574
+ output_packet: packet.Packet) -> Any:
575
+ """Gets packet content from a packet by type.
576
+
577
+ Args:
578
+ packet_data_type: The supported packet data type.
579
+ output_packet: The packet to get content from.
580
+
581
+ Returns:
582
+ Packet content by packet data type. None to indicate "no output".
583
+
584
+ """
585
+
586
+ if output_packet.is_empty():
587
+ return None
588
+ if packet_data_type == PacketDataType.STRING:
589
+ return packet_getter.get_str(output_packet)
590
+ elif (packet_data_type == PacketDataType.IMAGE_FRAME or
591
+ packet_data_type == PacketDataType.IMAGE):
592
+ return getattr(packet_getter, 'get_' +
593
+ packet_data_type.value)(output_packet).numpy_view()
594
+ else:
595
+ return getattr(packet_getter, 'get_' + packet_data_type.value)(
596
+ output_packet)
597
+
598
+ def __enter__(self):
599
+ """A "with" statement support."""
600
+ return self
601
+
602
+ def __exit__(self, exc_type, exc_val, exc_tb):
603
+ """Closes all the input sources and the graph."""
604
+ self.close()
python_embeded/Lib/site-packages/mediapipe/python/solution_base_test.py ADDED
@@ -0,0 +1,396 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python.solution_base."""
16
+
17
+ from absl.testing import absltest
18
+ from absl.testing import parameterized
19
+ import numpy as np
20
+
21
+ from google.protobuf import text_format
22
+ from mediapipe.framework import calculator_pb2
23
+ from mediapipe.framework.formats import detection_pb2
24
+ from mediapipe.python import solution_base
25
+ from mediapipe.python.solution_base import PacketDataType
26
+
27
+ CALCULATOR_OPTIONS_TEST_GRAPH_CONFIG = """
28
+ input_stream: 'image_in'
29
+ output_stream: 'image_out'
30
+ node {
31
+ name: 'ImageTransformation'
32
+ calculator: 'ImageTransformationCalculator'
33
+ input_stream: 'IMAGE:image_in'
34
+ output_stream: 'IMAGE:image_out'
35
+ options: {
36
+ [mediapipe.ImageTransformationCalculatorOptions.ext] {
37
+ output_width: 10
38
+ output_height: 10
39
+ }
40
+ }
41
+ node_options: {
42
+ [type.googleapis.com/mediapipe.ImageTransformationCalculatorOptions] {
43
+ output_width: 10
44
+ output_height: 10
45
+ }
46
+ }
47
+ }
48
+ """
49
+
50
+
51
+ class SolutionBaseTest(parameterized.TestCase):
52
+
53
+ def test_invalid_initialization_arguments(self):
54
+ with self.assertRaisesRegex(
55
+ ValueError,
56
+ 'Must provide exactly one of \'binary_graph_path\' or \'graph_config\'.'
57
+ ):
58
+ solution_base.SolutionBase()
59
+ with self.assertRaisesRegex(
60
+ ValueError,
61
+ 'Must provide exactly one of \'binary_graph_path\' or \'graph_config\'.'
62
+ ):
63
+ solution_base.SolutionBase(
64
+ graph_config=calculator_pb2.CalculatorGraphConfig(),
65
+ binary_graph_path='/tmp/no_such.binarypb')
66
+
67
+ @parameterized.named_parameters(('no_graph_input_output_stream', """
68
+ node {
69
+ calculator: 'PassThroughCalculator'
70
+ input_stream: 'in'
71
+ output_stream: 'out'
72
+ }
73
+ """, RuntimeError, 'does not have a corresponding output stream.'),
74
+ ('calcualtor_io_mismatch', """
75
+ node {
76
+ calculator: 'PassThroughCalculator'
77
+ input_stream: 'in'
78
+ input_stream: 'in2'
79
+ output_stream: 'out'
80
+ }
81
+ """, ValueError, 'must use matching tags and indexes.'),
82
+ ('unkown_registered_stream_type_name', """
83
+ input_stream: 'in'
84
+ output_stream: 'out'
85
+ node {
86
+ calculator: 'PassThroughCalculator'
87
+ input_stream: 'in'
88
+ output_stream: 'out'
89
+ }
90
+ """, RuntimeError, 'Unable to find the type for stream \"in\".'))
91
+ def test_invalid_config(self, text_config, error_type, error_message):
92
+ config_proto = text_format.Parse(text_config,
93
+ calculator_pb2.CalculatorGraphConfig())
94
+ with self.assertRaisesRegex(error_type, error_message):
95
+ solution_base.SolutionBase(graph_config=config_proto)
96
+
97
+ def test_valid_input_data_type_proto(self):
98
+ text_config = """
99
+ input_stream: 'input_detections'
100
+ output_stream: 'output_detections'
101
+ node {
102
+ calculator: 'DetectionUniqueIdCalculator'
103
+ input_stream: 'DETECTION_LIST:input_detections'
104
+ output_stream: 'DETECTION_LIST:output_detections'
105
+ }
106
+ """
107
+ config_proto = text_format.Parse(text_config,
108
+ calculator_pb2.CalculatorGraphConfig())
109
+ with solution_base.SolutionBase(graph_config=config_proto) as solution:
110
+ input_detections = detection_pb2.DetectionList()
111
+ detection_1 = input_detections.detection.add()
112
+ text_format.Parse('score: 0.5', detection_1)
113
+ detection_2 = input_detections.detection.add()
114
+ text_format.Parse('score: 0.8', detection_2)
115
+ results = solution.process({'input_detections': input_detections})
116
+ self.assertTrue(hasattr(results, 'output_detections'))
117
+ self.assertLen(results.output_detections.detection, 2)
118
+ expected_detection_1 = detection_pb2.Detection()
119
+ text_format.Parse('score: 0.5, detection_id: 1', expected_detection_1)
120
+ expected_detection_2 = detection_pb2.Detection()
121
+ text_format.Parse('score: 0.8, detection_id: 2', expected_detection_2)
122
+ self.assertEqual(results.output_detections.detection[0],
123
+ expected_detection_1)
124
+ self.assertEqual(results.output_detections.detection[1],
125
+ expected_detection_2)
126
+
127
+ def test_invalid_input_data_type_proto_vector(self):
128
+ text_config = """
129
+ input_stream: 'input_detections'
130
+ output_stream: 'output_detections'
131
+ node {
132
+ calculator: 'DetectionUniqueIdCalculator'
133
+ input_stream: 'DETECTIONS:input_detections'
134
+ output_stream: 'DETECTIONS:output_detections'
135
+ }
136
+ """
137
+ config_proto = text_format.Parse(text_config,
138
+ calculator_pb2.CalculatorGraphConfig())
139
+ with solution_base.SolutionBase(graph_config=config_proto) as solution:
140
+ detection = detection_pb2.Detection()
141
+ text_format.Parse('score: 0.5', detection)
142
+ with self.assertRaisesRegex(
143
+ NotImplementedError,
144
+ 'SolutionBase can only process non-audio and non-proto-list data. '
145
+ + 'PROTO_LIST type is not supported.'
146
+ ):
147
+ solution.process({'input_detections': detection})
148
+
149
+ def test_invalid_input_image_data(self):
150
+ text_config = """
151
+ input_stream: 'image_in'
152
+ output_stream: 'image_out'
153
+ node {
154
+ calculator: 'ImageTransformationCalculator'
155
+ input_stream: 'IMAGE:image_in'
156
+ output_stream: 'IMAGE:transformed_image_in'
157
+ }
158
+ node {
159
+ calculator: 'ImageTransformationCalculator'
160
+ input_stream: 'IMAGE:transformed_image_in'
161
+ output_stream: 'IMAGE:image_out'
162
+ }
163
+ """
164
+ config_proto = text_format.Parse(text_config,
165
+ calculator_pb2.CalculatorGraphConfig())
166
+ with solution_base.SolutionBase(graph_config=config_proto) as solution:
167
+ with self.assertRaisesRegex(
168
+ ValueError, 'Input image must contain three channel rgb data.'):
169
+ solution.process(np.arange(36, dtype=np.uint8).reshape(3, 3, 4))
170
+
171
+ @parameterized.named_parameters(('graph_without_side_packets', """
172
+ input_stream: 'image_in'
173
+ output_stream: 'image_out'
174
+ node {
175
+ calculator: 'ImageTransformationCalculator'
176
+ input_stream: 'IMAGE:image_in'
177
+ output_stream: 'IMAGE:transformed_image_in'
178
+ }
179
+ node {
180
+ calculator: 'ImageTransformationCalculator'
181
+ input_stream: 'IMAGE:transformed_image_in'
182
+ output_stream: 'IMAGE:image_out'
183
+ }
184
+ """, None), ('graph_with_side_packets', """
185
+ input_stream: 'image_in'
186
+ input_side_packet: 'allow_signal'
187
+ input_side_packet: 'rotation_degrees'
188
+ output_stream: 'image_out'
189
+ node {
190
+ calculator: 'ImageTransformationCalculator'
191
+ input_stream: 'IMAGE:image_in'
192
+ input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
193
+ output_stream: 'IMAGE:transformed_image_in'
194
+ }
195
+ node {
196
+ calculator: 'GateCalculator'
197
+ input_stream: 'transformed_image_in'
198
+ input_side_packet: 'ALLOW:allow_signal'
199
+ output_stream: 'image_out_to_transform'
200
+ }
201
+ node {
202
+ calculator: 'ImageTransformationCalculator'
203
+ input_stream: 'IMAGE:image_out_to_transform'
204
+ input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
205
+ output_stream: 'IMAGE:image_out'
206
+ }""", {
207
+ 'allow_signal': True,
208
+ 'rotation_degrees': 0
209
+ }))
210
+ def test_solution_process(self, text_config, side_inputs):
211
+ self._process_and_verify(
212
+ config_proto=text_format.Parse(text_config,
213
+ calculator_pb2.CalculatorGraphConfig()),
214
+ side_inputs=side_inputs)
215
+
216
+ def test_invalid_calculator_options(self):
217
+ text_config = """
218
+ input_stream: 'image_in'
219
+ output_stream: 'image_out'
220
+ node {
221
+ calculator: 'ImageTransformationCalculator'
222
+ input_stream: 'IMAGE:image_in'
223
+ output_stream: 'IMAGE:transformed_image_in'
224
+ }
225
+ node {
226
+ name: 'SignalGate'
227
+ calculator: 'GateCalculator'
228
+ input_stream: 'transformed_image_in'
229
+ input_side_packet: 'ALLOW:allow_signal'
230
+ output_stream: 'image_out_to_transform'
231
+ }
232
+ node {
233
+ calculator: 'ImageTransformationCalculator'
234
+ input_stream: 'IMAGE:image_out_to_transform'
235
+ output_stream: 'IMAGE:image_out'
236
+ }
237
+ """
238
+ config_proto = text_format.Parse(text_config,
239
+ calculator_pb2.CalculatorGraphConfig())
240
+ with self.assertRaisesRegex(
241
+ ValueError,
242
+ 'Modifying the calculator options of SignalGate is not supported.'):
243
+ solution_base.SolutionBase(
244
+ graph_config=config_proto,
245
+ calculator_params={'SignalGate.invalid_field': 'I am invalid'})
246
+
247
+ def test_calculator_has_both_options_and_node_options(self):
248
+ config_proto = text_format.Parse(CALCULATOR_OPTIONS_TEST_GRAPH_CONFIG,
249
+ calculator_pb2.CalculatorGraphConfig())
250
+ with self.assertRaisesRegex(ValueError,
251
+ 'has both options and node_options fields.'):
252
+ solution_base.SolutionBase(
253
+ graph_config=config_proto,
254
+ calculator_params={
255
+ 'ImageTransformation.output_width': 0,
256
+ 'ImageTransformation.output_height': 0
257
+ })
258
+
259
+ def test_modifying_calculator_proto2_options(self):
260
+ config_proto = text_format.Parse(CALCULATOR_OPTIONS_TEST_GRAPH_CONFIG,
261
+ calculator_pb2.CalculatorGraphConfig())
262
+ # To test proto2 options only, remove the proto3 node_options field from the
263
+ # graph config.
264
+ self.assertEqual('ImageTransformation', config_proto.node[0].name)
265
+ config_proto.node[0].ClearField('node_options')
266
+ self._process_and_verify(
267
+ config_proto=config_proto,
268
+ calculator_params={
269
+ 'ImageTransformation.output_width': 0,
270
+ 'ImageTransformation.output_height': 0
271
+ })
272
+
273
+ def test_modifying_calculator_proto3_node_options(self):
274
+ config_proto = text_format.Parse(CALCULATOR_OPTIONS_TEST_GRAPH_CONFIG,
275
+ calculator_pb2.CalculatorGraphConfig())
276
+ # To test proto3 node options only, remove the proto2 options field from the
277
+ # graph config.
278
+ self.assertEqual('ImageTransformation', config_proto.node[0].name)
279
+ config_proto.node[0].ClearField('options')
280
+ self._process_and_verify(
281
+ config_proto=config_proto,
282
+ calculator_params={
283
+ 'ImageTransformation.output_width': 0,
284
+ 'ImageTransformation.output_height': 0
285
+ })
286
+
287
+ def test_adding_calculator_options(self):
288
+ config_proto = text_format.Parse(CALCULATOR_OPTIONS_TEST_GRAPH_CONFIG,
289
+ calculator_pb2.CalculatorGraphConfig())
290
+ # To test a calculator with no options field, remove both proto2 options and
291
+ # proto3 node_options fields from the graph config.
292
+ self.assertEqual('ImageTransformation', config_proto.node[0].name)
293
+ config_proto.node[0].ClearField('options')
294
+ config_proto.node[0].ClearField('node_options')
295
+ self._process_and_verify(
296
+ config_proto=config_proto,
297
+ calculator_params={
298
+ 'ImageTransformation.output_width': 0,
299
+ 'ImageTransformation.output_height': 0
300
+ })
301
+
302
+ @parameterized.named_parameters(('graph_without_side_packets', """
303
+ input_stream: 'image_in'
304
+ output_stream: 'image_out'
305
+ node {
306
+ calculator: 'ImageTransformationCalculator'
307
+ input_stream: 'IMAGE:image_in'
308
+ output_stream: 'IMAGE:transformed_image_in'
309
+ }
310
+ node {
311
+ calculator: 'ImageTransformationCalculator'
312
+ input_stream: 'IMAGE:transformed_image_in'
313
+ output_stream: 'IMAGE:image_out'
314
+ }
315
+ """, None), ('graph_with_side_packets', """
316
+ input_stream: 'image_in'
317
+ input_side_packet: 'allow_signal'
318
+ input_side_packet: 'rotation_degrees'
319
+ output_stream: 'image_out'
320
+ node {
321
+ calculator: 'ImageTransformationCalculator'
322
+ input_stream: 'IMAGE:image_in'
323
+ input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
324
+ output_stream: 'IMAGE:transformed_image_in'
325
+ }
326
+ node {
327
+ calculator: 'GateCalculator'
328
+ input_stream: 'transformed_image_in'
329
+ input_side_packet: 'ALLOW:allow_signal'
330
+ output_stream: 'image_out_to_transform'
331
+ }
332
+ node {
333
+ calculator: 'ImageTransformationCalculator'
334
+ input_stream: 'IMAGE:image_out_to_transform'
335
+ input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
336
+ output_stream: 'IMAGE:image_out'
337
+ }""", {
338
+ 'allow_signal': True,
339
+ 'rotation_degrees': 0
340
+ }))
341
+ def test_solution_reset(self, text_config, side_inputs):
342
+ config_proto = text_format.Parse(text_config,
343
+ calculator_pb2.CalculatorGraphConfig())
344
+ input_image = np.arange(27, dtype=np.uint8).reshape(3, 3, 3)
345
+ with solution_base.SolutionBase(
346
+ graph_config=config_proto, side_inputs=side_inputs) as solution:
347
+ for _ in range(20):
348
+ outputs = solution.process(input_image)
349
+ self.assertTrue(np.array_equal(input_image, outputs.image_out))
350
+ solution.reset()
351
+
352
+ def test_solution_stream_type_hints(self):
353
+ text_config = """
354
+ input_stream: 'union_type_image_in'
355
+ output_stream: 'image_type_out'
356
+ node {
357
+ calculator: 'ToImageCalculator'
358
+ input_stream: 'IMAGE:union_type_image_in'
359
+ output_stream: 'IMAGE:image_type_out'
360
+ }
361
+ """
362
+ config_proto = text_format.Parse(text_config,
363
+ calculator_pb2.CalculatorGraphConfig())
364
+ input_image = np.arange(27, dtype=np.uint8).reshape(3, 3, 3)
365
+ with solution_base.SolutionBase(
366
+ graph_config=config_proto,
367
+ stream_type_hints={'union_type_image_in': PacketDataType.IMAGE
368
+ }) as solution:
369
+ for _ in range(20):
370
+ outputs = solution.process(input_image)
371
+ self.assertTrue(np.array_equal(input_image, outputs.image_type_out))
372
+ with solution_base.SolutionBase(
373
+ graph_config=config_proto,
374
+ stream_type_hints={'union_type_image_in': PacketDataType.IMAGE_FRAME
375
+ }) as solution2:
376
+ for _ in range(20):
377
+ outputs = solution2.process(input_image)
378
+ self.assertTrue(np.array_equal(input_image, outputs.image_type_out))
379
+
380
+ def _process_and_verify(self,
381
+ config_proto,
382
+ side_inputs=None,
383
+ calculator_params=None):
384
+ input_image = np.arange(27, dtype=np.uint8).reshape(3, 3, 3)
385
+ with solution_base.SolutionBase(
386
+ graph_config=config_proto,
387
+ side_inputs=side_inputs,
388
+ calculator_params=calculator_params) as solution:
389
+ outputs = solution.process(input_image)
390
+ outputs2 = solution.process({'image_in': input_image})
391
+ self.assertTrue(np.array_equal(input_image, outputs.image_out))
392
+ self.assertTrue(np.array_equal(input_image, outputs2.image_out))
393
+
394
+
395
+ if __name__ == '__main__':
396
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/python/timestamp_test.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The MediaPipe Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tests for mediapipe.python._framework_bindings.timestamp."""
16
+
17
+ import time
18
+
19
+ from absl.testing import absltest
20
+
21
+ from mediapipe.python._framework_bindings import timestamp
22
+
23
+ Timestamp = timestamp.Timestamp
24
+
25
+
26
+ class TimestampTest(absltest.TestCase):
27
+
28
+ def test_timestamp(self):
29
+ t = Timestamp(100)
30
+ self.assertEqual(t.value, 100)
31
+ self.assertEqual(t, 100)
32
+ self.assertEqual(str(t), '<mediapipe.Timestamp with value: 100>')
33
+
34
+ def test_timestamp_copy_constructor(self):
35
+ ts1 = Timestamp(100)
36
+ ts2 = Timestamp(ts1)
37
+ self.assertEqual(ts1, ts2)
38
+
39
+ def test_timestamp_comparsion(self):
40
+ ts1 = Timestamp(100)
41
+ ts2 = Timestamp(100)
42
+ self.assertEqual(ts1, ts2)
43
+ ts3 = Timestamp(200)
44
+ self.assertNotEqual(ts1, ts3)
45
+
46
+ def test_timestamp_special_values(self):
47
+ t1 = Timestamp.UNSET
48
+ self.assertEqual(str(t1), '<mediapipe.Timestamp with value: UNSET>')
49
+ t2 = Timestamp.UNSTARTED
50
+ self.assertEqual(str(t2), '<mediapipe.Timestamp with value: UNSTARTED>')
51
+ t3 = Timestamp.PRESTREAM
52
+ self.assertEqual(str(t3), '<mediapipe.Timestamp with value: PRESTREAM>')
53
+ t4 = Timestamp.MIN
54
+ self.assertEqual(str(t4), '<mediapipe.Timestamp with value: MIN>')
55
+ t5 = Timestamp.MAX
56
+ self.assertEqual(str(t5), '<mediapipe.Timestamp with value: MAX>')
57
+ t6 = Timestamp.POSTSTREAM
58
+ self.assertEqual(str(t6), '<mediapipe.Timestamp with value: POSTSTREAM>')
59
+ t7 = Timestamp.DONE
60
+ self.assertEqual(str(t7), '<mediapipe.Timestamp with value: DONE>')
61
+
62
+ def test_timestamp_comparisons(self):
63
+ ts1 = Timestamp(100)
64
+ ts2 = Timestamp(101)
65
+ self.assertGreater(ts2, ts1)
66
+ self.assertGreaterEqual(ts2, ts1)
67
+ self.assertLess(ts1, ts2)
68
+ self.assertLessEqual(ts1, ts2)
69
+ self.assertNotEqual(ts1, ts2)
70
+
71
+ def test_from_seconds(self):
72
+ now = time.time()
73
+ ts = Timestamp.from_seconds(now)
74
+ self.assertAlmostEqual(now, ts.seconds(), delta=1)
75
+
76
+
77
+ if __name__ == '__main__':
78
+ absltest.main()
python_embeded/Lib/site-packages/mediapipe/tasks/__init__.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Copyright 2022 The MediaPipe Authors.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ """
python_embeded/Lib/site-packages/mediapipe/tasks/cc/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/audio/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/components/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/acceleration_pb2.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/tasks/cc/core/proto/acceleration.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.calculators.tensor import inference_calculator_pb2 as mediapipe_dot_calculators_dot_tensor_dot_inference__calculator__pb2
15
+
16
+
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n0mediapipe/tasks/cc/core/proto/acceleration.proto\x12\x1amediapipe.tasks.core.proto\x1a\x37mediapipe/calculators/tensor/inference_calculator.proto\"\xb8\x02\n\x0c\x41\x63\x63\x65leration\x12I\n\x07xnnpack\x18\x01 \x01(\x0b\x32\x36.mediapipe.InferenceCalculatorOptions.Delegate.XnnpackH\x00\x12\x41\n\x03gpu\x18\x02 \x01(\x0b\x32\x32.mediapipe.InferenceCalculatorOptions.Delegate.GpuH\x00\x12G\n\x06tflite\x18\x04 \x01(\x0b\x32\x35.mediapipe.InferenceCalculatorOptions.Delegate.TfLiteH\x00\x12\x45\n\x05nnapi\x18\x05 \x01(\x0b\x32\x34.mediapipe.InferenceCalculatorOptions.Delegate.NnapiH\x00\x42\n\n\x08\x64\x65legateB:\n%com.google.mediapipe.tasks.core.protoB\x11\x41\x63\x63\x65lerationProto')
18
+
19
+ _globals = globals()
20
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
21
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.tasks.cc.core.proto.acceleration_pb2', _globals)
22
+ if _descriptor._USE_C_DESCRIPTORS == False:
23
+
24
+ DESCRIPTOR._options = None
25
+ DESCRIPTOR._serialized_options = b'\n%com.google.mediapipe.tasks.core.protoB\021AccelerationProto'
26
+ _globals['_ACCELERATION']._serialized_start=138
27
+ _globals['_ACCELERATION']._serialized_end=450
28
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/base_options_pb2.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/tasks/cc/core/proto/base_options.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.gpu import gpu_origin_pb2 as mediapipe_dot_gpu_dot_gpu__origin__pb2
15
+ from mediapipe.tasks.cc.core.proto import acceleration_pb2 as mediapipe_dot_tasks_dot_cc_dot_core_dot_proto_dot_acceleration__pb2
16
+ from mediapipe.tasks.cc.core.proto import external_file_pb2 as mediapipe_dot_tasks_dot_cc_dot_core_dot_proto_dot_external__file__pb2
17
+
18
+
19
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n0mediapipe/tasks/cc/core/proto/base_options.proto\x12\x1amediapipe.tasks.core.proto\x1a\x1emediapipe/gpu/gpu_origin.proto\x1a\x30mediapipe/tasks/cc/core/proto/acceleration.proto\x1a\x31mediapipe/tasks/cc/core/proto/external_file.proto\"\xe5\x01\n\x0b\x42\x61seOptions\x12=\n\x0bmodel_asset\x18\x01 \x01(\x0b\x32(.mediapipe.tasks.core.proto.ExternalFile\x12\x1e\n\x0fuse_stream_mode\x18\x02 \x01(\x08:\x05\x66\x61lse\x12>\n\x0c\x61\x63\x63\x65leration\x18\x03 \x01(\x0b\x32(.mediapipe.tasks.core.proto.Acceleration\x12\x37\n\ngpu_origin\x18\x04 \x01(\x0e\x32\x19.mediapipe.GpuOrigin.Mode:\x08TOP_LEFTB9\n%com.google.mediapipe.tasks.core.protoB\x10\x42\x61seOptionsProto')
20
+
21
+ _globals = globals()
22
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
23
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.tasks.cc.core.proto.base_options_pb2', _globals)
24
+ if _descriptor._USE_C_DESCRIPTORS == False:
25
+
26
+ DESCRIPTOR._options = None
27
+ DESCRIPTOR._serialized_options = b'\n%com.google.mediapipe.tasks.core.protoB\020BaseOptionsProto'
28
+ _globals['_BASEOPTIONS']._serialized_start=214
29
+ _globals['_BASEOPTIONS']._serialized_end=443
30
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/external_file_pb2.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/tasks/cc/core/proto/external_file.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+
15
+
16
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n1mediapipe/tasks/cc/core/proto/external_file.proto\x12\x1amediapipe.tasks.core.proto\"\xcd\x01\n\x0c\x45xternalFile\x12\x14\n\x0c\x66ile_content\x18\x01 \x01(\x0c\x12\x11\n\tfile_name\x18\x02 \x01(\t\x12L\n\x14\x66ile_descriptor_meta\x18\x03 \x01(\x0b\x32..mediapipe.tasks.core.proto.FileDescriptorMeta\x12\x46\n\x11\x66ile_pointer_meta\x18\x04 \x01(\x0b\x32+.mediapipe.tasks.core.proto.FilePointerMeta\"@\n\x12\x46ileDescriptorMeta\x12\n\n\x02\x66\x64\x18\x01 \x01(\x05\x12\x0e\n\x06length\x18\x02 \x01(\x03\x12\x0e\n\x06offset\x18\x03 \x01(\x03\"2\n\x0f\x46ilePointerMeta\x12\x0f\n\x07pointer\x18\x01 \x01(\x04\x12\x0e\n\x06length\x18\x02 \x01(\x03\x42:\n%com.google.mediapipe.tasks.core.protoB\x11\x45xternalFileProto')
17
+
18
+ _globals = globals()
19
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
20
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.tasks.cc.core.proto.external_file_pb2', _globals)
21
+ if _descriptor._USE_C_DESCRIPTORS == False:
22
+
23
+ DESCRIPTOR._options = None
24
+ DESCRIPTOR._serialized_options = b'\n%com.google.mediapipe.tasks.core.protoB\021ExternalFileProto'
25
+ _globals['_EXTERNALFILE']._serialized_start=82
26
+ _globals['_EXTERNALFILE']._serialized_end=287
27
+ _globals['_FILEDESCRIPTORMETA']._serialized_start=289
28
+ _globals['_FILEDESCRIPTORMETA']._serialized_end=353
29
+ _globals['_FILEPOINTERMETA']._serialized_start=355
30
+ _globals['_FILEPOINTERMETA']._serialized_end=405
31
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/inference_subgraph_pb2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/tasks/cc/core/proto/inference_subgraph.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+ from mediapipe.tasks.cc.core.proto import base_options_pb2 as mediapipe_dot_tasks_dot_cc_dot_core_dot_proto_dot_base__options__pb2
20
+
21
+
22
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n6mediapipe/tasks/cc/core/proto/inference_subgraph.proto\x12\x1amediapipe.tasks.core.proto\x1a$mediapipe/framework/calculator.proto\x1a\x30mediapipe/tasks/cc/core/proto/base_options.proto\"\xdb\x01\n\x18InferenceSubgraphOptions\x12=\n\x0c\x62\x61se_options\x18\x01 \x01(\x0b\x32\'.mediapipe.tasks.core.proto.BaseOptions\x12\x1b\n\x13model_resources_tag\x18\x02 \x01(\t2c\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\xbd\xe2\xd8\xd2\x01 \x01(\x0b\x32\x34.mediapipe.tasks.core.proto.InferenceSubgraphOptions')
23
+
24
+ _globals = globals()
25
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
26
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.tasks.cc.core.proto.inference_subgraph_pb2', _globals)
27
+ if _descriptor._USE_C_DESCRIPTORS == False:
28
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_INFERENCESUBGRAPHOPTIONS.extensions_by_name['ext'])
29
+
30
+ DESCRIPTOR._options = None
31
+ _globals['_INFERENCESUBGRAPHOPTIONS']._serialized_start=175
32
+ _globals['_INFERENCESUBGRAPHOPTIONS']._serialized_end=394
33
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/tasks/cc/core/proto/model_resources_calculator_pb2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: mediapipe/tasks/cc/core/proto/model_resources_calculator.proto
4
+ """Generated protocol buffer code."""
5
+ from google.protobuf import descriptor as _descriptor
6
+ from google.protobuf import descriptor_pool as _descriptor_pool
7
+ from google.protobuf import symbol_database as _symbol_database
8
+ from google.protobuf.internal import builder as _builder
9
+ # @@protoc_insertion_point(imports)
10
+
11
+ _sym_db = _symbol_database.Default()
12
+
13
+
14
+ from mediapipe.framework import calculator_pb2 as mediapipe_dot_framework_dot_calculator__pb2
15
+ try:
16
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe_dot_framework_dot_calculator__options__pb2
17
+ except AttributeError:
18
+ mediapipe_dot_framework_dot_calculator__options__pb2 = mediapipe_dot_framework_dot_calculator__pb2.mediapipe.framework.calculator_options_pb2
19
+ from mediapipe.tasks.cc.core.proto import external_file_pb2 as mediapipe_dot_tasks_dot_cc_dot_core_dot_proto_dot_external__file__pb2
20
+
21
+
22
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n>mediapipe/tasks/cc/core/proto/model_resources_calculator.proto\x12\x1amediapipe.tasks.core.proto\x1a$mediapipe/framework/calculator.proto\x1a\x31mediapipe/tasks/cc/core/proto/external_file.proto\"\xe8\x01\n\x1fModelResourcesCalculatorOptions\x12\x1b\n\x13model_resources_tag\x18\x01 \x01(\t\x12<\n\nmodel_file\x18\x02 \x01(\x0b\x32(.mediapipe.tasks.core.proto.ExternalFile2j\n\x03\x65xt\x12\x1c.mediapipe.CalculatorOptions\x18\xb0\xce\xf3\xd1\x01 \x01(\x0b\x32;.mediapipe.tasks.core.proto.ModelResourcesCalculatorOptions')
23
+
24
+ _globals = globals()
25
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
26
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mediapipe.tasks.cc.core.proto.model_resources_calculator_pb2', _globals)
27
+ if _descriptor._USE_C_DESCRIPTORS == False:
28
+ mediapipe_dot_framework_dot_calculator__options__pb2.CalculatorOptions.RegisterExtension(_MODELRESOURCESCALCULATOROPTIONS.extensions_by_name['ext'])
29
+
30
+ DESCRIPTOR._options = None
31
+ _globals['_MODELRESOURCESCALCULATOROPTIONS']._serialized_start=184
32
+ _globals['_MODELRESOURCESCALCULATOROPTIONS']._serialized_end=416
33
+ # @@protoc_insertion_point(module_scope)
python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/inference/__init__.py ADDED
File without changes
python_embeded/Lib/site-packages/mediapipe/tasks/cc/genai/inference/c/__init__.py ADDED
File without changes