mediapipe-nightly 0.10.21.post20250114__cp39-cp39-manylinux_2_28_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (593) 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 +33 -0
  5. mediapipe/calculators/audio/rational_factor_resample_calculator_pb2.py +33 -0
  6. mediapipe/calculators/audio/spectrogram_calculator_pb2.py +37 -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 +39 -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 +29 -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 +63 -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/tensor/vector_to_tensor_calculator_pb2.py +27 -0
  60. mediapipe/calculators/tflite/__init__.py +0 -0
  61. mediapipe/calculators/tflite/ssd_anchors_calculator_pb2.py +32 -0
  62. mediapipe/calculators/tflite/tflite_converter_calculator_pb2.py +33 -0
  63. mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator_pb2.py +31 -0
  64. mediapipe/calculators/tflite/tflite_inference_calculator_pb2.py +49 -0
  65. mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator_pb2.py +31 -0
  66. mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator_pb2.py +31 -0
  67. mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator_pb2.py +33 -0
  68. mediapipe/calculators/tflite/tflite_tensors_to_segmentation_calculator_pb2.py +31 -0
  69. mediapipe/calculators/util/__init__.py +0 -0
  70. mediapipe/calculators/util/align_hand_to_pose_in_world_calculator_pb2.py +31 -0
  71. mediapipe/calculators/util/annotation_overlay_calculator_pb2.py +32 -0
  72. mediapipe/calculators/util/association_calculator_pb2.py +31 -0
  73. mediapipe/calculators/util/collection_has_min_size_calculator_pb2.py +31 -0
  74. mediapipe/calculators/util/combine_joints_calculator_pb2.py +36 -0
  75. mediapipe/calculators/util/detection_label_id_to_text_calculator_pb2.py +36 -0
  76. mediapipe/calculators/util/detections_to_rects_calculator_pb2.py +33 -0
  77. mediapipe/calculators/util/detections_to_render_data_calculator_pb2.py +33 -0
  78. mediapipe/calculators/util/face_to_rect_calculator_pb2.py +26 -0
  79. mediapipe/calculators/util/filter_detections_calculator_pb2.py +31 -0
  80. mediapipe/calculators/util/flat_color_image_calculator_pb2.py +32 -0
  81. mediapipe/calculators/util/labels_to_render_data_calculator_pb2.py +34 -0
  82. mediapipe/calculators/util/landmark_projection_calculator_pb2.py +31 -0
  83. mediapipe/calculators/util/landmarks_refinement_calculator_pb2.py +41 -0
  84. mediapipe/calculators/util/landmarks_smoothing_calculator_pb2.py +33 -0
  85. mediapipe/calculators/util/landmarks_to_detection_calculator_pb2.py +31 -0
  86. mediapipe/calculators/util/landmarks_to_floats_calculator_pb2.py +31 -0
  87. mediapipe/calculators/util/landmarks_to_render_data_calculator_pb2.py +32 -0
  88. mediapipe/calculators/util/landmarks_transformation_calculator_pb2.py +37 -0
  89. mediapipe/calculators/util/latency_pb2.py +26 -0
  90. mediapipe/calculators/util/local_file_contents_calculator_pb2.py +31 -0
  91. mediapipe/calculators/util/logic_calculator_pb2.py +34 -0
  92. mediapipe/calculators/util/non_max_suppression_calculator_pb2.py +35 -0
  93. mediapipe/calculators/util/packet_frequency_calculator_pb2.py +31 -0
  94. mediapipe/calculators/util/packet_frequency_pb2.py +26 -0
  95. mediapipe/calculators/util/packet_latency_calculator_pb2.py +31 -0
  96. mediapipe/calculators/util/rect_to_render_data_calculator_pb2.py +32 -0
  97. mediapipe/calculators/util/rect_to_render_scale_calculator_pb2.py +31 -0
  98. mediapipe/calculators/util/rect_transformation_calculator_pb2.py +31 -0
  99. mediapipe/calculators/util/refine_landmarks_from_heatmap_calculator_pb2.py +31 -0
  100. mediapipe/calculators/util/resource_provider_calculator_pb2.py +28 -0
  101. mediapipe/calculators/util/set_joints_visibility_calculator_pb2.py +41 -0
  102. mediapipe/calculators/util/thresholding_calculator_pb2.py +31 -0
  103. mediapipe/calculators/util/timed_box_list_id_to_label_calculator_pb2.py +31 -0
  104. mediapipe/calculators/util/timed_box_list_to_render_data_calculator_pb2.py +32 -0
  105. mediapipe/calculators/util/top_k_scores_calculator_pb2.py +31 -0
  106. mediapipe/calculators/util/visibility_copy_calculator_pb2.py +27 -0
  107. mediapipe/calculators/util/visibility_smoothing_calculator_pb2.py +31 -0
  108. mediapipe/calculators/video/__init__.py +0 -0
  109. mediapipe/calculators/video/box_detector_calculator_pb2.py +32 -0
  110. mediapipe/calculators/video/box_tracker_calculator_pb2.py +32 -0
  111. mediapipe/calculators/video/flow_packager_calculator_pb2.py +32 -0
  112. mediapipe/calculators/video/flow_to_image_calculator_pb2.py +31 -0
  113. mediapipe/calculators/video/motion_analysis_calculator_pb2.py +42 -0
  114. mediapipe/calculators/video/opencv_video_encoder_calculator_pb2.py +31 -0
  115. mediapipe/calculators/video/tool/__init__.py +0 -0
  116. mediapipe/calculators/video/tool/flow_quantizer_model_pb2.py +26 -0
  117. mediapipe/calculators/video/tracked_detection_manager_calculator_pb2.py +32 -0
  118. mediapipe/calculators/video/video_pre_stream_calculator_pb2.py +35 -0
  119. mediapipe/examples/__init__.py +14 -0
  120. mediapipe/examples/desktop/__init__.py +14 -0
  121. mediapipe/framework/__init__.py +0 -0
  122. mediapipe/framework/calculator_options_pb2.py +29 -0
  123. mediapipe/framework/calculator_pb2.py +59 -0
  124. mediapipe/framework/calculator_profile_pb2.py +48 -0
  125. mediapipe/framework/deps/__init__.py +0 -0
  126. mediapipe/framework/deps/proto_descriptor_pb2.py +29 -0
  127. mediapipe/framework/formats/__init__.py +0 -0
  128. mediapipe/framework/formats/affine_transform_data_pb2.py +28 -0
  129. mediapipe/framework/formats/annotation/__init__.py +0 -0
  130. mediapipe/framework/formats/annotation/locus_pb2.py +32 -0
  131. mediapipe/framework/formats/annotation/rasterization_pb2.py +29 -0
  132. mediapipe/framework/formats/body_rig_pb2.py +28 -0
  133. mediapipe/framework/formats/classification_pb2.py +31 -0
  134. mediapipe/framework/formats/detection_pb2.py +36 -0
  135. mediapipe/framework/formats/image_file_properties_pb2.py +26 -0
  136. mediapipe/framework/formats/image_format_pb2.py +29 -0
  137. mediapipe/framework/formats/landmark_pb2.py +37 -0
  138. mediapipe/framework/formats/location_data_pb2.py +38 -0
  139. mediapipe/framework/formats/matrix_data_pb2.py +31 -0
  140. mediapipe/framework/formats/motion/__init__.py +0 -0
  141. mediapipe/framework/formats/motion/optical_flow_field_data_pb2.py +30 -0
  142. mediapipe/framework/formats/object_detection/__init__.py +0 -0
  143. mediapipe/framework/formats/object_detection/anchor_pb2.py +26 -0
  144. mediapipe/framework/formats/rect_pb2.py +29 -0
  145. mediapipe/framework/formats/time_series_header_pb2.py +28 -0
  146. mediapipe/framework/graph_runtime_info_pb2.py +31 -0
  147. mediapipe/framework/mediapipe_options_pb2.py +27 -0
  148. mediapipe/framework/packet_factory_pb2.py +31 -0
  149. mediapipe/framework/packet_generator_pb2.py +33 -0
  150. mediapipe/framework/status_handler_pb2.py +28 -0
  151. mediapipe/framework/stream_handler/__init__.py +0 -0
  152. mediapipe/framework/stream_handler/default_input_stream_handler_pb2.py +27 -0
  153. mediapipe/framework/stream_handler/fixed_size_input_stream_handler_pb2.py +27 -0
  154. mediapipe/framework/stream_handler/sync_set_input_stream_handler_pb2.py +29 -0
  155. mediapipe/framework/stream_handler/timestamp_align_input_stream_handler_pb2.py +27 -0
  156. mediapipe/framework/stream_handler_pb2.py +30 -0
  157. mediapipe/framework/test_calculators_pb2.py +31 -0
  158. mediapipe/framework/thread_pool_executor_pb2.py +29 -0
  159. mediapipe/framework/tool/__init__.py +0 -0
  160. mediapipe/framework/tool/calculator_graph_template_pb2.py +44 -0
  161. mediapipe/framework/tool/field_data_pb2.py +28 -0
  162. mediapipe/framework/tool/node_chain_subgraph_pb2.py +31 -0
  163. mediapipe/framework/tool/packet_generator_wrapper_calculator_pb2.py +28 -0
  164. mediapipe/framework/tool/source_pb2.py +33 -0
  165. mediapipe/framework/tool/switch_container_pb2.py +32 -0
  166. mediapipe/gpu/__init__.py +0 -0
  167. mediapipe/gpu/copy_calculator_pb2.py +33 -0
  168. mediapipe/gpu/gl_animation_overlay_calculator_pb2.py +31 -0
  169. mediapipe/gpu/gl_context_options_pb2.py +31 -0
  170. mediapipe/gpu/gl_scaler_calculator_pb2.py +32 -0
  171. mediapipe/gpu/gl_surface_sink_calculator_pb2.py +32 -0
  172. mediapipe/gpu/gpu_origin_pb2.py +29 -0
  173. mediapipe/gpu/scale_mode_pb2.py +28 -0
  174. mediapipe/model_maker/__init__.py +27 -0
  175. mediapipe/model_maker/setup.py +107 -0
  176. mediapipe/modules/__init__.py +0 -0
  177. mediapipe/modules/face_detection/__init__.py +0 -0
  178. mediapipe/modules/face_detection/face_detection_full_range_cpu.binarypb +0 -0
  179. mediapipe/modules/face_detection/face_detection_full_range_sparse.tflite +0 -0
  180. mediapipe/modules/face_detection/face_detection_pb2.py +30 -0
  181. mediapipe/modules/face_detection/face_detection_short_range.tflite +0 -0
  182. mediapipe/modules/face_detection/face_detection_short_range_cpu.binarypb +0 -0
  183. mediapipe/modules/face_geometry/__init__.py +0 -0
  184. mediapipe/modules/face_geometry/data/__init__.py +0 -0
  185. mediapipe/modules/face_geometry/effect_renderer_calculator_pb2.py +27 -0
  186. mediapipe/modules/face_geometry/env_generator_calculator_pb2.py +28 -0
  187. mediapipe/modules/face_geometry/geometry_pipeline_calculator_pb2.py +27 -0
  188. mediapipe/modules/face_geometry/libs/__init__.py +0 -0
  189. mediapipe/modules/face_geometry/protos/__init__.py +0 -0
  190. mediapipe/modules/face_geometry/protos/environment_pb2.py +31 -0
  191. mediapipe/modules/face_geometry/protos/face_geometry_pb2.py +29 -0
  192. mediapipe/modules/face_geometry/protos/geometry_pipeline_metadata_pb2.py +32 -0
  193. mediapipe/modules/face_geometry/protos/mesh_3d_pb2.py +31 -0
  194. mediapipe/modules/face_landmark/__init__.py +0 -0
  195. mediapipe/modules/face_landmark/face_landmark.tflite +0 -0
  196. mediapipe/modules/face_landmark/face_landmark_front_cpu.binarypb +0 -0
  197. mediapipe/modules/face_landmark/face_landmark_with_attention.tflite +0 -0
  198. mediapipe/modules/hand_landmark/__init__.py +0 -0
  199. mediapipe/modules/hand_landmark/calculators/__init__.py +0 -0
  200. mediapipe/modules/hand_landmark/hand_landmark_full.tflite +0 -0
  201. mediapipe/modules/hand_landmark/hand_landmark_lite.tflite +0 -0
  202. mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb +0 -0
  203. mediapipe/modules/hand_landmark/handedness.txt +2 -0
  204. mediapipe/modules/holistic_landmark/__init__.py +0 -0
  205. mediapipe/modules/holistic_landmark/calculators/__init__.py +0 -0
  206. mediapipe/modules/holistic_landmark/calculators/roi_tracking_calculator_pb2.py +37 -0
  207. mediapipe/modules/holistic_landmark/hand_recrop.tflite +0 -0
  208. mediapipe/modules/holistic_landmark/holistic_landmark_cpu.binarypb +0 -0
  209. mediapipe/modules/iris_landmark/__init__.py +0 -0
  210. mediapipe/modules/iris_landmark/iris_landmark.tflite +0 -0
  211. mediapipe/modules/objectron/__init__.py +0 -0
  212. mediapipe/modules/objectron/calculators/__init__.py +0 -0
  213. mediapipe/modules/objectron/calculators/a_r_capture_metadata_pb2.py +102 -0
  214. mediapipe/modules/objectron/calculators/annotation_data_pb2.py +38 -0
  215. mediapipe/modules/objectron/calculators/belief_decoder_config_pb2.py +28 -0
  216. mediapipe/modules/objectron/calculators/camera_parameters_pb2.py +30 -0
  217. mediapipe/modules/objectron/calculators/filter_detection_calculator_pb2.py +35 -0
  218. mediapipe/modules/objectron/calculators/frame_annotation_to_rect_calculator_pb2.py +31 -0
  219. mediapipe/modules/objectron/calculators/frame_annotation_tracker_calculator_pb2.py +31 -0
  220. mediapipe/modules/objectron/calculators/lift_2d_frame_annotation_to_3d_calculator_pb2.py +32 -0
  221. mediapipe/modules/objectron/calculators/object_pb2.py +38 -0
  222. mediapipe/modules/objectron/calculators/tensors_to_objects_calculator_pb2.py +32 -0
  223. mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator_pb2.py +32 -0
  224. mediapipe/modules/objectron/object_detection_oidv4_labelmap.txt +24 -0
  225. mediapipe/modules/objectron/objectron_cpu.binarypb +0 -0
  226. mediapipe/modules/palm_detection/__init__.py +0 -0
  227. mediapipe/modules/palm_detection/palm_detection_full.tflite +0 -0
  228. mediapipe/modules/palm_detection/palm_detection_lite.tflite +0 -0
  229. mediapipe/modules/pose_detection/__init__.py +0 -0
  230. mediapipe/modules/pose_detection/pose_detection.tflite +0 -0
  231. mediapipe/modules/pose_landmark/__init__.py +0 -0
  232. mediapipe/modules/pose_landmark/pose_landmark_cpu.binarypb +0 -0
  233. mediapipe/modules/pose_landmark/pose_landmark_full.tflite +0 -0
  234. mediapipe/modules/selfie_segmentation/__init__.py +0 -0
  235. mediapipe/modules/selfie_segmentation/selfie_segmentation.tflite +0 -0
  236. mediapipe/modules/selfie_segmentation/selfie_segmentation_cpu.binarypb +0 -0
  237. mediapipe/modules/selfie_segmentation/selfie_segmentation_landscape.tflite +0 -0
  238. mediapipe/python/__init__.py +29 -0
  239. mediapipe/python/_framework_bindings.cpython-39-x86_64-linux-gnu.so +0 -0
  240. mediapipe/python/calculator_graph_test.py +251 -0
  241. mediapipe/python/image_frame_test.py +194 -0
  242. mediapipe/python/image_test.py +218 -0
  243. mediapipe/python/packet_creator.py +275 -0
  244. mediapipe/python/packet_getter.py +120 -0
  245. mediapipe/python/packet_test.py +533 -0
  246. mediapipe/python/solution_base.py +604 -0
  247. mediapipe/python/solution_base_test.py +396 -0
  248. mediapipe/python/solutions/__init__.py +27 -0
  249. mediapipe/python/solutions/download_utils.py +37 -0
  250. mediapipe/python/solutions/drawing_styles.py +249 -0
  251. mediapipe/python/solutions/drawing_utils.py +320 -0
  252. mediapipe/python/solutions/drawing_utils_test.py +258 -0
  253. mediapipe/python/solutions/face_detection.py +105 -0
  254. mediapipe/python/solutions/face_detection_test.py +92 -0
  255. mediapipe/python/solutions/face_mesh.py +125 -0
  256. mediapipe/python/solutions/face_mesh_connections.py +500 -0
  257. mediapipe/python/solutions/face_mesh_test.py +170 -0
  258. mediapipe/python/solutions/hands.py +153 -0
  259. mediapipe/python/solutions/hands_connections.py +32 -0
  260. mediapipe/python/solutions/hands_test.py +219 -0
  261. mediapipe/python/solutions/holistic.py +167 -0
  262. mediapipe/python/solutions/holistic_test.py +142 -0
  263. mediapipe/python/solutions/objectron.py +288 -0
  264. mediapipe/python/solutions/objectron_test.py +81 -0
  265. mediapipe/python/solutions/pose.py +192 -0
  266. mediapipe/python/solutions/pose_connections.py +22 -0
  267. mediapipe/python/solutions/pose_test.py +262 -0
  268. mediapipe/python/solutions/selfie_segmentation.py +76 -0
  269. mediapipe/python/solutions/selfie_segmentation_test.py +68 -0
  270. mediapipe/python/timestamp_test.py +78 -0
  271. mediapipe/tasks/__init__.py +14 -0
  272. mediapipe/tasks/cc/__init__.py +0 -0
  273. mediapipe/tasks/cc/audio/__init__.py +0 -0
  274. mediapipe/tasks/cc/audio/audio_classifier/__init__.py +0 -0
  275. mediapipe/tasks/cc/audio/audio_classifier/proto/__init__.py +0 -0
  276. mediapipe/tasks/cc/audio/audio_classifier/proto/audio_classifier_graph_options_pb2.py +35 -0
  277. mediapipe/tasks/cc/audio/audio_embedder/__init__.py +0 -0
  278. mediapipe/tasks/cc/audio/audio_embedder/proto/__init__.py +0 -0
  279. mediapipe/tasks/cc/audio/audio_embedder/proto/audio_embedder_graph_options_pb2.py +35 -0
  280. mediapipe/tasks/cc/audio/core/__init__.py +0 -0
  281. mediapipe/tasks/cc/audio/utils/__init__.py +0 -0
  282. mediapipe/tasks/cc/components/__init__.py +0 -0
  283. mediapipe/tasks/cc/components/calculators/__init__.py +0 -0
  284. mediapipe/tasks/cc/components/calculators/classification_aggregation_calculator_pb2.py +31 -0
  285. mediapipe/tasks/cc/components/calculators/score_calibration_calculator_pb2.py +35 -0
  286. mediapipe/tasks/cc/components/calculators/tensors_to_embeddings_calculator_pb2.py +32 -0
  287. mediapipe/tasks/cc/components/containers/__init__.py +0 -0
  288. mediapipe/tasks/cc/components/containers/proto/__init__.py +0 -0
  289. mediapipe/tasks/cc/components/containers/proto/classifications_pb2.py +30 -0
  290. mediapipe/tasks/cc/components/containers/proto/embeddings_pb2.py +35 -0
  291. mediapipe/tasks/cc/components/containers/proto/landmarks_detection_result_pb2.py +32 -0
  292. mediapipe/tasks/cc/components/processors/__init__.py +0 -0
  293. mediapipe/tasks/cc/components/processors/proto/__init__.py +0 -0
  294. mediapipe/tasks/cc/components/processors/proto/classification_postprocessing_graph_options_pb2.py +38 -0
  295. mediapipe/tasks/cc/components/processors/proto/classifier_options_pb2.py +27 -0
  296. mediapipe/tasks/cc/components/processors/proto/detection_postprocessing_graph_options_pb2.py +36 -0
  297. mediapipe/tasks/cc/components/processors/proto/detector_options_pb2.py +27 -0
  298. mediapipe/tasks/cc/components/processors/proto/embedder_options_pb2.py +27 -0
  299. mediapipe/tasks/cc/components/processors/proto/embedding_postprocessing_graph_options_pb2.py +32 -0
  300. mediapipe/tasks/cc/components/processors/proto/image_preprocessing_graph_options_pb2.py +34 -0
  301. mediapipe/tasks/cc/components/processors/proto/text_model_type_pb2.py +28 -0
  302. mediapipe/tasks/cc/components/processors/proto/text_preprocessing_graph_options_pb2.py +32 -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 +28 -0
  307. mediapipe/tasks/cc/core/proto/base_options_pb2.py +30 -0
  308. mediapipe/tasks/cc/core/proto/external_file_pb2.py +31 -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/genai/__init__.py +0 -0
  312. mediapipe/tasks/cc/genai/inference/__init__.py +0 -0
  313. mediapipe/tasks/cc/genai/inference/c/__init__.py +0 -0
  314. mediapipe/tasks/cc/genai/inference/calculators/__init__.py +0 -0
  315. mediapipe/tasks/cc/genai/inference/calculators/detokenizer_calculator_pb2.py +27 -0
  316. mediapipe/tasks/cc/genai/inference/calculators/llm_gpu_calculator_pb2.py +32 -0
  317. mediapipe/tasks/cc/genai/inference/calculators/model_data_calculator_pb2.py +27 -0
  318. mediapipe/tasks/cc/genai/inference/calculators/tokenizer_calculator_pb2.py +29 -0
  319. mediapipe/tasks/cc/genai/inference/common/__init__.py +0 -0
  320. mediapipe/tasks/cc/genai/inference/proto/__init__.py +0 -0
  321. mediapipe/tasks/cc/genai/inference/proto/llm_file_metadata_pb2.py +32 -0
  322. mediapipe/tasks/cc/genai/inference/proto/llm_params_pb2.py +33 -0
  323. mediapipe/tasks/cc/genai/inference/proto/prompt_template_pb2.py +27 -0
  324. mediapipe/tasks/cc/genai/inference/proto/sampler_params_pb2.py +29 -0
  325. mediapipe/tasks/cc/genai/inference/proto/transformer_params_pb2.py +45 -0
  326. mediapipe/tasks/cc/genai/inference/utils/__init__.py +0 -0
  327. mediapipe/tasks/cc/genai/inference/utils/llm_utils/__init__.py +0 -0
  328. mediapipe/tasks/cc/genai/inference/utils/xnn_utils/__init__.py +0 -0
  329. mediapipe/tasks/cc/metadata/__init__.py +0 -0
  330. mediapipe/tasks/cc/metadata/python/__init__.py +0 -0
  331. mediapipe/tasks/cc/metadata/python/_pywrap_metadata_version.cpython-39-x86_64-linux-gnu.so +0 -0
  332. mediapipe/tasks/cc/metadata/tests/__init__.py +0 -0
  333. mediapipe/tasks/cc/metadata/utils/__init__.py +0 -0
  334. mediapipe/tasks/cc/text/__init__.py +0 -0
  335. mediapipe/tasks/cc/text/custom_ops/__init__.py +0 -0
  336. mediapipe/tasks/cc/text/custom_ops/ragged/__init__.py +0 -0
  337. mediapipe/tasks/cc/text/custom_ops/sentencepiece/__init__.py +0 -0
  338. mediapipe/tasks/cc/text/custom_ops/sentencepiece/testdata/__init__.py +0 -0
  339. mediapipe/tasks/cc/text/language_detector/__init__.py +0 -0
  340. mediapipe/tasks/cc/text/language_detector/custom_ops/__init__.py +0 -0
  341. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/__init__.py +0 -0
  342. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/hash/__init__.py +0 -0
  343. mediapipe/tasks/cc/text/language_detector/custom_ops/utils/utf/__init__.py +0 -0
  344. mediapipe/tasks/cc/text/text_classifier/__init__.py +0 -0
  345. mediapipe/tasks/cc/text/text_classifier/proto/__init__.py +0 -0
  346. mediapipe/tasks/cc/text/text_classifier/proto/text_classifier_graph_options_pb2.py +35 -0
  347. mediapipe/tasks/cc/text/text_embedder/__init__.py +0 -0
  348. mediapipe/tasks/cc/text/text_embedder/proto/__init__.py +0 -0
  349. mediapipe/tasks/cc/text/text_embedder/proto/text_embedder_graph_options_pb2.py +35 -0
  350. mediapipe/tasks/cc/text/tokenizers/__init__.py +0 -0
  351. mediapipe/tasks/cc/text/utils/__init__.py +0 -0
  352. mediapipe/tasks/cc/vision/__init__.py +0 -0
  353. mediapipe/tasks/cc/vision/core/__init__.py +0 -0
  354. mediapipe/tasks/cc/vision/custom_ops/__init__.py +0 -0
  355. mediapipe/tasks/cc/vision/face_detector/__init__.py +0 -0
  356. mediapipe/tasks/cc/vision/face_detector/proto/__init__.py +0 -0
  357. mediapipe/tasks/cc/vision/face_detector/proto/face_detector_graph_options_pb2.py +34 -0
  358. mediapipe/tasks/cc/vision/face_geometry/__init__.py +0 -0
  359. mediapipe/tasks/cc/vision/face_geometry/calculators/__init__.py +0 -0
  360. mediapipe/tasks/cc/vision/face_geometry/calculators/env_generator_calculator_pb2.py +28 -0
  361. mediapipe/tasks/cc/vision/face_geometry/calculators/geometry_pipeline_calculator_pb2.py +29 -0
  362. mediapipe/tasks/cc/vision/face_geometry/data/__init__.py +0 -0
  363. mediapipe/tasks/cc/vision/face_geometry/libs/__init__.py +0 -0
  364. mediapipe/tasks/cc/vision/face_geometry/proto/__init__.py +0 -0
  365. mediapipe/tasks/cc/vision/face_geometry/proto/environment_pb2.py +31 -0
  366. mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_graph_options_pb2.py +29 -0
  367. mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_pb2.py +29 -0
  368. mediapipe/tasks/cc/vision/face_geometry/proto/geometry_pipeline_metadata_pb2.py +32 -0
  369. mediapipe/tasks/cc/vision/face_geometry/proto/mesh_3d_pb2.py +31 -0
  370. mediapipe/tasks/cc/vision/face_landmarker/__init__.py +0 -0
  371. mediapipe/tasks/cc/vision/face_landmarker/proto/__init__.py +0 -0
  372. mediapipe/tasks/cc/vision/face_landmarker/proto/face_blendshapes_graph_options_pb2.py +34 -0
  373. mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarker_graph_options_pb2.py +37 -0
  374. mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarks_detector_graph_options_pb2.py +35 -0
  375. mediapipe/tasks/cc/vision/face_landmarker/proto/tensors_to_face_landmarks_graph_options_pb2.py +32 -0
  376. mediapipe/tasks/cc/vision/face_stylizer/__init__.py +0 -0
  377. mediapipe/tasks/cc/vision/face_stylizer/calculators/__init__.py +0 -0
  378. mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator_pb2.py +36 -0
  379. mediapipe/tasks/cc/vision/face_stylizer/proto/__init__.py +0 -0
  380. mediapipe/tasks/cc/vision/face_stylizer/proto/face_stylizer_graph_options_pb2.py +35 -0
  381. mediapipe/tasks/cc/vision/gesture_recognizer/__init__.py +0 -0
  382. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/__init__.py +0 -0
  383. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/combined_prediction_calculator_pb2.py +33 -0
  384. mediapipe/tasks/cc/vision/gesture_recognizer/calculators/landmarks_to_matrix_calculator_pb2.py +31 -0
  385. mediapipe/tasks/cc/vision/gesture_recognizer/proto/__init__.py +0 -0
  386. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_classifier_graph_options_pb2.py +35 -0
  387. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_embedder_graph_options_pb2.py +34 -0
  388. mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_recognizer_graph_options_pb2.py +36 -0
  389. mediapipe/tasks/cc/vision/gesture_recognizer/proto/hand_gesture_recognizer_graph_options_pb2.py +36 -0
  390. mediapipe/tasks/cc/vision/hand_detector/__init__.py +0 -0
  391. mediapipe/tasks/cc/vision/hand_detector/proto/__init__.py +0 -0
  392. mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options_pb2.py +34 -0
  393. mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_result_pb2.py +30 -0
  394. mediapipe/tasks/cc/vision/hand_landmarker/__init__.py +0 -0
  395. mediapipe/tasks/cc/vision/hand_landmarker/calculators/__init__.py +0 -0
  396. mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator_pb2.py +31 -0
  397. mediapipe/tasks/cc/vision/hand_landmarker/proto/__init__.py +0 -0
  398. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb2.py +36 -0
  399. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb2.py +34 -0
  400. mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_roi_refinement_graph_options_pb2.py +28 -0
  401. mediapipe/tasks/cc/vision/holistic_landmarker/__init__.py +0 -0
  402. mediapipe/tasks/cc/vision/holistic_landmarker/proto/__init__.py +0 -0
  403. mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_landmarker_graph_options_pb2.py +34 -0
  404. mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_result_pb2.py +29 -0
  405. mediapipe/tasks/cc/vision/image_classifier/__init__.py +0 -0
  406. mediapipe/tasks/cc/vision/image_classifier/proto/__init__.py +0 -0
  407. mediapipe/tasks/cc/vision/image_classifier/proto/image_classifier_graph_options_pb2.py +35 -0
  408. mediapipe/tasks/cc/vision/image_embedder/__init__.py +0 -0
  409. mediapipe/tasks/cc/vision/image_embedder/proto/__init__.py +0 -0
  410. mediapipe/tasks/cc/vision/image_embedder/proto/image_embedder_graph_options_pb2.py +35 -0
  411. mediapipe/tasks/cc/vision/image_generator/__init__.py +0 -0
  412. mediapipe/tasks/cc/vision/image_generator/diffuser/__init__.py +0 -0
  413. mediapipe/tasks/cc/vision/image_generator/diffuser/stable_diffusion_iterate_calculator_pb2.py +40 -0
  414. mediapipe/tasks/cc/vision/image_generator/proto/__init__.py +0 -0
  415. mediapipe/tasks/cc/vision/image_generator/proto/conditioned_image_graph_options_pb2.py +40 -0
  416. mediapipe/tasks/cc/vision/image_generator/proto/control_plugin_graph_options_pb2.py +34 -0
  417. mediapipe/tasks/cc/vision/image_generator/proto/image_generator_graph_options_pb2.py +30 -0
  418. mediapipe/tasks/cc/vision/image_segmenter/__init__.py +0 -0
  419. mediapipe/tasks/cc/vision/image_segmenter/calculators/__init__.py +0 -0
  420. mediapipe/tasks/cc/vision/image_segmenter/calculators/tensors_to_segmentation_calculator_pb2.py +34 -0
  421. mediapipe/tasks/cc/vision/image_segmenter/proto/__init__.py +0 -0
  422. mediapipe/tasks/cc/vision/image_segmenter/proto/image_segmenter_graph_options_pb2.py +35 -0
  423. mediapipe/tasks/cc/vision/image_segmenter/proto/segmenter_options_pb2.py +33 -0
  424. mediapipe/tasks/cc/vision/interactive_segmenter/__init__.py +0 -0
  425. mediapipe/tasks/cc/vision/object_detector/__init__.py +0 -0
  426. mediapipe/tasks/cc/vision/object_detector/proto/__init__.py +0 -0
  427. mediapipe/tasks/cc/vision/object_detector/proto/object_detector_options_pb2.py +34 -0
  428. mediapipe/tasks/cc/vision/pose_detector/__init__.py +0 -0
  429. mediapipe/tasks/cc/vision/pose_detector/proto/__init__.py +0 -0
  430. mediapipe/tasks/cc/vision/pose_detector/proto/pose_detector_graph_options_pb2.py +34 -0
  431. mediapipe/tasks/cc/vision/pose_landmarker/__init__.py +0 -0
  432. mediapipe/tasks/cc/vision/pose_landmarker/proto/__init__.py +0 -0
  433. mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarker_graph_options_pb2.py +36 -0
  434. mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarks_detector_graph_options_pb2.py +34 -0
  435. mediapipe/tasks/cc/vision/utils/__init__.py +0 -0
  436. mediapipe/tasks/cc/vision/utils/ghum/__init__.py +0 -0
  437. mediapipe/tasks/metadata/image_segmenter_metadata_schema.fbs +59 -0
  438. mediapipe/tasks/metadata/image_segmenter_metadata_schema_py_generated.py +108 -0
  439. mediapipe/tasks/metadata/metadata_schema.fbs +732 -0
  440. mediapipe/tasks/metadata/metadata_schema_py_generated.py +3251 -0
  441. mediapipe/tasks/metadata/object_detector_metadata_schema.fbs +98 -0
  442. mediapipe/tasks/metadata/object_detector_metadata_schema_py_generated.py +674 -0
  443. mediapipe/tasks/metadata/schema_py_generated.py +18438 -0
  444. mediapipe/tasks/python/__init__.py +27 -0
  445. mediapipe/tasks/python/audio/__init__.py +33 -0
  446. mediapipe/tasks/python/audio/audio_classifier.py +324 -0
  447. mediapipe/tasks/python/audio/audio_embedder.py +285 -0
  448. mediapipe/tasks/python/audio/core/__init__.py +16 -0
  449. mediapipe/tasks/python/audio/core/audio_record.py +125 -0
  450. mediapipe/tasks/python/audio/core/audio_task_running_mode.py +29 -0
  451. mediapipe/tasks/python/audio/core/base_audio_task_api.py +181 -0
  452. mediapipe/tasks/python/benchmark/__init__.py +13 -0
  453. mediapipe/tasks/python/benchmark/benchmark_utils.py +70 -0
  454. mediapipe/tasks/python/benchmark/vision/__init__.py +13 -0
  455. mediapipe/tasks/python/benchmark/vision/benchmark.py +99 -0
  456. mediapipe/tasks/python/benchmark/vision/core/__init__.py +14 -0
  457. mediapipe/tasks/python/benchmark/vision/core/base_vision_benchmark_api.py +40 -0
  458. mediapipe/tasks/python/components/__init__.py +13 -0
  459. mediapipe/tasks/python/components/containers/__init__.py +53 -0
  460. mediapipe/tasks/python/components/containers/audio_data.py +137 -0
  461. mediapipe/tasks/python/components/containers/bounding_box.py +73 -0
  462. mediapipe/tasks/python/components/containers/category.py +78 -0
  463. mediapipe/tasks/python/components/containers/classification_result.py +111 -0
  464. mediapipe/tasks/python/components/containers/detections.py +181 -0
  465. mediapipe/tasks/python/components/containers/embedding_result.py +89 -0
  466. mediapipe/tasks/python/components/containers/keypoint.py +77 -0
  467. mediapipe/tasks/python/components/containers/landmark.py +122 -0
  468. mediapipe/tasks/python/components/containers/landmark_detection_result.py +106 -0
  469. mediapipe/tasks/python/components/containers/rect.py +109 -0
  470. mediapipe/tasks/python/components/processors/__init__.py +23 -0
  471. mediapipe/tasks/python/components/processors/classifier_options.py +86 -0
  472. mediapipe/tasks/python/components/utils/__init__.py +13 -0
  473. mediapipe/tasks/python/components/utils/cosine_similarity.py +68 -0
  474. mediapipe/tasks/python/core/__init__.py +13 -0
  475. mediapipe/tasks/python/core/base_options.py +121 -0
  476. mediapipe/tasks/python/core/optional_dependencies.py +25 -0
  477. mediapipe/tasks/python/core/task_info.py +139 -0
  478. mediapipe/tasks/python/genai/__init__.py +14 -0
  479. mediapipe/tasks/python/genai/bundler/__init__.py +23 -0
  480. mediapipe/tasks/python/genai/bundler/llm_bundler.py +130 -0
  481. mediapipe/tasks/python/genai/bundler/llm_bundler_test.py +168 -0
  482. mediapipe/tasks/python/genai/converter/__init__.py +24 -0
  483. mediapipe/tasks/python/genai/converter/converter_base.py +179 -0
  484. mediapipe/tasks/python/genai/converter/converter_factory.py +79 -0
  485. mediapipe/tasks/python/genai/converter/llm_converter.py +374 -0
  486. mediapipe/tasks/python/genai/converter/llm_converter_test.py +63 -0
  487. mediapipe/tasks/python/genai/converter/pytorch_converter.py +318 -0
  488. mediapipe/tasks/python/genai/converter/pytorch_converter_test.py +86 -0
  489. mediapipe/tasks/python/genai/converter/quantization_util.py +516 -0
  490. mediapipe/tasks/python/genai/converter/quantization_util_test.py +259 -0
  491. mediapipe/tasks/python/genai/converter/safetensors_converter.py +580 -0
  492. mediapipe/tasks/python/genai/converter/safetensors_converter_test.py +83 -0
  493. mediapipe/tasks/python/genai/converter/weight_bins_writer.py +120 -0
  494. mediapipe/tasks/python/genai/converter/weight_bins_writer_test.py +95 -0
  495. mediapipe/tasks/python/metadata/__init__.py +13 -0
  496. mediapipe/tasks/python/metadata/flatbuffers_lib/_pywrap_flatbuffers.cpython-39-x86_64-linux-gnu.so +0 -0
  497. mediapipe/tasks/python/metadata/metadata.py +928 -0
  498. mediapipe/tasks/python/metadata/metadata_displayer_cli.py +34 -0
  499. mediapipe/tasks/python/metadata/metadata_writers/__init__.py +13 -0
  500. mediapipe/tasks/python/metadata/metadata_writers/face_stylizer.py +138 -0
  501. mediapipe/tasks/python/metadata/metadata_writers/image_classifier.py +71 -0
  502. mediapipe/tasks/python/metadata/metadata_writers/image_segmenter.py +170 -0
  503. mediapipe/tasks/python/metadata/metadata_writers/metadata_info.py +1166 -0
  504. mediapipe/tasks/python/metadata/metadata_writers/metadata_writer.py +845 -0
  505. mediapipe/tasks/python/metadata/metadata_writers/model_asset_bundle_utils.py +71 -0
  506. mediapipe/tasks/python/metadata/metadata_writers/object_detector.py +331 -0
  507. mediapipe/tasks/python/metadata/metadata_writers/text_classifier.py +119 -0
  508. mediapipe/tasks/python/metadata/metadata_writers/writer_utils.py +91 -0
  509. mediapipe/tasks/python/test/__init__.py +13 -0
  510. mediapipe/tasks/python/test/audio/__init__.py +13 -0
  511. mediapipe/tasks/python/test/audio/audio_classifier_test.py +387 -0
  512. mediapipe/tasks/python/test/audio/audio_embedder_test.py +297 -0
  513. mediapipe/tasks/python/test/test_utils.py +196 -0
  514. mediapipe/tasks/python/test/text/__init__.py +13 -0
  515. mediapipe/tasks/python/test/text/language_detector_test.py +228 -0
  516. mediapipe/tasks/python/test/text/text_classifier_test.py +235 -0
  517. mediapipe/tasks/python/test/text/text_embedder_test.py +326 -0
  518. mediapipe/tasks/python/test/vision/__init__.py +13 -0
  519. mediapipe/tasks/python/test/vision/face_aligner_test.py +190 -0
  520. mediapipe/tasks/python/test/vision/face_detector_test.py +523 -0
  521. mediapipe/tasks/python/test/vision/face_landmarker_test.py +565 -0
  522. mediapipe/tasks/python/test/vision/face_stylizer_test.py +191 -0
  523. mediapipe/tasks/python/test/vision/hand_landmarker_test.py +437 -0
  524. mediapipe/tasks/python/test/vision/holistic_landmarker_test.py +544 -0
  525. mediapipe/tasks/python/test/vision/image_classifier_test.py +657 -0
  526. mediapipe/tasks/python/test/vision/image_embedder_test.py +423 -0
  527. mediapipe/tasks/python/test/vision/image_segmenter_test.py +512 -0
  528. mediapipe/tasks/python/test/vision/interactive_segmenter_test.py +341 -0
  529. mediapipe/tasks/python/test/vision/object_detector_test.py +493 -0
  530. mediapipe/tasks/python/test/vision/pose_landmarker_test.py +518 -0
  531. mediapipe/tasks/python/text/__init__.py +35 -0
  532. mediapipe/tasks/python/text/core/__init__.py +16 -0
  533. mediapipe/tasks/python/text/core/base_text_task_api.py +54 -0
  534. mediapipe/tasks/python/text/language_detector.py +220 -0
  535. mediapipe/tasks/python/text/text_classifier.py +187 -0
  536. mediapipe/tasks/python/text/text_embedder.py +188 -0
  537. mediapipe/tasks/python/vision/__init__.py +90 -0
  538. mediapipe/tasks/python/vision/core/__init__.py +14 -0
  539. mediapipe/tasks/python/vision/core/base_vision_task_api.py +226 -0
  540. mediapipe/tasks/python/vision/core/image_processing_options.py +39 -0
  541. mediapipe/tasks/python/vision/core/vision_task_running_mode.py +31 -0
  542. mediapipe/tasks/python/vision/face_aligner.py +158 -0
  543. mediapipe/tasks/python/vision/face_detector.py +332 -0
  544. mediapipe/tasks/python/vision/face_landmarker.py +3244 -0
  545. mediapipe/tasks/python/vision/face_stylizer.py +158 -0
  546. mediapipe/tasks/python/vision/gesture_recognizer.py +480 -0
  547. mediapipe/tasks/python/vision/hand_landmarker.py +504 -0
  548. mediapipe/tasks/python/vision/holistic_landmarker.py +576 -0
  549. mediapipe/tasks/python/vision/image_classifier.py +358 -0
  550. mediapipe/tasks/python/vision/image_embedder.py +362 -0
  551. mediapipe/tasks/python/vision/image_segmenter.py +433 -0
  552. mediapipe/tasks/python/vision/interactive_segmenter.py +285 -0
  553. mediapipe/tasks/python/vision/object_detector.py +389 -0
  554. mediapipe/tasks/python/vision/pose_landmarker.py +455 -0
  555. mediapipe/util/__init__.py +0 -0
  556. mediapipe/util/analytics/__init__.py +0 -0
  557. mediapipe/util/analytics/mediapipe_log_extension_pb2.py +44 -0
  558. mediapipe/util/analytics/mediapipe_logging_enums_pb2.py +37 -0
  559. mediapipe/util/audio_decoder_pb2.py +33 -0
  560. mediapipe/util/color_pb2.py +33 -0
  561. mediapipe/util/label_map_pb2.py +27 -0
  562. mediapipe/util/render_data_pb2.py +58 -0
  563. mediapipe/util/sequence/__init__.py +14 -0
  564. mediapipe/util/sequence/media_sequence.py +716 -0
  565. mediapipe/util/sequence/media_sequence_test.py +290 -0
  566. mediapipe/util/sequence/media_sequence_util.py +800 -0
  567. mediapipe/util/sequence/media_sequence_util_test.py +389 -0
  568. mediapipe/util/tracking/__init__.py +0 -0
  569. mediapipe/util/tracking/box_detector_pb2.py +39 -0
  570. mediapipe/util/tracking/box_tracker_pb2.py +32 -0
  571. mediapipe/util/tracking/camera_motion_pb2.py +31 -0
  572. mediapipe/util/tracking/flow_packager_pb2.py +60 -0
  573. mediapipe/util/tracking/frame_selection_pb2.py +35 -0
  574. mediapipe/util/tracking/frame_selection_solution_evaluator_pb2.py +28 -0
  575. mediapipe/util/tracking/motion_analysis_pb2.py +35 -0
  576. mediapipe/util/tracking/motion_estimation_pb2.py +66 -0
  577. mediapipe/util/tracking/motion_models_pb2.py +42 -0
  578. mediapipe/util/tracking/motion_saliency_pb2.py +26 -0
  579. mediapipe/util/tracking/push_pull_filtering_pb2.py +26 -0
  580. mediapipe/util/tracking/region_flow_computation_pb2.py +59 -0
  581. mediapipe/util/tracking/region_flow_pb2.py +49 -0
  582. mediapipe/util/tracking/tone_estimation_pb2.py +45 -0
  583. mediapipe/util/tracking/tone_models_pb2.py +32 -0
  584. mediapipe/util/tracking/tracked_detection_manager_config_pb2.py +26 -0
  585. mediapipe/util/tracking/tracking_pb2.py +73 -0
  586. mediapipe_nightly-0.10.21.post20250114.dist-info/LICENSE +218 -0
  587. mediapipe_nightly-0.10.21.post20250114.dist-info/METADATA +199 -0
  588. mediapipe_nightly-0.10.21.post20250114.dist-info/RECORD +593 -0
  589. mediapipe_nightly-0.10.21.post20250114.dist-info/WHEEL +5 -0
  590. mediapipe_nightly-0.10.21.post20250114.dist-info/top_level.txt +4 -0
  591. mediapipe_nightly.libs/libEGL-48f73270.so.1.1.0 +0 -0
  592. mediapipe_nightly.libs/libGLESv2-ed5eda4f.so.2.1.0 +0 -0
  593. mediapipe_nightly.libs/libGLdispatch-64b28464.so.0.0.0 +0 -0
@@ -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()