mediapipe-nightly 0.0.0.post20231103__cp39-cp39-macosx_11_0_universal2.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (545) hide show
  1. mediapipe/__init__.py +26 -0
  2. mediapipe/calculators/__init__.py +0 -0
  3. mediapipe/calculators/audio/__init__.py +0 -0
  4. mediapipe/calculators/audio/mfcc_mel_calculators_pb2.py +34 -0
  5. mediapipe/calculators/audio/rational_factor_resample_calculator_pb2.py +33 -0
  6. mediapipe/calculators/audio/spectrogram_calculator_pb2.py +35 -0
  7. mediapipe/calculators/audio/stabilized_log_calculator_pb2.py +31 -0
  8. mediapipe/calculators/audio/time_series_framer_calculator_pb2.py +33 -0
  9. mediapipe/calculators/core/__init__.py +0 -0
  10. mediapipe/calculators/core/bypass_calculator_pb2.py +31 -0
  11. mediapipe/calculators/core/clip_vector_size_calculator_pb2.py +31 -0
  12. mediapipe/calculators/core/concatenate_vector_calculator_pb2.py +31 -0
  13. mediapipe/calculators/core/constant_side_packet_calculator_pb2.py +37 -0
  14. mediapipe/calculators/core/dequantize_byte_array_calculator_pb2.py +31 -0
  15. mediapipe/calculators/core/flow_limiter_calculator_pb2.py +32 -0
  16. mediapipe/calculators/core/gate_calculator_pb2.py +33 -0
  17. mediapipe/calculators/core/get_vector_item_calculator_pb2.py +31 -0
  18. mediapipe/calculators/core/graph_profile_calculator_pb2.py +31 -0
  19. mediapipe/calculators/core/packet_cloner_calculator_pb2.py +31 -0
  20. mediapipe/calculators/core/packet_resampler_calculator_pb2.py +33 -0
  21. mediapipe/calculators/core/packet_thinner_calculator_pb2.py +33 -0
  22. mediapipe/calculators/core/quantize_float_vector_calculator_pb2.py +31 -0
  23. mediapipe/calculators/core/sequence_shift_calculator_pb2.py +31 -0
  24. mediapipe/calculators/core/split_vector_calculator_pb2.py +33 -0
  25. mediapipe/calculators/image/__init__.py +0 -0
  26. mediapipe/calculators/image/bilateral_filter_calculator_pb2.py +31 -0
  27. mediapipe/calculators/image/feature_detector_calculator_pb2.py +31 -0
  28. mediapipe/calculators/image/image_clone_calculator_pb2.py +31 -0
  29. mediapipe/calculators/image/image_cropping_calculator_pb2.py +33 -0
  30. mediapipe/calculators/image/image_transformation_calculator_pb2.py +38 -0
  31. mediapipe/calculators/image/mask_overlay_calculator_pb2.py +33 -0
  32. mediapipe/calculators/image/opencv_encoded_image_to_image_frame_calculator_pb2.py +31 -0
  33. mediapipe/calculators/image/opencv_image_encoder_calculator_pb2.py +35 -0
  34. mediapipe/calculators/image/recolor_calculator_pb2.py +34 -0
  35. mediapipe/calculators/image/rotation_mode_pb2.py +28 -0
  36. mediapipe/calculators/image/scale_image_calculator_pb2.py +34 -0
  37. mediapipe/calculators/image/segmentation_smoothing_calculator_pb2.py +31 -0
  38. mediapipe/calculators/image/set_alpha_calculator_pb2.py +31 -0
  39. mediapipe/calculators/image/warp_affine_calculator_pb2.py +36 -0
  40. mediapipe/calculators/internal/__init__.py +0 -0
  41. mediapipe/calculators/internal/callback_packet_calculator_pb2.py +33 -0
  42. mediapipe/calculators/tensor/__init__.py +0 -0
  43. mediapipe/calculators/tensor/audio_to_tensor_calculator_pb2.py +35 -0
  44. mediapipe/calculators/tensor/bert_preprocessor_calculator_pb2.py +31 -0
  45. mediapipe/calculators/tensor/feedback_tensors_calculator_pb2.py +37 -0
  46. mediapipe/calculators/tensor/image_to_tensor_calculator_pb2.py +40 -0
  47. mediapipe/calculators/tensor/inference_calculator_pb2.py +53 -0
  48. mediapipe/calculators/tensor/landmarks_to_tensor_calculator_pb2.py +33 -0
  49. mediapipe/calculators/tensor/regex_preprocessor_calculator_pb2.py +31 -0
  50. mediapipe/calculators/tensor/tensor_converter_calculator_pb2.py +34 -0
  51. mediapipe/calculators/tensor/tensor_to_joints_calculator_pb2.py +31 -0
  52. mediapipe/calculators/tensor/tensors_readback_calculator_pb2.py +35 -0
  53. mediapipe/calculators/tensor/tensors_to_audio_calculator_pb2.py +33 -0
  54. mediapipe/calculators/tensor/tensors_to_classification_calculator_pb2.py +44 -0
  55. mediapipe/calculators/tensor/tensors_to_detections_calculator_pb2.py +39 -0
  56. mediapipe/calculators/tensor/tensors_to_floats_calculator_pb2.py +33 -0
  57. mediapipe/calculators/tensor/tensors_to_landmarks_calculator_pb2.py +33 -0
  58. mediapipe/calculators/tensor/tensors_to_segmentation_calculator_pb2.py +34 -0
  59. mediapipe/calculators/tflite/__init__.py +0 -0
  60. mediapipe/calculators/tflite/ssd_anchors_calculator_pb2.py +32 -0
  61. mediapipe/calculators/tflite/tflite_converter_calculator_pb2.py +33 -0
  62. mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator_pb2.py +31 -0
  63. mediapipe/calculators/tflite/tflite_inference_calculator_pb2.py +49 -0
  64. mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator_pb2.py +31 -0
  65. mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator_pb2.py +31 -0
  66. mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator_pb2.py +33 -0
  67. mediapipe/calculators/tflite/tflite_tensors_to_segmentation_calculator_pb2.py +31 -0
  68. mediapipe/calculators/util/__init__.py +0 -0
  69. mediapipe/calculators/util/align_hand_to_pose_in_world_calculator_pb2.py +31 -0
  70. mediapipe/calculators/util/annotation_overlay_calculator_pb2.py +32 -0
  71. mediapipe/calculators/util/association_calculator_pb2.py +31 -0
  72. mediapipe/calculators/util/collection_has_min_size_calculator_pb2.py +31 -0
  73. mediapipe/calculators/util/combine_joints_calculator_pb2.py +36 -0
  74. mediapipe/calculators/util/detection_label_id_to_text_calculator_pb2.py +36 -0
  75. mediapipe/calculators/util/detections_to_rects_calculator_pb2.py +33 -0
  76. mediapipe/calculators/util/detections_to_render_data_calculator_pb2.py +33 -0
  77. mediapipe/calculators/util/face_to_rect_calculator_pb2.py +25 -0
  78. mediapipe/calculators/util/filter_detections_calculator_pb2.py +31 -0
  79. mediapipe/calculators/util/flat_color_image_calculator_pb2.py +32 -0
  80. mediapipe/calculators/util/labels_to_render_data_calculator_pb2.py +34 -0
  81. mediapipe/calculators/util/landmark_projection_calculator_pb2.py +31 -0
  82. mediapipe/calculators/util/landmarks_refinement_calculator_pb2.py +41 -0
  83. mediapipe/calculators/util/landmarks_smoothing_calculator_pb2.py +33 -0
  84. mediapipe/calculators/util/landmarks_to_detection_calculator_pb2.py +31 -0
  85. mediapipe/calculators/util/landmarks_to_floats_calculator_pb2.py +31 -0
  86. mediapipe/calculators/util/landmarks_to_render_data_calculator_pb2.py +32 -0
  87. mediapipe/calculators/util/landmarks_transformation_calculator_pb2.py +37 -0
  88. mediapipe/calculators/util/latency_pb2.py +25 -0
  89. mediapipe/calculators/util/local_file_contents_calculator_pb2.py +31 -0
  90. mediapipe/calculators/util/logic_calculator_pb2.py +34 -0
  91. mediapipe/calculators/util/non_max_suppression_calculator_pb2.py +35 -0
  92. mediapipe/calculators/util/packet_frequency_calculator_pb2.py +31 -0
  93. mediapipe/calculators/util/packet_frequency_pb2.py +25 -0
  94. mediapipe/calculators/util/packet_latency_calculator_pb2.py +31 -0
  95. mediapipe/calculators/util/rect_to_render_data_calculator_pb2.py +32 -0
  96. mediapipe/calculators/util/rect_to_render_scale_calculator_pb2.py +31 -0
  97. mediapipe/calculators/util/rect_transformation_calculator_pb2.py +31 -0
  98. mediapipe/calculators/util/refine_landmarks_from_heatmap_calculator_pb2.py +31 -0
  99. mediapipe/calculators/util/set_joints_visibility_calculator_pb2.py +41 -0
  100. mediapipe/calculators/util/thresholding_calculator_pb2.py +31 -0
  101. mediapipe/calculators/util/timed_box_list_id_to_label_calculator_pb2.py +31 -0
  102. mediapipe/calculators/util/timed_box_list_to_render_data_calculator_pb2.py +32 -0
  103. mediapipe/calculators/util/top_k_scores_calculator_pb2.py +31 -0
  104. mediapipe/calculators/util/visibility_copy_calculator_pb2.py +27 -0
  105. mediapipe/calculators/util/visibility_smoothing_calculator_pb2.py +31 -0
  106. mediapipe/calculators/video/__init__.py +0 -0
  107. mediapipe/calculators/video/box_detector_calculator_pb2.py +32 -0
  108. mediapipe/calculators/video/box_tracker_calculator_pb2.py +32 -0
  109. mediapipe/calculators/video/flow_packager_calculator_pb2.py +32 -0
  110. mediapipe/calculators/video/flow_to_image_calculator_pb2.py +31 -0
  111. mediapipe/calculators/video/motion_analysis_calculator_pb2.py +42 -0
  112. mediapipe/calculators/video/opencv_video_encoder_calculator_pb2.py +31 -0
  113. mediapipe/calculators/video/tool/__init__.py +0 -0
  114. mediapipe/calculators/video/tool/flow_quantizer_model_pb2.py +25 -0
  115. mediapipe/calculators/video/tracked_detection_manager_calculator_pb2.py +32 -0
  116. mediapipe/calculators/video/video_pre_stream_calculator_pb2.py +35 -0
  117. mediapipe/examples/__init__.py +14 -0
  118. mediapipe/examples/desktop/__init__.py +14 -0
  119. mediapipe/framework/__init__.py +0 -0
  120. mediapipe/framework/calculator_options_pb2.py +28 -0
  121. mediapipe/framework/calculator_pb2.py +56 -0
  122. mediapipe/framework/calculator_profile_pb2.py +47 -0
  123. mediapipe/framework/deps/__init__.py +0 -0
  124. mediapipe/framework/deps/proto_descriptor_pb2.py +28 -0
  125. mediapipe/framework/formats/__init__.py +0 -0
  126. mediapipe/framework/formats/affine_transform_data_pb2.py +27 -0
  127. mediapipe/framework/formats/annotation/__init__.py +0 -0
  128. mediapipe/framework/formats/annotation/locus_pb2.py +31 -0
  129. mediapipe/framework/formats/annotation/rasterization_pb2.py +28 -0
  130. mediapipe/framework/formats/body_rig_pb2.py +27 -0
  131. mediapipe/framework/formats/classification_pb2.py +30 -0
  132. mediapipe/framework/formats/detection_pb2.py +35 -0
  133. mediapipe/framework/formats/image_file_properties_pb2.py +25 -0
  134. mediapipe/framework/formats/image_format_pb2.py +28 -0
  135. mediapipe/framework/formats/landmark_pb2.py +36 -0
  136. mediapipe/framework/formats/location_data_pb2.py +37 -0
  137. mediapipe/framework/formats/matrix_data_pb2.py +30 -0
  138. mediapipe/framework/formats/motion/__init__.py +0 -0
  139. mediapipe/framework/formats/motion/optical_flow_field_data_pb2.py +29 -0
  140. mediapipe/framework/formats/object_detection/__init__.py +0 -0
  141. mediapipe/framework/formats/object_detection/anchor_pb2.py +25 -0
  142. mediapipe/framework/formats/rect_pb2.py +28 -0
  143. mediapipe/framework/formats/time_series_header_pb2.py +27 -0
  144. mediapipe/framework/mediapipe_options_pb2.py +26 -0
  145. mediapipe/framework/packet_factory_pb2.py +30 -0
  146. mediapipe/framework/packet_generator_pb2.py +32 -0
  147. mediapipe/framework/status_handler_pb2.py +27 -0
  148. mediapipe/framework/stream_handler/__init__.py +0 -0
  149. mediapipe/framework/stream_handler/default_input_stream_handler_pb2.py +27 -0
  150. mediapipe/framework/stream_handler/fixed_size_input_stream_handler_pb2.py +27 -0
  151. mediapipe/framework/stream_handler/sync_set_input_stream_handler_pb2.py +29 -0
  152. mediapipe/framework/stream_handler/timestamp_align_input_stream_handler_pb2.py +27 -0
  153. mediapipe/framework/stream_handler_pb2.py +29 -0
  154. mediapipe/framework/test_calculators_pb2.py +31 -0
  155. mediapipe/framework/thread_pool_executor_pb2.py +29 -0
  156. mediapipe/framework/tool/__init__.py +0 -0
  157. mediapipe/framework/tool/calculator_graph_template_pb2.py +44 -0
  158. mediapipe/framework/tool/field_data_pb2.py +27 -0
  159. mediapipe/framework/tool/node_chain_subgraph_pb2.py +31 -0
  160. mediapipe/framework/tool/packet_generator_wrapper_calculator_pb2.py +28 -0
  161. mediapipe/framework/tool/source_pb2.py +33 -0
  162. mediapipe/framework/tool/switch_container_pb2.py +32 -0
  163. mediapipe/gpu/__init__.py +0 -0
  164. mediapipe/gpu/copy_calculator_pb2.py +33 -0
  165. mediapipe/gpu/gl_animation_overlay_calculator_pb2.py +31 -0
  166. mediapipe/gpu/gl_context_options_pb2.py +31 -0
  167. mediapipe/gpu/gl_scaler_calculator_pb2.py +32 -0
  168. mediapipe/gpu/gl_surface_sink_calculator_pb2.py +32 -0
  169. mediapipe/gpu/gpu_origin_pb2.py +28 -0
  170. mediapipe/gpu/scale_mode_pb2.py +27 -0
  171. mediapipe/model_maker/__init__.py +27 -0
  172. mediapipe/model_maker/setup.py +107 -0
  173. mediapipe/modules/__init__.py +0 -0
  174. mediapipe/modules/face_detection/__init__.py +0 -0
  175. mediapipe/modules/face_detection/face_detection_full_range_cpu.binarypb +0 -0
  176. mediapipe/modules/face_detection/face_detection_full_range_sparse.tflite +0 -0
  177. mediapipe/modules/face_detection/face_detection_pb2.py +30 -0
  178. mediapipe/modules/face_detection/face_detection_short_range.tflite +0 -0
  179. mediapipe/modules/face_detection/face_detection_short_range_cpu.binarypb +0 -0
  180. mediapipe/modules/face_geometry/__init__.py +0 -0
  181. mediapipe/modules/face_geometry/data/__init__.py +0 -0
  182. mediapipe/modules/face_geometry/effect_renderer_calculator_pb2.py +27 -0
  183. mediapipe/modules/face_geometry/env_generator_calculator_pb2.py +28 -0
  184. mediapipe/modules/face_geometry/geometry_pipeline_calculator_pb2.py +27 -0
  185. mediapipe/modules/face_geometry/libs/__init__.py +0 -0
  186. mediapipe/modules/face_geometry/protos/__init__.py +0 -0
  187. mediapipe/modules/face_geometry/protos/environment_pb2.py +30 -0
  188. mediapipe/modules/face_geometry/protos/face_geometry_pb2.py +28 -0
  189. mediapipe/modules/face_geometry/protos/geometry_pipeline_metadata_pb2.py +31 -0
  190. mediapipe/modules/face_geometry/protos/mesh_3d_pb2.py +30 -0
  191. mediapipe/modules/face_landmark/__init__.py +0 -0
  192. mediapipe/modules/face_landmark/face_landmark.tflite +0 -0
  193. mediapipe/modules/face_landmark/face_landmark_front_cpu.binarypb +0 -0
  194. mediapipe/modules/face_landmark/face_landmark_with_attention.tflite +0 -0
  195. mediapipe/modules/hand_landmark/__init__.py +0 -0
  196. mediapipe/modules/hand_landmark/calculators/__init__.py +0 -0
  197. mediapipe/modules/hand_landmark/hand_landmark_full.tflite +0 -0
  198. mediapipe/modules/hand_landmark/hand_landmark_lite.tflite +0 -0
  199. mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb +0 -0
  200. mediapipe/modules/hand_landmark/handedness.txt +2 -0
  201. mediapipe/modules/holistic_landmark/__init__.py +0 -0
  202. mediapipe/modules/holistic_landmark/calculators/__init__.py +0 -0
  203. mediapipe/modules/holistic_landmark/calculators/roi_tracking_calculator_pb2.py +37 -0
  204. mediapipe/modules/holistic_landmark/hand_recrop.tflite +0 -0
  205. mediapipe/modules/holistic_landmark/holistic_landmark_cpu.binarypb +0 -0
  206. mediapipe/modules/iris_landmark/__init__.py +0 -0
  207. mediapipe/modules/iris_landmark/iris_landmark.tflite +0 -0
  208. mediapipe/modules/objectron/__init__.py +0 -0
  209. mediapipe/modules/objectron/calculators/__init__.py +0 -0
  210. mediapipe/modules/objectron/calculators/a_r_capture_metadata_pb2.py +101 -0
  211. mediapipe/modules/objectron/calculators/annotation_data_pb2.py +37 -0
  212. mediapipe/modules/objectron/calculators/belief_decoder_config_pb2.py +27 -0
  213. mediapipe/modules/objectron/calculators/camera_parameters_pb2.py +29 -0
  214. mediapipe/modules/objectron/calculators/filter_detection_calculator_pb2.py +35 -0
  215. mediapipe/modules/objectron/calculators/frame_annotation_to_rect_calculator_pb2.py +31 -0
  216. mediapipe/modules/objectron/calculators/frame_annotation_tracker_calculator_pb2.py +31 -0
  217. mediapipe/modules/objectron/calculators/lift_2d_frame_annotation_to_3d_calculator_pb2.py +32 -0
  218. mediapipe/modules/objectron/calculators/object_pb2.py +37 -0
  219. mediapipe/modules/objectron/calculators/tensors_to_objects_calculator_pb2.py +32 -0
  220. mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator_pb2.py +32 -0
  221. mediapipe/modules/objectron/object_detection_oidv4_labelmap.txt +24 -0
  222. mediapipe/modules/objectron/objectron_cpu.binarypb +0 -0
  223. mediapipe/modules/palm_detection/__init__.py +0 -0
  224. mediapipe/modules/palm_detection/palm_detection_full.tflite +0 -0
  225. mediapipe/modules/palm_detection/palm_detection_lite.tflite +0 -0
  226. mediapipe/modules/pose_detection/__init__.py +0 -0
  227. mediapipe/modules/pose_detection/pose_detection.tflite +0 -0
  228. mediapipe/modules/pose_landmark/__init__.py +0 -0
  229. mediapipe/modules/pose_landmark/pose_landmark_cpu.binarypb +0 -0
  230. mediapipe/modules/pose_landmark/pose_landmark_full.tflite +0 -0
  231. mediapipe/modules/selfie_segmentation/__init__.py +0 -0
  232. mediapipe/modules/selfie_segmentation/selfie_segmentation.tflite +0 -0
  233. mediapipe/modules/selfie_segmentation/selfie_segmentation_cpu.binarypb +0 -0
  234. mediapipe/modules/selfie_segmentation/selfie_segmentation_landscape.tflite +0 -0
  235. mediapipe/python/__init__.py +28 -0
  236. mediapipe/python/_framework_bindings/arm64.cpython-39-darwin.so +0 -0
  237. mediapipe/python/_framework_bindings.cpython-39-darwin.so +0 -0
  238. mediapipe/python/calculator_graph_test.py +251 -0
  239. mediapipe/python/image_frame_test.py +194 -0
  240. mediapipe/python/image_test.py +218 -0
  241. mediapipe/python/packet_creator.py +275 -0
  242. mediapipe/python/packet_getter.py +119 -0
  243. mediapipe/python/packet_test.py +533 -0
  244. mediapipe/python/solution_base.py +632 -0
  245. mediapipe/python/solution_base_test.py +396 -0
  246. mediapipe/python/solutions/__init__.py +27 -0
  247. mediapipe/python/solutions/download_utils.py +37 -0
  248. mediapipe/python/solutions/drawing_styles.py +249 -0
  249. mediapipe/python/solutions/drawing_utils.py +316 -0
  250. mediapipe/python/solutions/drawing_utils_test.py +258 -0
  251. mediapipe/python/solutions/face_detection.py +105 -0
  252. mediapipe/python/solutions/face_detection_test.py +92 -0
  253. mediapipe/python/solutions/face_mesh.py +125 -0
  254. mediapipe/python/solutions/face_mesh_connections.py +500 -0
  255. mediapipe/python/solutions/face_mesh_test.py +170 -0
  256. mediapipe/python/solutions/hands.py +153 -0
  257. mediapipe/python/solutions/hands_connections.py +32 -0
  258. mediapipe/python/solutions/hands_test.py +218 -0
  259. mediapipe/python/solutions/holistic.py +167 -0
  260. mediapipe/python/solutions/holistic_test.py +142 -0
  261. mediapipe/python/solutions/objectron.py +288 -0
  262. mediapipe/python/solutions/objectron_test.py +81 -0
  263. mediapipe/python/solutions/pose.py +192 -0
  264. mediapipe/python/solutions/pose_connections.py +22 -0
  265. mediapipe/python/solutions/pose_test.py +262 -0
  266. mediapipe/python/solutions/selfie_segmentation.py +76 -0
  267. mediapipe/python/solutions/selfie_segmentation_test.py +68 -0
  268. mediapipe/python/timestamp_test.py +78 -0
  269. mediapipe/tasks/__init__.py +14 -0
  270. mediapipe/tasks/cc/__init__.py +0 -0
  271. mediapipe/tasks/cc/audio/__init__.py +0 -0
  272. mediapipe/tasks/cc/audio/audio_classifier/__init__.py +0 -0
  273. mediapipe/tasks/cc/audio/audio_classifier/proto/__init__.py +0 -0
  274. mediapipe/tasks/cc/audio/audio_classifier/proto/audio_classifier_graph_options_pb2.py +35 -0
  275. mediapipe/tasks/cc/audio/audio_embedder/__init__.py +0 -0
  276. mediapipe/tasks/cc/audio/audio_embedder/proto/__init__.py +0 -0
  277. mediapipe/tasks/cc/audio/audio_embedder/proto/audio_embedder_graph_options_pb2.py +35 -0
  278. mediapipe/tasks/cc/audio/core/__init__.py +0 -0
  279. mediapipe/tasks/cc/audio/utils/__init__.py +0 -0
  280. mediapipe/tasks/cc/components/__init__.py +0 -0
  281. mediapipe/tasks/cc/components/calculators/__init__.py +0 -0
  282. mediapipe/tasks/cc/components/calculators/classification_aggregation_calculator_pb2.py +31 -0
  283. mediapipe/tasks/cc/components/calculators/score_calibration_calculator_pb2.py +35 -0
  284. mediapipe/tasks/cc/components/calculators/tensors_to_embeddings_calculator_pb2.py +32 -0
  285. mediapipe/tasks/cc/components/containers/__init__.py +0 -0
  286. mediapipe/tasks/cc/components/containers/proto/__init__.py +0 -0
  287. mediapipe/tasks/cc/components/containers/proto/classifications_pb2.py +29 -0
  288. mediapipe/tasks/cc/components/containers/proto/embeddings_pb2.py +34 -0
  289. mediapipe/tasks/cc/components/containers/proto/landmarks_detection_result_pb2.py +31 -0
  290. mediapipe/tasks/cc/components/processors/__init__.py +0 -0
  291. mediapipe/tasks/cc/components/processors/proto/__init__.py +0 -0
  292. mediapipe/tasks/cc/components/processors/proto/classification_postprocessing_graph_options_pb2.py +38 -0
  293. mediapipe/tasks/cc/components/processors/proto/classifier_options_pb2.py +26 -0
  294. mediapipe/tasks/cc/components/processors/proto/detection_postprocessing_graph_options_pb2.py +35 -0
  295. mediapipe/tasks/cc/components/processors/proto/detector_options_pb2.py +26 -0
  296. mediapipe/tasks/cc/components/processors/proto/embedder_options_pb2.py +26 -0
  297. mediapipe/tasks/cc/components/processors/proto/embedding_postprocessing_graph_options_pb2.py +32 -0
  298. mediapipe/tasks/cc/components/processors/proto/image_preprocessing_graph_options_pb2.py +34 -0
  299. mediapipe/tasks/cc/components/processors/proto/llm_params_pb2.py +27 -0
  300. mediapipe/tasks/cc/components/processors/proto/text_model_type_pb2.py +27 -0
  301. mediapipe/tasks/cc/components/processors/proto/text_preprocessing_graph_options_pb2.py +32 -0
  302. mediapipe/tasks/cc/components/processors/proto/transformer_params_pb2.py +28 -0
  303. mediapipe/tasks/cc/components/utils/__init__.py +0 -0
  304. mediapipe/tasks/cc/core/__init__.py +0 -0
  305. mediapipe/tasks/cc/core/proto/__init__.py +0 -0
  306. mediapipe/tasks/cc/core/proto/acceleration_pb2.py +27 -0
  307. mediapipe/tasks/cc/core/proto/base_options_pb2.py +29 -0
  308. mediapipe/tasks/cc/core/proto/external_file_pb2.py +30 -0
  309. mediapipe/tasks/cc/core/proto/inference_subgraph_pb2.py +32 -0
  310. mediapipe/tasks/cc/core/proto/model_resources_calculator_pb2.py +32 -0
  311. mediapipe/tasks/cc/metadata/__init__.py +0 -0
  312. mediapipe/tasks/cc/metadata/python/__init__.py +0 -0
  313. mediapipe/tasks/cc/metadata/python/_pywrap_metadata_version/arm64.cpython-39-darwin.so +0 -0
  314. mediapipe/tasks/cc/metadata/python/_pywrap_metadata_version.cpython-39-darwin.so +0 -0
  315. mediapipe/tasks/cc/metadata/tests/__init__.py +0 -0
  316. mediapipe/tasks/cc/metadata/utils/__init__.py +0 -0
  317. mediapipe/tasks/cc/text/__init__.py +0 -0
  318. mediapipe/tasks/cc/text/custom_ops/__init__.py +0 -0
  319. mediapipe/tasks/cc/text/custom_ops/ragged/__init__.py +0 -0
  320. mediapipe/tasks/cc/text/custom_ops/sentencepiece/__init__.py +0 -0
  321. mediapipe/tasks/cc/text/custom_ops/sentencepiece/testdata/__init__.py +0 -0
  322. mediapipe/tasks/cc/text/language_detector/__init__.py +0 -0
  323. mediapipe/tasks/cc/text/language_detector/custom_ops/__init__.py +0 -0
  324. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/__init__.py +0 -0
  325. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/hash/__init__.py +0 -0
  326. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/utf/__init__.py +0 -0
  327. mediapipe/tasks/cc/text/text_classifier/__init__.py +0 -0
  328. mediapipe/tasks/cc/text/text_classifier/proto/__init__.py +0 -0
  329. mediapipe/tasks/cc/text/text_classifier/proto/text_classifier_graph_options_pb2.py +35 -0
  330. mediapipe/tasks/cc/text/text_embedder/__init__.py +0 -0
  331. mediapipe/tasks/cc/text/text_embedder/proto/__init__.py +0 -0
  332. mediapipe/tasks/cc/text/text_embedder/proto/text_embedder_graph_options_pb2.py +35 -0
  333. mediapipe/tasks/cc/text/tokenizers/__init__.py +0 -0
  334. mediapipe/tasks/cc/text/utils/__init__.py +0 -0
  335. mediapipe/tasks/cc/vision/__init__.py +0 -0
  336. mediapipe/tasks/cc/vision/core/__init__.py +0 -0
  337. mediapipe/tasks/cc/vision/custom_ops/__init__.py +0 -0
  338. mediapipe/tasks/cc/vision/face_detector/__init__.py +0 -0
  339. mediapipe/tasks/cc/vision/face_detector/proto/__init__.py +0 -0
  340. mediapipe/tasks/cc/vision/face_detector/proto/face_detector_graph_options_pb2.py +34 -0
  341. mediapipe/tasks/cc/vision/face_geometry/__init__.py +0 -0
  342. mediapipe/tasks/cc/vision/face_geometry/calculators/__init__.py +0 -0
  343. mediapipe/tasks/cc/vision/face_geometry/calculators/env_generator_calculator_pb2.py +28 -0
  344. mediapipe/tasks/cc/vision/face_geometry/calculators/geometry_pipeline_calculator_pb2.py +29 -0
  345. mediapipe/tasks/cc/vision/face_geometry/data/__init__.py +0 -0
  346. mediapipe/tasks/cc/vision/face_geometry/libs/__init__.py +0 -0
  347. mediapipe/tasks/cc/vision/face_geometry/proto/__init__.py +0 -0
  348. mediapipe/tasks/cc/vision/face_geometry/proto/environment_pb2.py +30 -0
  349. mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_graph_options_pb2.py +29 -0
  350. mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_pb2.py +28 -0
  351. mediapipe/tasks/cc/vision/face_geometry/proto/geometry_pipeline_metadata_pb2.py +31 -0
  352. mediapipe/tasks/cc/vision/face_geometry/proto/mesh_3d_pb2.py +30 -0
  353. mediapipe/tasks/cc/vision/face_landmarker/__init__.py +0 -0
  354. mediapipe/tasks/cc/vision/face_landmarker/proto/__init__.py +0 -0
  355. mediapipe/tasks/cc/vision/face_landmarker/proto/face_blendshapes_graph_options_pb2.py +34 -0
  356. mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarker_graph_options_pb2.py +37 -0
  357. mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarks_detector_graph_options_pb2.py +35 -0
  358. mediapipe/tasks/cc/vision/face_landmarker/proto/tensors_to_face_landmarks_graph_options_pb2.py +32 -0
  359. mediapipe/tasks/cc/vision/face_stylizer/__init__.py +0 -0
  360. mediapipe/tasks/cc/vision/face_stylizer/calculators/__init__.py +0 -0
  361. mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator_pb2.py +36 -0
  362. mediapipe/tasks/cc/vision/face_stylizer/proto/__init__.py +0 -0
  363. mediapipe/tasks/cc/vision/face_stylizer/proto/face_stylizer_graph_options_pb2.py +35 -0
  364. mediapipe/tasks/cc/vision/gesture_recognizer/__init__.py +0 -0
  365. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/__init__.py +0 -0
  366. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/combined_prediction_calculator_pb2.py +33 -0
  367. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/landmarks_to_matrix_calculator_pb2.py +31 -0
  368. mediapipe/tasks/cc/vision/gesture_recognizer/proto/__init__.py +0 -0
  369. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_classifier_graph_options_pb2.py +35 -0
  370. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_embedder_graph_options_pb2.py +34 -0
  371. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_recognizer_graph_options_pb2.py +36 -0
  372. mediapipe/tasks/cc/vision/gesture_recognizer/proto/hand_gesture_recognizer_graph_options_pb2.py +36 -0
  373. mediapipe/tasks/cc/vision/hand_detector/__init__.py +0 -0
  374. mediapipe/tasks/cc/vision/hand_detector/proto/__init__.py +0 -0
  375. mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options_pb2.py +34 -0
  376. mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_result_pb2.py +29 -0
  377. mediapipe/tasks/cc/vision/hand_landmarker/__init__.py +0 -0
  378. mediapipe/tasks/cc/vision/hand_landmarker/calculators/__init__.py +0 -0
  379. mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator_pb2.py +31 -0
  380. mediapipe/tasks/cc/vision/hand_landmarker/proto/__init__.py +0 -0
  381. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb2.py +36 -0
  382. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb2.py +34 -0
  383. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_roi_refinement_graph_options_pb2.py +26 -0
  384. mediapipe/tasks/cc/vision/image_classifier/__init__.py +0 -0
  385. mediapipe/tasks/cc/vision/image_classifier/proto/__init__.py +0 -0
  386. mediapipe/tasks/cc/vision/image_classifier/proto/image_classifier_graph_options_pb2.py +35 -0
  387. mediapipe/tasks/cc/vision/image_embedder/__init__.py +0 -0
  388. mediapipe/tasks/cc/vision/image_embedder/proto/__init__.py +0 -0
  389. mediapipe/tasks/cc/vision/image_embedder/proto/image_embedder_graph_options_pb2.py +35 -0
  390. mediapipe/tasks/cc/vision/image_generator/__init__.py +0 -0
  391. mediapipe/tasks/cc/vision/image_generator/diffuser/__init__.py +0 -0
  392. mediapipe/tasks/cc/vision/image_generator/diffuser/stable_diffusion_iterate_calculator_pb2.py +40 -0
  393. mediapipe/tasks/cc/vision/image_generator/proto/__init__.py +0 -0
  394. mediapipe/tasks/cc/vision/image_generator/proto/conditioned_image_graph_options_pb2.py +39 -0
  395. mediapipe/tasks/cc/vision/image_generator/proto/control_plugin_graph_options_pb2.py +33 -0
  396. mediapipe/tasks/cc/vision/image_generator/proto/image_generator_graph_options_pb2.py +29 -0
  397. mediapipe/tasks/cc/vision/image_segmenter/__init__.py +0 -0
  398. mediapipe/tasks/cc/vision/image_segmenter/calculators/__init__.py +0 -0
  399. mediapipe/tasks/cc/vision/image_segmenter/calculators/tensors_to_segmentation_calculator_pb2.py +34 -0
  400. mediapipe/tasks/cc/vision/image_segmenter/proto/__init__.py +0 -0
  401. mediapipe/tasks/cc/vision/image_segmenter/proto/image_segmenter_graph_options_pb2.py +35 -0
  402. mediapipe/tasks/cc/vision/image_segmenter/proto/segmenter_options_pb2.py +32 -0
  403. mediapipe/tasks/cc/vision/interactive_segmenter/__init__.py +0 -0
  404. mediapipe/tasks/cc/vision/object_detector/__init__.py +0 -0
  405. mediapipe/tasks/cc/vision/object_detector/proto/__init__.py +0 -0
  406. mediapipe/tasks/cc/vision/object_detector/proto/object_detector_options_pb2.py +34 -0
  407. mediapipe/tasks/cc/vision/pose_detector/__init__.py +0 -0
  408. mediapipe/tasks/cc/vision/pose_detector/proto/__init__.py +0 -0
  409. mediapipe/tasks/cc/vision/pose_detector/proto/pose_detector_graph_options_pb2.py +34 -0
  410. mediapipe/tasks/cc/vision/pose_landmarker/__init__.py +0 -0
  411. mediapipe/tasks/cc/vision/pose_landmarker/proto/__init__.py +0 -0
  412. mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarker_graph_options_pb2.py +36 -0
  413. mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarks_detector_graph_options_pb2.py +34 -0
  414. mediapipe/tasks/cc/vision/utils/__init__.py +0 -0
  415. mediapipe/tasks/cc/vision/utils/ghum/__init__.py +0 -0
  416. mediapipe/tasks/metadata/image_segmenter_metadata_schema.fbs +59 -0
  417. mediapipe/tasks/metadata/image_segmenter_metadata_schema_py_generated.py +108 -0
  418. mediapipe/tasks/metadata/metadata_schema.fbs +732 -0
  419. mediapipe/tasks/metadata/metadata_schema_py_generated.py +3251 -0
  420. mediapipe/tasks/metadata/object_detector_metadata_schema.fbs +98 -0
  421. mediapipe/tasks/metadata/object_detector_metadata_schema_py_generated.py +674 -0
  422. mediapipe/tasks/metadata/schema_py_generated.py +14263 -0
  423. mediapipe/tasks/python/__init__.py +26 -0
  424. mediapipe/tasks/python/audio/__init__.py +33 -0
  425. mediapipe/tasks/python/audio/audio_classifier.py +324 -0
  426. mediapipe/tasks/python/audio/audio_embedder.py +285 -0
  427. mediapipe/tasks/python/audio/core/__init__.py +16 -0
  428. mediapipe/tasks/python/audio/core/audio_record.py +125 -0
  429. mediapipe/tasks/python/audio/core/audio_task_running_mode.py +29 -0
  430. mediapipe/tasks/python/audio/core/base_audio_task_api.py +181 -0
  431. mediapipe/tasks/python/components/__init__.py +13 -0
  432. mediapipe/tasks/python/components/containers/__init__.py +53 -0
  433. mediapipe/tasks/python/components/containers/audio_data.py +137 -0
  434. mediapipe/tasks/python/components/containers/bounding_box.py +73 -0
  435. mediapipe/tasks/python/components/containers/category.py +78 -0
  436. mediapipe/tasks/python/components/containers/classification_result.py +111 -0
  437. mediapipe/tasks/python/components/containers/detections.py +181 -0
  438. mediapipe/tasks/python/components/containers/embedding_result.py +89 -0
  439. mediapipe/tasks/python/components/containers/keypoint.py +77 -0
  440. mediapipe/tasks/python/components/containers/landmark.py +122 -0
  441. mediapipe/tasks/python/components/containers/landmark_detection_result.py +106 -0
  442. mediapipe/tasks/python/components/containers/rect.py +109 -0
  443. mediapipe/tasks/python/components/processors/__init__.py +23 -0
  444. mediapipe/tasks/python/components/processors/classifier_options.py +86 -0
  445. mediapipe/tasks/python/components/utils/__init__.py +13 -0
  446. mediapipe/tasks/python/components/utils/cosine_similarity.py +68 -0
  447. mediapipe/tasks/python/core/__init__.py +13 -0
  448. mediapipe/tasks/python/core/base_options.py +121 -0
  449. mediapipe/tasks/python/core/optional_dependencies.py +25 -0
  450. mediapipe/tasks/python/core/task_info.py +132 -0
  451. mediapipe/tasks/python/metadata/__init__.py +13 -0
  452. mediapipe/tasks/python/metadata/flatbuffers_lib/_pywrap_flatbuffers/arm64.cpython-39-darwin.so +0 -0
  453. mediapipe/tasks/python/metadata/flatbuffers_lib/_pywrap_flatbuffers.cpython-39-darwin.so +0 -0
  454. mediapipe/tasks/python/metadata/metadata.py +928 -0
  455. mediapipe/tasks/python/metadata/metadata_displayer_cli.py +34 -0
  456. mediapipe/tasks/python/metadata/metadata_writers/__init__.py +13 -0
  457. mediapipe/tasks/python/metadata/metadata_writers/face_stylizer.py +138 -0
  458. mediapipe/tasks/python/metadata/metadata_writers/image_classifier.py +71 -0
  459. mediapipe/tasks/python/metadata/metadata_writers/image_segmenter.py +170 -0
  460. mediapipe/tasks/python/metadata/metadata_writers/metadata_info.py +1166 -0
  461. mediapipe/tasks/python/metadata/metadata_writers/metadata_writer.py +845 -0
  462. mediapipe/tasks/python/metadata/metadata_writers/model_asset_bundle_utils.py +71 -0
  463. mediapipe/tasks/python/metadata/metadata_writers/object_detector.py +331 -0
  464. mediapipe/tasks/python/metadata/metadata_writers/text_classifier.py +119 -0
  465. mediapipe/tasks/python/metadata/metadata_writers/writer_utils.py +91 -0
  466. mediapipe/tasks/python/test/__init__.py +13 -0
  467. mediapipe/tasks/python/test/audio/__init__.py +13 -0
  468. mediapipe/tasks/python/test/audio/audio_classifier_test.py +387 -0
  469. mediapipe/tasks/python/test/audio/audio_embedder_test.py +297 -0
  470. mediapipe/tasks/python/test/test_utils.py +196 -0
  471. mediapipe/tasks/python/test/text/__init__.py +13 -0
  472. mediapipe/tasks/python/test/text/language_detector_test.py +228 -0
  473. mediapipe/tasks/python/test/text/text_classifier_test.py +231 -0
  474. mediapipe/tasks/python/test/text/text_embedder_test.py +326 -0
  475. mediapipe/tasks/python/test/vision/__init__.py +13 -0
  476. mediapipe/tasks/python/test/vision/face_aligner_test.py +190 -0
  477. mediapipe/tasks/python/test/vision/face_detector_test.py +523 -0
  478. mediapipe/tasks/python/test/vision/face_landmarker_test.py +565 -0
  479. mediapipe/tasks/python/test/vision/face_stylizer_test.py +191 -0
  480. mediapipe/tasks/python/test/vision/hand_landmarker_test.py +437 -0
  481. mediapipe/tasks/python/test/vision/image_classifier_test.py +657 -0
  482. mediapipe/tasks/python/test/vision/image_embedder_test.py +423 -0
  483. mediapipe/tasks/python/test/vision/image_segmenter_test.py +512 -0
  484. mediapipe/tasks/python/test/vision/interactive_segmenter_test.py +341 -0
  485. mediapipe/tasks/python/test/vision/object_detector_test.py +493 -0
  486. mediapipe/tasks/python/test/vision/pose_landmarker_test.py +518 -0
  487. mediapipe/tasks/python/text/__init__.py +35 -0
  488. mediapipe/tasks/python/text/core/__init__.py +16 -0
  489. mediapipe/tasks/python/text/core/base_text_task_api.py +54 -0
  490. mediapipe/tasks/python/text/language_detector.py +220 -0
  491. mediapipe/tasks/python/text/text_classifier.py +187 -0
  492. mediapipe/tasks/python/text/text_embedder.py +188 -0
  493. mediapipe/tasks/python/vision/__init__.py +83 -0
  494. mediapipe/tasks/python/vision/core/__init__.py +14 -0
  495. mediapipe/tasks/python/vision/core/base_vision_task_api.py +226 -0
  496. mediapipe/tasks/python/vision/core/image_processing_options.py +39 -0
  497. mediapipe/tasks/python/vision/core/vision_task_running_mode.py +31 -0
  498. mediapipe/tasks/python/vision/face_aligner.py +158 -0
  499. mediapipe/tasks/python/vision/face_detector.py +332 -0
  500. mediapipe/tasks/python/vision/face_landmarker.py +3244 -0
  501. mediapipe/tasks/python/vision/face_stylizer.py +158 -0
  502. mediapipe/tasks/python/vision/gesture_recognizer.py +480 -0
  503. mediapipe/tasks/python/vision/hand_landmarker.py +504 -0
  504. mediapipe/tasks/python/vision/image_classifier.py +358 -0
  505. mediapipe/tasks/python/vision/image_embedder.py +362 -0
  506. mediapipe/tasks/python/vision/image_segmenter.py +433 -0
  507. mediapipe/tasks/python/vision/interactive_segmenter.py +285 -0
  508. mediapipe/tasks/python/vision/object_detector.py +385 -0
  509. mediapipe/tasks/python/vision/pose_landmarker.py +455 -0
  510. mediapipe/util/__init__.py +0 -0
  511. mediapipe/util/analytics/__init__.py +0 -0
  512. mediapipe/util/analytics/mediapipe_log_extension_pb2.py +41 -0
  513. mediapipe/util/analytics/mediapipe_logging_enums_pb2.py +36 -0
  514. mediapipe/util/audio_decoder_pb2.py +33 -0
  515. mediapipe/util/color_pb2.py +32 -0
  516. mediapipe/util/label_map_pb2.py +26 -0
  517. mediapipe/util/render_data_pb2.py +57 -0
  518. mediapipe/util/sequence/__init__.py +14 -0
  519. mediapipe/util/sequence/media_sequence.py +716 -0
  520. mediapipe/util/sequence/media_sequence_test.py +290 -0
  521. mediapipe/util/sequence/media_sequence_util.py +800 -0
  522. mediapipe/util/sequence/media_sequence_util_test.py +389 -0
  523. mediapipe/util/tracking/__init__.py +0 -0
  524. mediapipe/util/tracking/box_detector_pb2.py +38 -0
  525. mediapipe/util/tracking/box_tracker_pb2.py +31 -0
  526. mediapipe/util/tracking/camera_motion_pb2.py +30 -0
  527. mediapipe/util/tracking/flow_packager_pb2.py +59 -0
  528. mediapipe/util/tracking/frame_selection_pb2.py +34 -0
  529. mediapipe/util/tracking/frame_selection_solution_evaluator_pb2.py +27 -0
  530. mediapipe/util/tracking/motion_analysis_pb2.py +34 -0
  531. mediapipe/util/tracking/motion_estimation_pb2.py +65 -0
  532. mediapipe/util/tracking/motion_models_pb2.py +41 -0
  533. mediapipe/util/tracking/motion_saliency_pb2.py +25 -0
  534. mediapipe/util/tracking/push_pull_filtering_pb2.py +25 -0
  535. mediapipe/util/tracking/region_flow_computation_pb2.py +58 -0
  536. mediapipe/util/tracking/region_flow_pb2.py +48 -0
  537. mediapipe/util/tracking/tone_estimation_pb2.py +44 -0
  538. mediapipe/util/tracking/tone_models_pb2.py +31 -0
  539. mediapipe/util/tracking/tracked_detection_manager_config_pb2.py +25 -0
  540. mediapipe/util/tracking/tracking_pb2.py +72 -0
  541. mediapipe_nightly-0.0.0.post20231103.dist-info/LICENSE +218 -0
  542. mediapipe_nightly-0.0.0.post20231103.dist-info/METADATA +196 -0
  543. mediapipe_nightly-0.0.0.post20231103.dist-info/RECORD +545 -0
  544. mediapipe_nightly-0.0.0.post20231103.dist-info/WHEEL +5 -0
  545. mediapipe_nightly-0.0.0.post20231103.dist-info/top_level.txt +4 -0
@@ -0,0 +1,632 @@
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':
121
+ PacketDataType.STRING,
122
+ 'bool':
123
+ PacketDataType.BOOL,
124
+ '::std::vector<bool>':
125
+ PacketDataType.BOOL_LIST,
126
+ 'int':
127
+ PacketDataType.INT,
128
+ '::std::vector<int>':
129
+ PacketDataType.INT_LIST,
130
+ 'int64':
131
+ PacketDataType.INT,
132
+ '::std::vector<int64>':
133
+ PacketDataType.INT_LIST,
134
+ 'float':
135
+ PacketDataType.FLOAT,
136
+ '::std::vector<float>':
137
+ PacketDataType.FLOAT_LIST,
138
+ '::mediapipe::Matrix':
139
+ PacketDataType.AUDIO,
140
+ '::mediapipe::ImageFrame':
141
+ PacketDataType.IMAGE_FRAME,
142
+ '::mediapipe::Classification':
143
+ PacketDataType.PROTO,
144
+ '::mediapipe::ClassificationList':
145
+ PacketDataType.PROTO,
146
+ '::mediapipe::ClassificationListCollection':
147
+ PacketDataType.PROTO,
148
+ '::mediapipe::Detection':
149
+ PacketDataType.PROTO,
150
+ '::mediapipe::DetectionList':
151
+ PacketDataType.PROTO,
152
+ '::mediapipe::Landmark':
153
+ PacketDataType.PROTO,
154
+ '::mediapipe::LandmarkList':
155
+ PacketDataType.PROTO,
156
+ '::mediapipe::LandmarkListCollection':
157
+ PacketDataType.PROTO,
158
+ '::mediapipe::NormalizedLandmark':
159
+ PacketDataType.PROTO,
160
+ '::mediapipe::FrameAnnotation':
161
+ PacketDataType.PROTO,
162
+ '::mediapipe::Trigger':
163
+ PacketDataType.PROTO,
164
+ '::mediapipe::Rect':
165
+ PacketDataType.PROTO,
166
+ '::mediapipe::NormalizedRect':
167
+ PacketDataType.PROTO,
168
+ '::mediapipe::NormalizedLandmarkList':
169
+ PacketDataType.PROTO,
170
+ '::mediapipe::NormalizedLandmarkListCollection':
171
+ PacketDataType.PROTO,
172
+ '::mediapipe::Image':
173
+ PacketDataType.IMAGE,
174
+ '::std::vector<::mediapipe::Image>':
175
+ PacketDataType.IMAGE_LIST,
176
+ '::std::vector<::mediapipe::Classification>':
177
+ PacketDataType.PROTO_LIST,
178
+ '::std::vector<::mediapipe::ClassificationList>':
179
+ PacketDataType.PROTO_LIST,
180
+ '::std::vector<::mediapipe::Detection>':
181
+ PacketDataType.PROTO_LIST,
182
+ '::std::vector<::mediapipe::DetectionList>':
183
+ PacketDataType.PROTO_LIST,
184
+ '::std::vector<::mediapipe::Landmark>':
185
+ PacketDataType.PROTO_LIST,
186
+ '::std::vector<::mediapipe::LandmarkList>':
187
+ PacketDataType.PROTO_LIST,
188
+ '::std::vector<::mediapipe::NormalizedLandmark>':
189
+ PacketDataType.PROTO_LIST,
190
+ '::std::vector<::mediapipe::NormalizedLandmarkList>':
191
+ PacketDataType.PROTO_LIST,
192
+ '::std::vector<::mediapipe::Rect>':
193
+ PacketDataType.PROTO_LIST,
194
+ '::std::vector<::mediapipe::NormalizedRect>':
195
+ PacketDataType.PROTO_LIST,
196
+ '::mediapipe::Joint':
197
+ PacketDataType.PROTO,
198
+ '::mediapipe::JointList':
199
+ PacketDataType.PROTO,
200
+ '::std::vector<::mediapipe::JointList>':
201
+ PacketDataType.PROTO_LIST,
202
+ }
203
+
204
+
205
+ class SolutionBase:
206
+ """The common base class for the high-level MediaPipe Solution APIs.
207
+
208
+ The SolutionBase class contains the shared logic among the high-level solution
209
+ APIs including graph initialization, processing image/audio data, and graph
210
+ shutdown.
211
+
212
+ Example usage:
213
+ with solution_base.SolutionBase(
214
+ binary_graph_path='mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb',
215
+ side_inputs={'num_hands': 2}) as hand_tracker:
216
+ # Read an image and convert the BGR image to RGB.
217
+ input_image = cv2.cvtColor(cv2.imread('/tmp/hand.png'), COLOR_BGR2RGB)
218
+ results = hand_tracker.process(input_image)
219
+ print(results.palm_detections)
220
+ print(results.multi_hand_landmarks)
221
+ """
222
+
223
+ def __init__(
224
+ self,
225
+ binary_graph_path: Optional[str] = None,
226
+ graph_config: Optional[calculator_pb2.CalculatorGraphConfig] = None,
227
+ calculator_params: Optional[Mapping[str, Any]] = None,
228
+ graph_options: Optional[message.Message] = None,
229
+ side_inputs: Optional[Mapping[str, Any]] = None,
230
+ outputs: Optional[List[str]] = None,
231
+ stream_type_hints: Optional[Mapping[str, PacketDataType]] = None):
232
+ """Initializes the SolutionBase object.
233
+
234
+ Args:
235
+ binary_graph_path: The path to a binary mediapipe graph file (.binarypb).
236
+ graph_config: A CalculatorGraphConfig proto message or its text proto
237
+ format.
238
+ calculator_params: A mapping from the
239
+ {calculator_name}.{options_field_name} str to the field value.
240
+ graph_options: The graph options protobuf for the mediapipe graph.
241
+ side_inputs: A mapping from the side packet name to the packet raw data.
242
+ outputs: A list of the graph output stream names to observe. If the list
243
+ is empty, all the output streams listed in the graph config will be
244
+ automatically observed by default.
245
+ stream_type_hints: A mapping from the stream name to its packet type hint.
246
+
247
+ Raises:
248
+ FileNotFoundError: If the binary graph file can't be found.
249
+ RuntimeError: If the underlying calculator graph can't be successfully
250
+ initialized or started.
251
+ ValueError: If any of the following:
252
+ a) If not exactly one of 'binary_graph_path' or 'graph_config' arguments
253
+ is provided.
254
+ b) If the graph validation process contains error.
255
+ c) If the registered type name of the streams and side packets can't be
256
+ found.
257
+ d) If the calculator options of the calculator listed in
258
+ calculator_params is not allowed to be modified.
259
+ e) If the calculator options field is a repeated field but the field
260
+ value to be set is not iterable.
261
+ f) If not all calculator params are valid.
262
+ """
263
+ if bool(binary_graph_path) == bool(graph_config):
264
+ raise ValueError(
265
+ "Must provide exactly one of 'binary_graph_path' or 'graph_config'.")
266
+ # MediaPipe package root path
267
+ root_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-3])
268
+ resource_util.set_resource_dir(root_path)
269
+ validated_graph = validated_graph_config.ValidatedGraphConfig()
270
+ if binary_graph_path:
271
+ validated_graph.initialize(
272
+ binary_graph_path=os.path.join(root_path, binary_graph_path))
273
+ else:
274
+ validated_graph.initialize(graph_config=graph_config)
275
+
276
+ canonical_graph_config_proto = self._initialize_graph_interface(
277
+ validated_graph, side_inputs, outputs, stream_type_hints)
278
+ if calculator_params:
279
+ self._modify_calculator_options(canonical_graph_config_proto,
280
+ calculator_params)
281
+ if graph_options:
282
+ self._set_extension(canonical_graph_config_proto.graph_options,
283
+ graph_options)
284
+
285
+ self._graph = calculator_graph.CalculatorGraph(
286
+ graph_config=canonical_graph_config_proto)
287
+ self._simulated_timestamp = 0
288
+ self._graph_outputs = {}
289
+
290
+ def callback(stream_name: str, output_packet: packet.Packet) -> None:
291
+ self._graph_outputs[stream_name] = output_packet
292
+
293
+ for stream_name in self._output_stream_type_info.keys():
294
+ self._graph.observe_output_stream(stream_name, callback, True)
295
+
296
+ self._input_side_packets = {
297
+ name: self._make_packet(self._side_input_type_info[name], data)
298
+ for name, data in (side_inputs or {}).items()
299
+ }
300
+ self._graph.start_run(self._input_side_packets)
301
+
302
+ # TODO: Use "inspect.Parameter" to fetch the input argument names and
303
+ # types from "_input_stream_type_info" and then auto generate the process
304
+ # method signature by "inspect.Signature" in __init__.
305
+ def process(
306
+ self, input_data: Union[np.ndarray, Mapping[str, Union[np.ndarray,
307
+ message.Message]]]
308
+ ) -> NamedTuple:
309
+ """Processes a set of RGB image data and output SolutionOutputs.
310
+
311
+ Args:
312
+ input_data: Either a single numpy ndarray object representing the solo
313
+ image input of a graph or a mapping from the stream name to the image or
314
+ proto data that represents every input streams of a graph.
315
+
316
+ Raises:
317
+ NotImplementedError: If input_data contains audio data or a list of proto
318
+ objects.
319
+ RuntimeError: If the underlying graph occurs any error.
320
+ ValueError: If the input image data is not three channel RGB.
321
+
322
+ Returns:
323
+ A NamedTuple object that contains the output data of a graph run.
324
+ The field names in the NamedTuple object are mapping to the graph output
325
+ stream names.
326
+
327
+ Examples:
328
+ solution = solution_base.SolutionBase(graph_config=hand_landmark_graph)
329
+ results = solution.process(cv2.imread('/tmp/hand0.png')[:, :, ::-1])
330
+ print(results.detection)
331
+ results = solution.process(
332
+ {'video_in' : cv2.imread('/tmp/hand1.png')[:, :, ::-1]})
333
+ print(results.hand_landmarks)
334
+ """
335
+ self._graph_outputs.clear()
336
+
337
+ if isinstance(input_data, np.ndarray):
338
+ if len(self._input_stream_type_info.keys()) != 1:
339
+ raise ValueError(
340
+ "Can't process single image input since the graph has more than one input streams."
341
+ )
342
+ input_dict = {next(iter(self._input_stream_type_info)): input_data}
343
+ else:
344
+ input_dict = input_data
345
+
346
+ # Set the timestamp increment to 33333 us to simulate the 30 fps video
347
+ # input.
348
+ self._simulated_timestamp += 33333
349
+ for stream_name, data in input_dict.items():
350
+ input_stream_type = self._input_stream_type_info[stream_name]
351
+ if (input_stream_type == PacketDataType.PROTO_LIST or
352
+ input_stream_type == PacketDataType.AUDIO):
353
+ # TODO: Support audio data.
354
+ raise NotImplementedError(
355
+ f'SolutionBase can only process non-audio and non-proto-list data. '
356
+ f'{self._input_stream_type_info[stream_name].name} '
357
+ f'type is not supported yet.')
358
+ elif (input_stream_type == PacketDataType.IMAGE_FRAME or
359
+ input_stream_type == PacketDataType.IMAGE):
360
+ if data.shape[2] != RGB_CHANNELS:
361
+ raise ValueError('Input image must contain three channel rgb data.')
362
+ self._graph.add_packet_to_input_stream(
363
+ stream=stream_name,
364
+ packet=self._make_packet(input_stream_type,
365
+ data).at(self._simulated_timestamp))
366
+ else:
367
+ self._graph.add_packet_to_input_stream(
368
+ stream=stream_name,
369
+ packet=self._make_packet(input_stream_type,
370
+ data).at(self._simulated_timestamp))
371
+
372
+ self._graph.wait_until_idle()
373
+ # Create a NamedTuple object where the field names are mapping to the graph
374
+ # output stream names.
375
+ solution_outputs = collections.namedtuple(
376
+ 'SolutionOutputs', self._output_stream_type_info.keys())
377
+ for stream_name in self._output_stream_type_info.keys():
378
+ if stream_name in self._graph_outputs:
379
+ setattr(
380
+ solution_outputs, stream_name,
381
+ self._get_packet_content(self._output_stream_type_info[stream_name],
382
+ self._graph_outputs[stream_name]))
383
+ else:
384
+ setattr(solution_outputs, stream_name, None)
385
+
386
+ return solution_outputs
387
+
388
+ def close(self) -> None:
389
+ """Closes all the input sources and the graph."""
390
+ self._graph.close()
391
+ self._graph = None
392
+ self._input_stream_type_info = None
393
+ self._output_stream_type_info = None
394
+
395
+ def reset(self) -> None:
396
+ """Resets the graph for another run."""
397
+ if self._graph:
398
+ self._graph.close()
399
+ self._graph.start_run(self._input_side_packets)
400
+
401
+ def _initialize_graph_interface(
402
+ self,
403
+ validated_graph: validated_graph_config.ValidatedGraphConfig,
404
+ side_inputs: Optional[Mapping[str, Any]] = None,
405
+ outputs: Optional[List[str]] = None,
406
+ stream_type_hints: Optional[Mapping[str, PacketDataType]] = None):
407
+ """Gets graph interface type information and returns the canonical graph config proto."""
408
+
409
+ canonical_graph_config_proto = calculator_pb2.CalculatorGraphConfig()
410
+ canonical_graph_config_proto.ParseFromString(validated_graph.binary_config)
411
+
412
+ # Gets name from a 'TAG:index:name' str.
413
+ def get_name(tag_index_name):
414
+ return tag_index_name.split(':')[-1]
415
+
416
+ # Gets the packet type information of the input streams and output streams
417
+ # from the user provided stream_type_hints field or validated calculator
418
+ # graph. The mappings from the stream names to the packet data types is
419
+ # for deciding which packet creator and getter methods to call in the
420
+ # process() method.
421
+ def get_stream_packet_type(packet_tag_index_name):
422
+ stream_name = get_name(packet_tag_index_name)
423
+ if stream_type_hints and stream_name in stream_type_hints.keys():
424
+ return stream_type_hints[stream_name]
425
+ return PacketDataType.from_registered_name(
426
+ validated_graph.registered_stream_type_name(stream_name))
427
+
428
+ self._input_stream_type_info = {
429
+ get_name(tag_index_name): get_stream_packet_type(tag_index_name)
430
+ for tag_index_name in canonical_graph_config_proto.input_stream
431
+ }
432
+
433
+ if not outputs:
434
+ output_streams = canonical_graph_config_proto.output_stream
435
+ else:
436
+ output_streams = outputs
437
+ self._output_stream_type_info = {
438
+ get_name(tag_index_name): get_stream_packet_type(tag_index_name)
439
+ for tag_index_name in output_streams
440
+ }
441
+
442
+ # Gets the packet type information of the input side packets from the
443
+ # validated calculator graph. The mappings from the side packet names to the
444
+ # packet data types is for making the input_side_packets dict for graph
445
+ # start_run().
446
+ def get_side_packet_type(packet_tag_index_name):
447
+ return PacketDataType.from_registered_name(
448
+ validated_graph.registered_side_packet_type_name(
449
+ get_name(packet_tag_index_name)))
450
+
451
+ self._side_input_type_info = {
452
+ get_name(tag_index_name): get_side_packet_type(tag_index_name)
453
+ for tag_index_name, _ in (side_inputs or {}).items()
454
+ }
455
+ return canonical_graph_config_proto
456
+
457
+ def _modify_calculator_options(
458
+ self, calculator_graph_config: calculator_pb2.CalculatorGraphConfig,
459
+ calculator_params: Mapping[str, Any]) -> None:
460
+ """Modifies the CalculatorOptions of the calculators listed in calculator_params."""
461
+
462
+ # Reorganizes the calculator options field data by calculator name and puts
463
+ # all the field data of the same calculator in a list.
464
+ def generate_nested_calculator_params(flat_map):
465
+ nested_map = {}
466
+ for compound_name, field_value in flat_map.items():
467
+ calculator_and_field_name = compound_name.split('.')
468
+ if len(calculator_and_field_name) != 2:
469
+ raise ValueError(
470
+ f'The key "{compound_name}" in the calculator_params is invalid.')
471
+ calculator_name = calculator_and_field_name[0]
472
+ field_name = calculator_and_field_name[1]
473
+ if calculator_name in nested_map:
474
+ nested_map[calculator_name].append((field_name, field_value))
475
+ else:
476
+ nested_map[calculator_name] = [(field_name, field_value)]
477
+ return nested_map
478
+
479
+ def modify_options_fields(calculator_options, options_field_list):
480
+ for field_name, field_value in options_field_list:
481
+ if field_value is None:
482
+ calculator_options.ClearField(field_name)
483
+ else:
484
+ field_label = calculator_options.DESCRIPTOR.fields_by_name[
485
+ field_name].label
486
+ if field_label == descriptor.FieldDescriptor.LABEL_REPEATED:
487
+ if not isinstance(field_value, Iterable):
488
+ raise ValueError(
489
+ f'{field_name} is a repeated proto field but the value '
490
+ f'to be set is {type(field_value)}, which is not iterable.')
491
+ # TODO: Support resetting the entire repeated field
492
+ # (array-option) and changing the individual values in the repeated
493
+ # field (array-element-option).
494
+ calculator_options.ClearField(field_name)
495
+ for elem in field_value:
496
+ getattr(calculator_options, field_name).append(elem)
497
+ else:
498
+ setattr(calculator_options, field_name, field_value)
499
+
500
+ nested_calculator_params = generate_nested_calculator_params(
501
+ calculator_params)
502
+
503
+ num_modified = 0
504
+ for node in calculator_graph_config.node:
505
+ if node.name not in nested_calculator_params:
506
+ continue
507
+ options_type = CALCULATOR_TO_OPTIONS.get(node.calculator)
508
+ if options_type is None:
509
+ raise ValueError(
510
+ f'Modifying the calculator options of {node.name} is not supported.'
511
+ )
512
+ options_field_list = nested_calculator_params[node.name]
513
+ if node.HasField('options') and node.node_options:
514
+ raise ValueError(
515
+ f'Cannot modify the calculator options of {node.name} because it '
516
+ f'has both options and node_options fields.')
517
+ if node.node_options:
518
+ # The "node_options" case for the proto3 syntax.
519
+ node_options_modified = False
520
+ for elem in node.node_options:
521
+ type_name = elem.type_url.split('/')[-1]
522
+ if type_name == options_type.DESCRIPTOR.full_name:
523
+ calculator_options = options_type.FromString(elem.value)
524
+ modify_options_fields(calculator_options, options_field_list)
525
+ elem.value = calculator_options.SerializeToString()
526
+ node_options_modified = True
527
+ break
528
+ # There is no existing node_options being modified. Add a new
529
+ # node_options instead.
530
+ if not node_options_modified:
531
+ calculator_options = options_type()
532
+ modify_options_fields(calculator_options, options_field_list)
533
+ node.node_options.add().Pack(calculator_options)
534
+ else:
535
+ # The "options" case for the proto2 syntax as well as the fallback
536
+ # when the calculator doesn't have either "options" or "node_options".
537
+ modify_options_fields(node.options.Extensions[options_type.ext],
538
+ options_field_list)
539
+
540
+ num_modified += 1
541
+ # Exits the loop early when every elements in nested_calculator_params
542
+ # have been visited.
543
+ if num_modified == len(nested_calculator_params):
544
+ break
545
+ if num_modified < len(nested_calculator_params):
546
+ raise ValueError('Not all calculator params are valid.')
547
+
548
+ def create_graph_options(self, options_message: message.Message,
549
+ values: Mapping[str, Any]) -> message.Message:
550
+ """Sets protobuf field values.
551
+
552
+ Args:
553
+ options_message: the options protobuf message.
554
+ values: field value pairs, where each field may be a "." separated path.
555
+
556
+ Returns:
557
+ the options protobuf message.
558
+ """
559
+
560
+ if hasattr(values, 'items'):
561
+ values = values.items()
562
+ for pair in values:
563
+ (field, value) = pair
564
+ fields = field.split('.')
565
+ m = options_message
566
+ while len(fields) > 1:
567
+ m = getattr(m, fields[0])
568
+ del fields[0]
569
+ v = getattr(m, fields[0])
570
+ if hasattr(v, 'append'):
571
+ del v[:]
572
+ v.extend(value)
573
+ elif hasattr(v, 'CopyFrom'):
574
+ v.CopyFrom(value)
575
+ else:
576
+ setattr(m, fields[0], value)
577
+ return options_message
578
+
579
+ def _set_extension(self,
580
+ extension_list: containers.RepeatedCompositeFieldContainer,
581
+ extension_value: message.Message) -> None:
582
+ """Sets one value in a repeated protobuf.Any extension field."""
583
+ for extension_any in extension_list:
584
+ if extension_any.Is(extension_value.DESCRIPTOR):
585
+ v = type(extension_value)()
586
+ extension_any.Unpack(v)
587
+ v.MergeFrom(extension_value)
588
+ extension_any.Pack(v)
589
+ return
590
+ extension_list.add().Pack(extension_value)
591
+
592
+ def _make_packet(self, packet_data_type: PacketDataType,
593
+ data: Any) -> packet.Packet:
594
+ if (packet_data_type == PacketDataType.IMAGE_FRAME or
595
+ packet_data_type == PacketDataType.IMAGE):
596
+ return getattr(packet_creator, 'create_' + packet_data_type.value)(
597
+ data, image_format=image_frame.ImageFormat.SRGB)
598
+ else:
599
+ return getattr(packet_creator, 'create_' + packet_data_type.value)(data)
600
+
601
+ def _get_packet_content(self, packet_data_type: PacketDataType,
602
+ output_packet: packet.Packet) -> Any:
603
+ """Gets packet content from a packet by type.
604
+
605
+ Args:
606
+ packet_data_type: The supported packet data type.
607
+ output_packet: The packet to get content from.
608
+
609
+ Returns:
610
+ Packet content by packet data type. None to indicate "no output".
611
+
612
+ """
613
+
614
+ if output_packet.is_empty():
615
+ return None
616
+ if packet_data_type == PacketDataType.STRING:
617
+ return packet_getter.get_str(output_packet)
618
+ elif (packet_data_type == PacketDataType.IMAGE_FRAME or
619
+ packet_data_type == PacketDataType.IMAGE):
620
+ return getattr(packet_getter, 'get_' +
621
+ packet_data_type.value)(output_packet).numpy_view()
622
+ else:
623
+ return getattr(packet_getter, 'get_' + packet_data_type.value)(
624
+ output_packet)
625
+
626
+ def __enter__(self):
627
+ """A "with" statement support."""
628
+ return self
629
+
630
+ def __exit__(self, exc_type, exc_val, exc_tb):
631
+ """Closes all the input sources and the graph."""
632
+ self.close()