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.
- mediapipe/__init__.py +26 -0
- mediapipe/calculators/__init__.py +0 -0
- mediapipe/calculators/audio/__init__.py +0 -0
- mediapipe/calculators/audio/mfcc_mel_calculators_pb2.py +33 -0
- mediapipe/calculators/audio/rational_factor_resample_calculator_pb2.py +33 -0
- mediapipe/calculators/audio/spectrogram_calculator_pb2.py +37 -0
- mediapipe/calculators/audio/stabilized_log_calculator_pb2.py +31 -0
- mediapipe/calculators/audio/time_series_framer_calculator_pb2.py +33 -0
- mediapipe/calculators/core/__init__.py +0 -0
- mediapipe/calculators/core/bypass_calculator_pb2.py +31 -0
- mediapipe/calculators/core/clip_vector_size_calculator_pb2.py +31 -0
- mediapipe/calculators/core/concatenate_vector_calculator_pb2.py +31 -0
- mediapipe/calculators/core/constant_side_packet_calculator_pb2.py +39 -0
- mediapipe/calculators/core/dequantize_byte_array_calculator_pb2.py +31 -0
- mediapipe/calculators/core/flow_limiter_calculator_pb2.py +32 -0
- mediapipe/calculators/core/gate_calculator_pb2.py +33 -0
- mediapipe/calculators/core/get_vector_item_calculator_pb2.py +31 -0
- mediapipe/calculators/core/graph_profile_calculator_pb2.py +31 -0
- mediapipe/calculators/core/packet_cloner_calculator_pb2.py +31 -0
- mediapipe/calculators/core/packet_resampler_calculator_pb2.py +33 -0
- mediapipe/calculators/core/packet_thinner_calculator_pb2.py +33 -0
- mediapipe/calculators/core/quantize_float_vector_calculator_pb2.py +31 -0
- mediapipe/calculators/core/sequence_shift_calculator_pb2.py +31 -0
- mediapipe/calculators/core/split_vector_calculator_pb2.py +33 -0
- mediapipe/calculators/image/__init__.py +0 -0
- mediapipe/calculators/image/bilateral_filter_calculator_pb2.py +31 -0
- mediapipe/calculators/image/feature_detector_calculator_pb2.py +31 -0
- mediapipe/calculators/image/image_clone_calculator_pb2.py +31 -0
- mediapipe/calculators/image/image_cropping_calculator_pb2.py +33 -0
- mediapipe/calculators/image/image_transformation_calculator_pb2.py +38 -0
- mediapipe/calculators/image/mask_overlay_calculator_pb2.py +33 -0
- mediapipe/calculators/image/opencv_encoded_image_to_image_frame_calculator_pb2.py +31 -0
- mediapipe/calculators/image/opencv_image_encoder_calculator_pb2.py +35 -0
- mediapipe/calculators/image/recolor_calculator_pb2.py +34 -0
- mediapipe/calculators/image/rotation_mode_pb2.py +29 -0
- mediapipe/calculators/image/scale_image_calculator_pb2.py +34 -0
- mediapipe/calculators/image/segmentation_smoothing_calculator_pb2.py +31 -0
- mediapipe/calculators/image/set_alpha_calculator_pb2.py +31 -0
- mediapipe/calculators/image/warp_affine_calculator_pb2.py +36 -0
- mediapipe/calculators/internal/__init__.py +0 -0
- mediapipe/calculators/internal/callback_packet_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/__init__.py +0 -0
- mediapipe/calculators/tensor/audio_to_tensor_calculator_pb2.py +35 -0
- mediapipe/calculators/tensor/bert_preprocessor_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/feedback_tensors_calculator_pb2.py +37 -0
- mediapipe/calculators/tensor/image_to_tensor_calculator_pb2.py +40 -0
- mediapipe/calculators/tensor/inference_calculator_pb2.py +63 -0
- mediapipe/calculators/tensor/landmarks_to_tensor_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/regex_preprocessor_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/tensor_converter_calculator_pb2.py +34 -0
- mediapipe/calculators/tensor/tensor_to_joints_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/tensors_readback_calculator_pb2.py +35 -0
- mediapipe/calculators/tensor/tensors_to_audio_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_classification_calculator_pb2.py +44 -0
- mediapipe/calculators/tensor/tensors_to_detections_calculator_pb2.py +39 -0
- mediapipe/calculators/tensor/tensors_to_floats_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_landmarks_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_segmentation_calculator_pb2.py +34 -0
- mediapipe/calculators/tensor/vector_to_tensor_calculator_pb2.py +27 -0
- mediapipe/calculators/tflite/__init__.py +0 -0
- mediapipe/calculators/tflite/ssd_anchors_calculator_pb2.py +32 -0
- mediapipe/calculators/tflite/tflite_converter_calculator_pb2.py +33 -0
- mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_inference_calculator_pb2.py +49 -0
- mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator_pb2.py +33 -0
- mediapipe/calculators/tflite/tflite_tensors_to_segmentation_calculator_pb2.py +31 -0
- mediapipe/calculators/util/__init__.py +0 -0
- mediapipe/calculators/util/align_hand_to_pose_in_world_calculator_pb2.py +31 -0
- mediapipe/calculators/util/annotation_overlay_calculator_pb2.py +32 -0
- mediapipe/calculators/util/association_calculator_pb2.py +31 -0
- mediapipe/calculators/util/collection_has_min_size_calculator_pb2.py +31 -0
- mediapipe/calculators/util/combine_joints_calculator_pb2.py +36 -0
- mediapipe/calculators/util/detection_label_id_to_text_calculator_pb2.py +36 -0
- mediapipe/calculators/util/detections_to_rects_calculator_pb2.py +33 -0
- mediapipe/calculators/util/detections_to_render_data_calculator_pb2.py +33 -0
- mediapipe/calculators/util/face_to_rect_calculator_pb2.py +26 -0
- mediapipe/calculators/util/filter_detections_calculator_pb2.py +31 -0
- mediapipe/calculators/util/flat_color_image_calculator_pb2.py +32 -0
- mediapipe/calculators/util/labels_to_render_data_calculator_pb2.py +34 -0
- mediapipe/calculators/util/landmark_projection_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_refinement_calculator_pb2.py +41 -0
- mediapipe/calculators/util/landmarks_smoothing_calculator_pb2.py +33 -0
- mediapipe/calculators/util/landmarks_to_detection_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_to_floats_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/landmarks_transformation_calculator_pb2.py +37 -0
- mediapipe/calculators/util/latency_pb2.py +26 -0
- mediapipe/calculators/util/local_file_contents_calculator_pb2.py +31 -0
- mediapipe/calculators/util/logic_calculator_pb2.py +34 -0
- mediapipe/calculators/util/non_max_suppression_calculator_pb2.py +35 -0
- mediapipe/calculators/util/packet_frequency_calculator_pb2.py +31 -0
- mediapipe/calculators/util/packet_frequency_pb2.py +26 -0
- mediapipe/calculators/util/packet_latency_calculator_pb2.py +31 -0
- mediapipe/calculators/util/rect_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/rect_to_render_scale_calculator_pb2.py +31 -0
- mediapipe/calculators/util/rect_transformation_calculator_pb2.py +31 -0
- mediapipe/calculators/util/refine_landmarks_from_heatmap_calculator_pb2.py +31 -0
- mediapipe/calculators/util/resource_provider_calculator_pb2.py +28 -0
- mediapipe/calculators/util/set_joints_visibility_calculator_pb2.py +41 -0
- mediapipe/calculators/util/thresholding_calculator_pb2.py +31 -0
- mediapipe/calculators/util/timed_box_list_id_to_label_calculator_pb2.py +31 -0
- mediapipe/calculators/util/timed_box_list_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/top_k_scores_calculator_pb2.py +31 -0
- mediapipe/calculators/util/visibility_copy_calculator_pb2.py +27 -0
- mediapipe/calculators/util/visibility_smoothing_calculator_pb2.py +31 -0
- mediapipe/calculators/video/__init__.py +0 -0
- mediapipe/calculators/video/box_detector_calculator_pb2.py +32 -0
- mediapipe/calculators/video/box_tracker_calculator_pb2.py +32 -0
- mediapipe/calculators/video/flow_packager_calculator_pb2.py +32 -0
- mediapipe/calculators/video/flow_to_image_calculator_pb2.py +31 -0
- mediapipe/calculators/video/motion_analysis_calculator_pb2.py +42 -0
- mediapipe/calculators/video/opencv_video_encoder_calculator_pb2.py +31 -0
- mediapipe/calculators/video/tool/__init__.py +0 -0
- mediapipe/calculators/video/tool/flow_quantizer_model_pb2.py +26 -0
- mediapipe/calculators/video/tracked_detection_manager_calculator_pb2.py +32 -0
- mediapipe/calculators/video/video_pre_stream_calculator_pb2.py +35 -0
- mediapipe/examples/__init__.py +14 -0
- mediapipe/examples/desktop/__init__.py +14 -0
- mediapipe/framework/__init__.py +0 -0
- mediapipe/framework/calculator_options_pb2.py +29 -0
- mediapipe/framework/calculator_pb2.py +59 -0
- mediapipe/framework/calculator_profile_pb2.py +48 -0
- mediapipe/framework/deps/__init__.py +0 -0
- mediapipe/framework/deps/proto_descriptor_pb2.py +29 -0
- mediapipe/framework/formats/__init__.py +0 -0
- mediapipe/framework/formats/affine_transform_data_pb2.py +28 -0
- mediapipe/framework/formats/annotation/__init__.py +0 -0
- mediapipe/framework/formats/annotation/locus_pb2.py +32 -0
- mediapipe/framework/formats/annotation/rasterization_pb2.py +29 -0
- mediapipe/framework/formats/body_rig_pb2.py +28 -0
- mediapipe/framework/formats/classification_pb2.py +31 -0
- mediapipe/framework/formats/detection_pb2.py +36 -0
- mediapipe/framework/formats/image_file_properties_pb2.py +26 -0
- mediapipe/framework/formats/image_format_pb2.py +29 -0
- mediapipe/framework/formats/landmark_pb2.py +37 -0
- mediapipe/framework/formats/location_data_pb2.py +38 -0
- mediapipe/framework/formats/matrix_data_pb2.py +31 -0
- mediapipe/framework/formats/motion/__init__.py +0 -0
- mediapipe/framework/formats/motion/optical_flow_field_data_pb2.py +30 -0
- mediapipe/framework/formats/object_detection/__init__.py +0 -0
- mediapipe/framework/formats/object_detection/anchor_pb2.py +26 -0
- mediapipe/framework/formats/rect_pb2.py +29 -0
- mediapipe/framework/formats/time_series_header_pb2.py +28 -0
- mediapipe/framework/graph_runtime_info_pb2.py +31 -0
- mediapipe/framework/mediapipe_options_pb2.py +27 -0
- mediapipe/framework/packet_factory_pb2.py +31 -0
- mediapipe/framework/packet_generator_pb2.py +33 -0
- mediapipe/framework/status_handler_pb2.py +28 -0
- mediapipe/framework/stream_handler/__init__.py +0 -0
- mediapipe/framework/stream_handler/default_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler/fixed_size_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler/sync_set_input_stream_handler_pb2.py +29 -0
- mediapipe/framework/stream_handler/timestamp_align_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler_pb2.py +30 -0
- mediapipe/framework/test_calculators_pb2.py +31 -0
- mediapipe/framework/thread_pool_executor_pb2.py +29 -0
- mediapipe/framework/tool/__init__.py +0 -0
- mediapipe/framework/tool/calculator_graph_template_pb2.py +44 -0
- mediapipe/framework/tool/field_data_pb2.py +28 -0
- mediapipe/framework/tool/node_chain_subgraph_pb2.py +31 -0
- mediapipe/framework/tool/packet_generator_wrapper_calculator_pb2.py +28 -0
- mediapipe/framework/tool/source_pb2.py +33 -0
- mediapipe/framework/tool/switch_container_pb2.py +32 -0
- mediapipe/gpu/__init__.py +0 -0
- mediapipe/gpu/copy_calculator_pb2.py +33 -0
- mediapipe/gpu/gl_animation_overlay_calculator_pb2.py +31 -0
- mediapipe/gpu/gl_context_options_pb2.py +31 -0
- mediapipe/gpu/gl_scaler_calculator_pb2.py +32 -0
- mediapipe/gpu/gl_surface_sink_calculator_pb2.py +32 -0
- mediapipe/gpu/gpu_origin_pb2.py +29 -0
- mediapipe/gpu/scale_mode_pb2.py +28 -0
- mediapipe/model_maker/__init__.py +27 -0
- mediapipe/model_maker/setup.py +107 -0
- mediapipe/modules/__init__.py +0 -0
- mediapipe/modules/face_detection/__init__.py +0 -0
- mediapipe/modules/face_detection/face_detection_full_range_cpu.binarypb +0 -0
- mediapipe/modules/face_detection/face_detection_full_range_sparse.tflite +0 -0
- mediapipe/modules/face_detection/face_detection_pb2.py +30 -0
- mediapipe/modules/face_detection/face_detection_short_range.tflite +0 -0
- mediapipe/modules/face_detection/face_detection_short_range_cpu.binarypb +0 -0
- mediapipe/modules/face_geometry/__init__.py +0 -0
- mediapipe/modules/face_geometry/data/__init__.py +0 -0
- mediapipe/modules/face_geometry/effect_renderer_calculator_pb2.py +27 -0
- mediapipe/modules/face_geometry/env_generator_calculator_pb2.py +28 -0
- mediapipe/modules/face_geometry/geometry_pipeline_calculator_pb2.py +27 -0
- mediapipe/modules/face_geometry/libs/__init__.py +0 -0
- mediapipe/modules/face_geometry/protos/__init__.py +0 -0
- mediapipe/modules/face_geometry/protos/environment_pb2.py +31 -0
- mediapipe/modules/face_geometry/protos/face_geometry_pb2.py +29 -0
- mediapipe/modules/face_geometry/protos/geometry_pipeline_metadata_pb2.py +32 -0
- mediapipe/modules/face_geometry/protos/mesh_3d_pb2.py +31 -0
- mediapipe/modules/face_landmark/__init__.py +0 -0
- mediapipe/modules/face_landmark/face_landmark.tflite +0 -0
- mediapipe/modules/face_landmark/face_landmark_front_cpu.binarypb +0 -0
- mediapipe/modules/face_landmark/face_landmark_with_attention.tflite +0 -0
- mediapipe/modules/hand_landmark/__init__.py +0 -0
- mediapipe/modules/hand_landmark/calculators/__init__.py +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_full.tflite +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_lite.tflite +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb +0 -0
- mediapipe/modules/hand_landmark/handedness.txt +2 -0
- mediapipe/modules/holistic_landmark/__init__.py +0 -0
- mediapipe/modules/holistic_landmark/calculators/__init__.py +0 -0
- mediapipe/modules/holistic_landmark/calculators/roi_tracking_calculator_pb2.py +37 -0
- mediapipe/modules/holistic_landmark/hand_recrop.tflite +0 -0
- mediapipe/modules/holistic_landmark/holistic_landmark_cpu.binarypb +0 -0
- mediapipe/modules/iris_landmark/__init__.py +0 -0
- mediapipe/modules/iris_landmark/iris_landmark.tflite +0 -0
- mediapipe/modules/objectron/__init__.py +0 -0
- mediapipe/modules/objectron/calculators/__init__.py +0 -0
- mediapipe/modules/objectron/calculators/a_r_capture_metadata_pb2.py +102 -0
- mediapipe/modules/objectron/calculators/annotation_data_pb2.py +38 -0
- mediapipe/modules/objectron/calculators/belief_decoder_config_pb2.py +28 -0
- mediapipe/modules/objectron/calculators/camera_parameters_pb2.py +30 -0
- mediapipe/modules/objectron/calculators/filter_detection_calculator_pb2.py +35 -0
- mediapipe/modules/objectron/calculators/frame_annotation_to_rect_calculator_pb2.py +31 -0
- mediapipe/modules/objectron/calculators/frame_annotation_tracker_calculator_pb2.py +31 -0
- mediapipe/modules/objectron/calculators/lift_2d_frame_annotation_to_3d_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/calculators/object_pb2.py +38 -0
- mediapipe/modules/objectron/calculators/tensors_to_objects_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/object_detection_oidv4_labelmap.txt +24 -0
- mediapipe/modules/objectron/objectron_cpu.binarypb +0 -0
- mediapipe/modules/palm_detection/__init__.py +0 -0
- mediapipe/modules/palm_detection/palm_detection_full.tflite +0 -0
- mediapipe/modules/palm_detection/palm_detection_lite.tflite +0 -0
- mediapipe/modules/pose_detection/__init__.py +0 -0
- mediapipe/modules/pose_detection/pose_detection.tflite +0 -0
- mediapipe/modules/pose_landmark/__init__.py +0 -0
- mediapipe/modules/pose_landmark/pose_landmark_cpu.binarypb +0 -0
- mediapipe/modules/pose_landmark/pose_landmark_full.tflite +0 -0
- mediapipe/modules/selfie_segmentation/__init__.py +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation.tflite +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation_cpu.binarypb +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation_landscape.tflite +0 -0
- mediapipe/python/__init__.py +29 -0
- mediapipe/python/_framework_bindings.cpython-39-x86_64-linux-gnu.so +0 -0
- mediapipe/python/calculator_graph_test.py +251 -0
- mediapipe/python/image_frame_test.py +194 -0
- mediapipe/python/image_test.py +218 -0
- mediapipe/python/packet_creator.py +275 -0
- mediapipe/python/packet_getter.py +120 -0
- mediapipe/python/packet_test.py +533 -0
- mediapipe/python/solution_base.py +604 -0
- mediapipe/python/solution_base_test.py +396 -0
- mediapipe/python/solutions/__init__.py +27 -0
- mediapipe/python/solutions/download_utils.py +37 -0
- mediapipe/python/solutions/drawing_styles.py +249 -0
- mediapipe/python/solutions/drawing_utils.py +320 -0
- mediapipe/python/solutions/drawing_utils_test.py +258 -0
- mediapipe/python/solutions/face_detection.py +105 -0
- mediapipe/python/solutions/face_detection_test.py +92 -0
- mediapipe/python/solutions/face_mesh.py +125 -0
- mediapipe/python/solutions/face_mesh_connections.py +500 -0
- mediapipe/python/solutions/face_mesh_test.py +170 -0
- mediapipe/python/solutions/hands.py +153 -0
- mediapipe/python/solutions/hands_connections.py +32 -0
- mediapipe/python/solutions/hands_test.py +219 -0
- mediapipe/python/solutions/holistic.py +167 -0
- mediapipe/python/solutions/holistic_test.py +142 -0
- mediapipe/python/solutions/objectron.py +288 -0
- mediapipe/python/solutions/objectron_test.py +81 -0
- mediapipe/python/solutions/pose.py +192 -0
- mediapipe/python/solutions/pose_connections.py +22 -0
- mediapipe/python/solutions/pose_test.py +262 -0
- mediapipe/python/solutions/selfie_segmentation.py +76 -0
- mediapipe/python/solutions/selfie_segmentation_test.py +68 -0
- mediapipe/python/timestamp_test.py +78 -0
- mediapipe/tasks/__init__.py +14 -0
- mediapipe/tasks/cc/__init__.py +0 -0
- mediapipe/tasks/cc/audio/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/proto/audio_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/audio/audio_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_embedder/proto/audio_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/audio/core/__init__.py +0 -0
- mediapipe/tasks/cc/audio/utils/__init__.py +0 -0
- mediapipe/tasks/cc/components/__init__.py +0 -0
- mediapipe/tasks/cc/components/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/components/calculators/classification_aggregation_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/components/calculators/score_calibration_calculator_pb2.py +35 -0
- mediapipe/tasks/cc/components/calculators/tensors_to_embeddings_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/components/containers/__init__.py +0 -0
- mediapipe/tasks/cc/components/containers/proto/__init__.py +0 -0
- mediapipe/tasks/cc/components/containers/proto/classifications_pb2.py +30 -0
- mediapipe/tasks/cc/components/containers/proto/embeddings_pb2.py +35 -0
- mediapipe/tasks/cc/components/containers/proto/landmarks_detection_result_pb2.py +32 -0
- mediapipe/tasks/cc/components/processors/__init__.py +0 -0
- mediapipe/tasks/cc/components/processors/proto/__init__.py +0 -0
- mediapipe/tasks/cc/components/processors/proto/classification_postprocessing_graph_options_pb2.py +38 -0
- mediapipe/tasks/cc/components/processors/proto/classifier_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/detection_postprocessing_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/components/processors/proto/detector_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/embedder_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/embedding_postprocessing_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/components/processors/proto/image_preprocessing_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/components/processors/proto/text_model_type_pb2.py +28 -0
- mediapipe/tasks/cc/components/processors/proto/text_preprocessing_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/components/utils/__init__.py +0 -0
- mediapipe/tasks/cc/core/__init__.py +0 -0
- mediapipe/tasks/cc/core/proto/__init__.py +0 -0
- mediapipe/tasks/cc/core/proto/acceleration_pb2.py +28 -0
- mediapipe/tasks/cc/core/proto/base_options_pb2.py +30 -0
- mediapipe/tasks/cc/core/proto/external_file_pb2.py +31 -0
- mediapipe/tasks/cc/core/proto/inference_subgraph_pb2.py +32 -0
- mediapipe/tasks/cc/core/proto/model_resources_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/genai/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/c/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/calculators/detokenizer_calculator_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/calculators/llm_gpu_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/genai/inference/calculators/model_data_calculator_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/calculators/tokenizer_calculator_pb2.py +29 -0
- mediapipe/tasks/cc/genai/inference/common/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/proto/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/proto/llm_file_metadata_pb2.py +32 -0
- mediapipe/tasks/cc/genai/inference/proto/llm_params_pb2.py +33 -0
- mediapipe/tasks/cc/genai/inference/proto/prompt_template_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/proto/sampler_params_pb2.py +29 -0
- mediapipe/tasks/cc/genai/inference/proto/transformer_params_pb2.py +45 -0
- mediapipe/tasks/cc/genai/inference/utils/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/utils/llm_utils/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/utils/xnn_utils/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/python/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/python/_pywrap_metadata_version.cpython-39-x86_64-linux-gnu.so +0 -0
- mediapipe/tasks/cc/metadata/tests/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/utils/__init__.py +0 -0
- mediapipe/tasks/cc/text/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/ragged/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/sentencepiece/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/sentencepiece/testdata/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/hash/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/utf/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/proto/text_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/text/text_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_embedder/proto/text_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/text/tokenizers/__init__.py +0 -0
- mediapipe/tasks/cc/text/utils/__init__.py +0 -0
- mediapipe/tasks/cc/vision/__init__.py +0 -0
- mediapipe/tasks/cc/vision/core/__init__.py +0 -0
- mediapipe/tasks/cc/vision/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/proto/face_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/face_geometry/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/env_generator_calculator_pb2.py +28 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/geometry_pipeline_calculator_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/data/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/libs/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/environment_pb2.py +31 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_graph_options_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/geometry_pipeline_metadata_pb2.py +32 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/mesh_3d_pb2.py +31 -0
- mediapipe/tasks/cc/vision/face_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_blendshapes_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarker_graph_options_pb2.py +37 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarks_detector_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/tensors_to_face_landmarks_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/vision/face_stylizer/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator_pb2.py +36 -0
- mediapipe/tasks/cc/vision/face_stylizer/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/proto/face_stylizer_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/combined_prediction_calculator_pb2.py +33 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/landmarks_to_matrix_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_embedder_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_recognizer_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/hand_gesture_recognizer_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/hand_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_result_pb2.py +30 -0
- mediapipe/tasks/cc/vision/hand_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_roi_refinement_graph_options_pb2.py +28 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_landmarker_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_result_pb2.py +29 -0
- mediapipe/tasks/cc/vision/image_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_classifier/proto/image_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_embedder/proto/image_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_generator/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/diffuser/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/diffuser/stable_diffusion_iterate_calculator_pb2.py +40 -0
- mediapipe/tasks/cc/vision/image_generator/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/proto/conditioned_image_graph_options_pb2.py +40 -0
- mediapipe/tasks/cc/vision/image_generator/proto/control_plugin_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/image_generator/proto/image_generator_graph_options_pb2.py +30 -0
- mediapipe/tasks/cc/vision/image_segmenter/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/calculators/tensors_to_segmentation_calculator_pb2.py +34 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/image_segmenter_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/segmenter_options_pb2.py +33 -0
- mediapipe/tasks/cc/vision/interactive_segmenter/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/proto/object_detector_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/pose_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_detector/proto/pose_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/pose_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarker_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarks_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/utils/__init__.py +0 -0
- mediapipe/tasks/cc/vision/utils/ghum/__init__.py +0 -0
- mediapipe/tasks/metadata/image_segmenter_metadata_schema.fbs +59 -0
- mediapipe/tasks/metadata/image_segmenter_metadata_schema_py_generated.py +108 -0
- mediapipe/tasks/metadata/metadata_schema.fbs +732 -0
- mediapipe/tasks/metadata/metadata_schema_py_generated.py +3251 -0
- mediapipe/tasks/metadata/object_detector_metadata_schema.fbs +98 -0
- mediapipe/tasks/metadata/object_detector_metadata_schema_py_generated.py +674 -0
- mediapipe/tasks/metadata/schema_py_generated.py +18438 -0
- mediapipe/tasks/python/__init__.py +27 -0
- mediapipe/tasks/python/audio/__init__.py +33 -0
- mediapipe/tasks/python/audio/audio_classifier.py +324 -0
- mediapipe/tasks/python/audio/audio_embedder.py +285 -0
- mediapipe/tasks/python/audio/core/__init__.py +16 -0
- mediapipe/tasks/python/audio/core/audio_record.py +125 -0
- mediapipe/tasks/python/audio/core/audio_task_running_mode.py +29 -0
- mediapipe/tasks/python/audio/core/base_audio_task_api.py +181 -0
- mediapipe/tasks/python/benchmark/__init__.py +13 -0
- mediapipe/tasks/python/benchmark/benchmark_utils.py +70 -0
- mediapipe/tasks/python/benchmark/vision/__init__.py +13 -0
- mediapipe/tasks/python/benchmark/vision/benchmark.py +99 -0
- mediapipe/tasks/python/benchmark/vision/core/__init__.py +14 -0
- mediapipe/tasks/python/benchmark/vision/core/base_vision_benchmark_api.py +40 -0
- mediapipe/tasks/python/components/__init__.py +13 -0
- mediapipe/tasks/python/components/containers/__init__.py +53 -0
- mediapipe/tasks/python/components/containers/audio_data.py +137 -0
- mediapipe/tasks/python/components/containers/bounding_box.py +73 -0
- mediapipe/tasks/python/components/containers/category.py +78 -0
- mediapipe/tasks/python/components/containers/classification_result.py +111 -0
- mediapipe/tasks/python/components/containers/detections.py +181 -0
- mediapipe/tasks/python/components/containers/embedding_result.py +89 -0
- mediapipe/tasks/python/components/containers/keypoint.py +77 -0
- mediapipe/tasks/python/components/containers/landmark.py +122 -0
- mediapipe/tasks/python/components/containers/landmark_detection_result.py +106 -0
- mediapipe/tasks/python/components/containers/rect.py +109 -0
- mediapipe/tasks/python/components/processors/__init__.py +23 -0
- mediapipe/tasks/python/components/processors/classifier_options.py +86 -0
- mediapipe/tasks/python/components/utils/__init__.py +13 -0
- mediapipe/tasks/python/components/utils/cosine_similarity.py +68 -0
- mediapipe/tasks/python/core/__init__.py +13 -0
- mediapipe/tasks/python/core/base_options.py +121 -0
- mediapipe/tasks/python/core/optional_dependencies.py +25 -0
- mediapipe/tasks/python/core/task_info.py +139 -0
- mediapipe/tasks/python/genai/__init__.py +14 -0
- mediapipe/tasks/python/genai/bundler/__init__.py +23 -0
- mediapipe/tasks/python/genai/bundler/llm_bundler.py +130 -0
- mediapipe/tasks/python/genai/bundler/llm_bundler_test.py +168 -0
- mediapipe/tasks/python/genai/converter/__init__.py +24 -0
- mediapipe/tasks/python/genai/converter/converter_base.py +179 -0
- mediapipe/tasks/python/genai/converter/converter_factory.py +79 -0
- mediapipe/tasks/python/genai/converter/llm_converter.py +374 -0
- mediapipe/tasks/python/genai/converter/llm_converter_test.py +63 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter.py +318 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter_test.py +86 -0
- mediapipe/tasks/python/genai/converter/quantization_util.py +516 -0
- mediapipe/tasks/python/genai/converter/quantization_util_test.py +259 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter.py +580 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter_test.py +83 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer.py +120 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer_test.py +95 -0
- mediapipe/tasks/python/metadata/__init__.py +13 -0
- mediapipe/tasks/python/metadata/flatbuffers_lib/_pywrap_flatbuffers.cpython-39-x86_64-linux-gnu.so +0 -0
- mediapipe/tasks/python/metadata/metadata.py +928 -0
- mediapipe/tasks/python/metadata/metadata_displayer_cli.py +34 -0
- mediapipe/tasks/python/metadata/metadata_writers/__init__.py +13 -0
- mediapipe/tasks/python/metadata/metadata_writers/face_stylizer.py +138 -0
- mediapipe/tasks/python/metadata/metadata_writers/image_classifier.py +71 -0
- mediapipe/tasks/python/metadata/metadata_writers/image_segmenter.py +170 -0
- mediapipe/tasks/python/metadata/metadata_writers/metadata_info.py +1166 -0
- mediapipe/tasks/python/metadata/metadata_writers/metadata_writer.py +845 -0
- mediapipe/tasks/python/metadata/metadata_writers/model_asset_bundle_utils.py +71 -0
- mediapipe/tasks/python/metadata/metadata_writers/object_detector.py +331 -0
- mediapipe/tasks/python/metadata/metadata_writers/text_classifier.py +119 -0
- mediapipe/tasks/python/metadata/metadata_writers/writer_utils.py +91 -0
- mediapipe/tasks/python/test/__init__.py +13 -0
- mediapipe/tasks/python/test/audio/__init__.py +13 -0
- mediapipe/tasks/python/test/audio/audio_classifier_test.py +387 -0
- mediapipe/tasks/python/test/audio/audio_embedder_test.py +297 -0
- mediapipe/tasks/python/test/test_utils.py +196 -0
- mediapipe/tasks/python/test/text/__init__.py +13 -0
- mediapipe/tasks/python/test/text/language_detector_test.py +228 -0
- mediapipe/tasks/python/test/text/text_classifier_test.py +235 -0
- mediapipe/tasks/python/test/text/text_embedder_test.py +326 -0
- mediapipe/tasks/python/test/vision/__init__.py +13 -0
- mediapipe/tasks/python/test/vision/face_aligner_test.py +190 -0
- mediapipe/tasks/python/test/vision/face_detector_test.py +523 -0
- mediapipe/tasks/python/test/vision/face_landmarker_test.py +565 -0
- mediapipe/tasks/python/test/vision/face_stylizer_test.py +191 -0
- mediapipe/tasks/python/test/vision/hand_landmarker_test.py +437 -0
- mediapipe/tasks/python/test/vision/holistic_landmarker_test.py +544 -0
- mediapipe/tasks/python/test/vision/image_classifier_test.py +657 -0
- mediapipe/tasks/python/test/vision/image_embedder_test.py +423 -0
- mediapipe/tasks/python/test/vision/image_segmenter_test.py +512 -0
- mediapipe/tasks/python/test/vision/interactive_segmenter_test.py +341 -0
- mediapipe/tasks/python/test/vision/object_detector_test.py +493 -0
- mediapipe/tasks/python/test/vision/pose_landmarker_test.py +518 -0
- mediapipe/tasks/python/text/__init__.py +35 -0
- mediapipe/tasks/python/text/core/__init__.py +16 -0
- mediapipe/tasks/python/text/core/base_text_task_api.py +54 -0
- mediapipe/tasks/python/text/language_detector.py +220 -0
- mediapipe/tasks/python/text/text_classifier.py +187 -0
- mediapipe/tasks/python/text/text_embedder.py +188 -0
- mediapipe/tasks/python/vision/__init__.py +90 -0
- mediapipe/tasks/python/vision/core/__init__.py +14 -0
- mediapipe/tasks/python/vision/core/base_vision_task_api.py +226 -0
- mediapipe/tasks/python/vision/core/image_processing_options.py +39 -0
- mediapipe/tasks/python/vision/core/vision_task_running_mode.py +31 -0
- mediapipe/tasks/python/vision/face_aligner.py +158 -0
- mediapipe/tasks/python/vision/face_detector.py +332 -0
- mediapipe/tasks/python/vision/face_landmarker.py +3244 -0
- mediapipe/tasks/python/vision/face_stylizer.py +158 -0
- mediapipe/tasks/python/vision/gesture_recognizer.py +480 -0
- mediapipe/tasks/python/vision/hand_landmarker.py +504 -0
- mediapipe/tasks/python/vision/holistic_landmarker.py +576 -0
- mediapipe/tasks/python/vision/image_classifier.py +358 -0
- mediapipe/tasks/python/vision/image_embedder.py +362 -0
- mediapipe/tasks/python/vision/image_segmenter.py +433 -0
- mediapipe/tasks/python/vision/interactive_segmenter.py +285 -0
- mediapipe/tasks/python/vision/object_detector.py +389 -0
- mediapipe/tasks/python/vision/pose_landmarker.py +455 -0
- mediapipe/util/__init__.py +0 -0
- mediapipe/util/analytics/__init__.py +0 -0
- mediapipe/util/analytics/mediapipe_log_extension_pb2.py +44 -0
- mediapipe/util/analytics/mediapipe_logging_enums_pb2.py +37 -0
- mediapipe/util/audio_decoder_pb2.py +33 -0
- mediapipe/util/color_pb2.py +33 -0
- mediapipe/util/label_map_pb2.py +27 -0
- mediapipe/util/render_data_pb2.py +58 -0
- mediapipe/util/sequence/__init__.py +14 -0
- mediapipe/util/sequence/media_sequence.py +716 -0
- mediapipe/util/sequence/media_sequence_test.py +290 -0
- mediapipe/util/sequence/media_sequence_util.py +800 -0
- mediapipe/util/sequence/media_sequence_util_test.py +389 -0
- mediapipe/util/tracking/__init__.py +0 -0
- mediapipe/util/tracking/box_detector_pb2.py +39 -0
- mediapipe/util/tracking/box_tracker_pb2.py +32 -0
- mediapipe/util/tracking/camera_motion_pb2.py +31 -0
- mediapipe/util/tracking/flow_packager_pb2.py +60 -0
- mediapipe/util/tracking/frame_selection_pb2.py +35 -0
- mediapipe/util/tracking/frame_selection_solution_evaluator_pb2.py +28 -0
- mediapipe/util/tracking/motion_analysis_pb2.py +35 -0
- mediapipe/util/tracking/motion_estimation_pb2.py +66 -0
- mediapipe/util/tracking/motion_models_pb2.py +42 -0
- mediapipe/util/tracking/motion_saliency_pb2.py +26 -0
- mediapipe/util/tracking/push_pull_filtering_pb2.py +26 -0
- mediapipe/util/tracking/region_flow_computation_pb2.py +59 -0
- mediapipe/util/tracking/region_flow_pb2.py +49 -0
- mediapipe/util/tracking/tone_estimation_pb2.py +45 -0
- mediapipe/util/tracking/tone_models_pb2.py +32 -0
- mediapipe/util/tracking/tracked_detection_manager_config_pb2.py +26 -0
- mediapipe/util/tracking/tracking_pb2.py +73 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/LICENSE +218 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/METADATA +199 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/RECORD +593 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/WHEEL +5 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/top_level.txt +4 -0
- mediapipe_nightly.libs/libEGL-48f73270.so.1.1.0 +0 -0
- mediapipe_nightly.libs/libGLESv2-ed5eda4f.so.2.1.0 +0 -0
- mediapipe_nightly.libs/libGLdispatch-64b28464.so.0.0.0 +0 -0
@@ -0,0 +1,928 @@
|
|
1
|
+
# Copyright 2022 The MediaPipe Authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
"""TensorFlow Lite metadata tools."""
|
16
|
+
|
17
|
+
import copy
|
18
|
+
import inspect
|
19
|
+
import io
|
20
|
+
import json
|
21
|
+
import logging
|
22
|
+
import os
|
23
|
+
import shutil
|
24
|
+
import sys
|
25
|
+
import tempfile
|
26
|
+
from typing import Dict, Optional
|
27
|
+
import warnings
|
28
|
+
import zipfile
|
29
|
+
|
30
|
+
import flatbuffers
|
31
|
+
|
32
|
+
from mediapipe.tasks.cc.metadata.python import _pywrap_metadata_version
|
33
|
+
from mediapipe.tasks.metadata import metadata_schema_py_generated as _metadata_fb
|
34
|
+
from mediapipe.tasks.metadata import schema_py_generated as _schema_fb
|
35
|
+
from mediapipe.tasks.python.metadata.flatbuffers_lib import _pywrap_flatbuffers
|
36
|
+
|
37
|
+
try:
|
38
|
+
# If exists, optionally use TensorFlow to open and check files. Used to
|
39
|
+
# support more than local file systems.
|
40
|
+
# In pip requirements, we doesn't necessarily need tensorflow as a dep.
|
41
|
+
import tensorflow as tf
|
42
|
+
_open_file = tf.io.gfile.GFile
|
43
|
+
_exists_file = tf.io.gfile.exists
|
44
|
+
except ImportError as e:
|
45
|
+
# If TensorFlow package doesn't exist, fall back to original open and exists.
|
46
|
+
_open_file = open
|
47
|
+
_exists_file = os.path.exists
|
48
|
+
|
49
|
+
|
50
|
+
def _maybe_open_as_binary(filename, mode):
|
51
|
+
"""Maybe open the binary file, and returns a file-like."""
|
52
|
+
if hasattr(filename, "read"): # A file-like has read().
|
53
|
+
return filename
|
54
|
+
openmode = mode if "b" in mode else mode + "b" # Add binary explicitly.
|
55
|
+
return _open_file(filename, openmode)
|
56
|
+
|
57
|
+
|
58
|
+
def _open_as_zipfile(filename, mode="r"):
|
59
|
+
"""Open file as a zipfile.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
filename: str or file-like or path-like, to the zipfile.
|
63
|
+
mode: str, common file mode for zip.
|
64
|
+
(See: https://docs.python.org/3/library/zipfile.html)
|
65
|
+
|
66
|
+
Returns:
|
67
|
+
A ZipFile object.
|
68
|
+
"""
|
69
|
+
file_like = _maybe_open_as_binary(filename, mode)
|
70
|
+
return zipfile.ZipFile(file_like, mode)
|
71
|
+
|
72
|
+
|
73
|
+
def _is_zipfile(filename):
|
74
|
+
"""Checks whether it is a zipfile."""
|
75
|
+
with _maybe_open_as_binary(filename, "r") as f:
|
76
|
+
return zipfile.is_zipfile(f)
|
77
|
+
|
78
|
+
|
79
|
+
def get_path_to_datafile(path):
|
80
|
+
"""Gets the path to the specified file in the data dependencies.
|
81
|
+
|
82
|
+
The path is relative to the file calling the function.
|
83
|
+
|
84
|
+
It's a simple replacement of
|
85
|
+
"tensorflow.python.platform.resource_loader.get_path_to_datafile".
|
86
|
+
|
87
|
+
Args:
|
88
|
+
path: a string resource path relative to the calling file.
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
The path to the specified file present in the data attribute of py_test
|
92
|
+
or py_binary.
|
93
|
+
"""
|
94
|
+
data_files_path = os.path.dirname(inspect.getfile(sys._getframe(1))) # pylint: disable=protected-access
|
95
|
+
return os.path.join(data_files_path, path)
|
96
|
+
|
97
|
+
|
98
|
+
_FLATC_TFLITE_METADATA_SCHEMA_FILE = get_path_to_datafile(
|
99
|
+
"../../metadata/metadata_schema.fbs")
|
100
|
+
|
101
|
+
|
102
|
+
# TODO: add delete method for associated files.
|
103
|
+
class MetadataPopulator(object):
|
104
|
+
"""Packs metadata and associated files into TensorFlow Lite model file.
|
105
|
+
|
106
|
+
MetadataPopulator can be used to populate metadata and model associated files
|
107
|
+
into a model file or a model buffer (in bytearray). It can also help to
|
108
|
+
inspect list of files that have been packed into the model or are supposed to
|
109
|
+
be packed into the model.
|
110
|
+
|
111
|
+
The metadata file (or buffer) should be generated based on the metadata
|
112
|
+
schema:
|
113
|
+
mediapipe/tasks/metadata/metadata_schema.fbs
|
114
|
+
|
115
|
+
Example usage:
|
116
|
+
Populate metadata and label file into an image classifier model.
|
117
|
+
|
118
|
+
First, based on metadata_schema.fbs, generate the metadata for this image
|
119
|
+
classifier model using Flatbuffers API. Attach the label file onto the output
|
120
|
+
tensor (the tensor of probabilities) in the metadata.
|
121
|
+
|
122
|
+
Then, pack the metadata and label file into the model as follows.
|
123
|
+
|
124
|
+
```python
|
125
|
+
# Populating a metadata file (or a metadata buffer) and associated files to
|
126
|
+
a model file:
|
127
|
+
populator = MetadataPopulator.with_model_file(model_file)
|
128
|
+
# For metadata buffer (bytearray read from the metadata file), use:
|
129
|
+
# populator.load_metadata_buffer(metadata_buf)
|
130
|
+
populator.load_metadata_file(metadata_file)
|
131
|
+
populator.load_associated_files([label.txt])
|
132
|
+
# For associated file buffer (bytearray read from the file), use:
|
133
|
+
# populator.load_associated_file_buffers({"label.txt": b"file content"})
|
134
|
+
populator.populate()
|
135
|
+
|
136
|
+
# Populating a metadata file (or a metadata buffer) and associated files to
|
137
|
+
a model buffer:
|
138
|
+
populator = MetadataPopulator.with_model_buffer(model_buf)
|
139
|
+
populator.load_metadata_file(metadata_file)
|
140
|
+
populator.load_associated_files([label.txt])
|
141
|
+
populator.populate()
|
142
|
+
# Writing the updated model buffer into a file.
|
143
|
+
updated_model_buf = populator.get_model_buffer()
|
144
|
+
with open("updated_model.tflite", "wb") as f:
|
145
|
+
f.write(updated_model_buf)
|
146
|
+
|
147
|
+
# Transferring metadata and associated files from another TFLite model:
|
148
|
+
populator = MetadataPopulator.with_model_buffer(model_buf)
|
149
|
+
populator_dst.load_metadata_and_associated_files(src_model_buf)
|
150
|
+
populator_dst.populate()
|
151
|
+
updated_model_buf = populator.get_model_buffer()
|
152
|
+
with open("updated_model.tflite", "wb") as f:
|
153
|
+
f.write(updated_model_buf)
|
154
|
+
```
|
155
|
+
|
156
|
+
Note that existing metadata buffer (if applied) will be overridden by the new
|
157
|
+
metadata buffer.
|
158
|
+
"""
|
159
|
+
# As Zip API is used to concatenate associated files after tflite model file,
|
160
|
+
# the populating operation is developed based on a model file. For in-memory
|
161
|
+
# model buffer, we create a tempfile to serve the populating operation.
|
162
|
+
# Creating the deleting such a tempfile is handled by the class,
|
163
|
+
# _MetadataPopulatorWithBuffer.
|
164
|
+
|
165
|
+
METADATA_FIELD_NAME = "TFLITE_METADATA"
|
166
|
+
TFLITE_FILE_IDENTIFIER = b"TFL3"
|
167
|
+
METADATA_FILE_IDENTIFIER = b"M001"
|
168
|
+
|
169
|
+
def __init__(self, model_file):
|
170
|
+
"""Constructor for MetadataPopulator.
|
171
|
+
|
172
|
+
Args:
|
173
|
+
model_file: valid path to a TensorFlow Lite model file.
|
174
|
+
|
175
|
+
Raises:
|
176
|
+
IOError: File not found.
|
177
|
+
ValueError: the model does not have the expected flatbuffer identifier.
|
178
|
+
"""
|
179
|
+
_assert_model_file_identifier(model_file)
|
180
|
+
self._model_file = model_file
|
181
|
+
self._metadata_buf = None
|
182
|
+
# _associated_files is a dict of file name and file buffer.
|
183
|
+
self._associated_files = {}
|
184
|
+
|
185
|
+
@classmethod
|
186
|
+
def with_model_file(cls, model_file):
|
187
|
+
"""Creates a MetadataPopulator object that populates data to a model file.
|
188
|
+
|
189
|
+
Args:
|
190
|
+
model_file: valid path to a TensorFlow Lite model file.
|
191
|
+
|
192
|
+
Returns:
|
193
|
+
MetadataPopulator object.
|
194
|
+
|
195
|
+
Raises:
|
196
|
+
IOError: File not found.
|
197
|
+
ValueError: the model does not have the expected flatbuffer identifier.
|
198
|
+
"""
|
199
|
+
return cls(model_file)
|
200
|
+
|
201
|
+
# TODO: investigate if type check can be applied to model_buf for
|
202
|
+
# FB.
|
203
|
+
@classmethod
|
204
|
+
def with_model_buffer(cls, model_buf):
|
205
|
+
"""Creates a MetadataPopulator object that populates data to a model buffer.
|
206
|
+
|
207
|
+
Args:
|
208
|
+
model_buf: TensorFlow Lite model buffer in bytearray.
|
209
|
+
|
210
|
+
Returns:
|
211
|
+
A MetadataPopulator(_MetadataPopulatorWithBuffer) object.
|
212
|
+
|
213
|
+
Raises:
|
214
|
+
ValueError: the model does not have the expected flatbuffer identifier.
|
215
|
+
"""
|
216
|
+
return _MetadataPopulatorWithBuffer(model_buf)
|
217
|
+
|
218
|
+
def get_model_buffer(self):
|
219
|
+
"""Gets the buffer of the model with packed metadata and associated files.
|
220
|
+
|
221
|
+
Returns:
|
222
|
+
Model buffer (in bytearray).
|
223
|
+
"""
|
224
|
+
with _open_file(self._model_file, "rb") as f:
|
225
|
+
return f.read()
|
226
|
+
|
227
|
+
def get_packed_associated_file_list(self):
|
228
|
+
"""Gets a list of associated files packed to the model file.
|
229
|
+
|
230
|
+
Returns:
|
231
|
+
List of packed associated files.
|
232
|
+
"""
|
233
|
+
if not _is_zipfile(self._model_file):
|
234
|
+
return []
|
235
|
+
|
236
|
+
with _open_as_zipfile(self._model_file, "r") as zf:
|
237
|
+
return zf.namelist()
|
238
|
+
|
239
|
+
def get_recorded_associated_file_list(self):
|
240
|
+
"""Gets a list of associated files recorded in metadata of the model file.
|
241
|
+
|
242
|
+
Associated files may be attached to a model, a subgraph, or an input/output
|
243
|
+
tensor.
|
244
|
+
|
245
|
+
Returns:
|
246
|
+
List of recorded associated files.
|
247
|
+
"""
|
248
|
+
if not self._metadata_buf:
|
249
|
+
return []
|
250
|
+
|
251
|
+
metadata = _metadata_fb.ModelMetadataT.InitFromObj(
|
252
|
+
_metadata_fb.ModelMetadata.GetRootAsModelMetadata(
|
253
|
+
self._metadata_buf, 0))
|
254
|
+
|
255
|
+
return [
|
256
|
+
file.name.decode("utf-8")
|
257
|
+
for file in self._get_recorded_associated_file_object_list(metadata)
|
258
|
+
]
|
259
|
+
|
260
|
+
def load_associated_file_buffers(self, associated_files):
|
261
|
+
"""Loads the associated file buffers (in bytearray) to be populated.
|
262
|
+
|
263
|
+
Args:
|
264
|
+
associated_files: a dictionary of associated file names and corresponding
|
265
|
+
file buffers, such as {"file.txt": b"file content"}. If pass in file
|
266
|
+
paths for the file name, only the basename will be populated.
|
267
|
+
"""
|
268
|
+
|
269
|
+
self._associated_files.update({
|
270
|
+
os.path.basename(name): buffers
|
271
|
+
for name, buffers in associated_files.items()
|
272
|
+
})
|
273
|
+
|
274
|
+
def load_associated_files(self, associated_files):
|
275
|
+
"""Loads associated files that to be concatenated after the model file.
|
276
|
+
|
277
|
+
Args:
|
278
|
+
associated_files: list of file paths.
|
279
|
+
|
280
|
+
Raises:
|
281
|
+
IOError:
|
282
|
+
File not found.
|
283
|
+
"""
|
284
|
+
for af_name in associated_files:
|
285
|
+
_assert_file_exist(af_name)
|
286
|
+
with _open_file(af_name, "rb") as af:
|
287
|
+
self.load_associated_file_buffers({af_name: af.read()})
|
288
|
+
|
289
|
+
def load_metadata_buffer(self, metadata_buf):
|
290
|
+
"""Loads the metadata buffer (in bytearray) to be populated.
|
291
|
+
|
292
|
+
Args:
|
293
|
+
metadata_buf: metadata buffer (in bytearray) to be populated.
|
294
|
+
|
295
|
+
Raises:
|
296
|
+
ValueError: The metadata to be populated is empty.
|
297
|
+
ValueError: The metadata does not have the expected flatbuffer identifier.
|
298
|
+
ValueError: Cannot get minimum metadata parser version.
|
299
|
+
ValueError: The number of SubgraphMetadata is not 1.
|
300
|
+
ValueError: The number of input/output tensors does not match the number
|
301
|
+
of input/output tensor metadata.
|
302
|
+
"""
|
303
|
+
if not metadata_buf:
|
304
|
+
raise ValueError("The metadata to be populated is empty.")
|
305
|
+
|
306
|
+
self._validate_metadata(metadata_buf)
|
307
|
+
|
308
|
+
# Gets the minimum metadata parser version of the metadata_buf.
|
309
|
+
min_version = _pywrap_metadata_version.GetMinimumMetadataParserVersion(
|
310
|
+
bytes(metadata_buf))
|
311
|
+
|
312
|
+
# Inserts in the minimum metadata parser version into the metadata_buf.
|
313
|
+
metadata = _metadata_fb.ModelMetadataT.InitFromObj(
|
314
|
+
_metadata_fb.ModelMetadata.GetRootAsModelMetadata(metadata_buf, 0))
|
315
|
+
metadata.minParserVersion = min_version
|
316
|
+
|
317
|
+
# Remove local file directory in the `name` field of `AssociatedFileT`, and
|
318
|
+
# make it consistent with the name of the actual file packed in the model.
|
319
|
+
self._use_basename_for_associated_files_in_metadata(metadata)
|
320
|
+
|
321
|
+
b = flatbuffers.Builder(0)
|
322
|
+
b.Finish(metadata.Pack(b), self.METADATA_FILE_IDENTIFIER)
|
323
|
+
metadata_buf_with_version = b.Output()
|
324
|
+
|
325
|
+
self._metadata_buf = metadata_buf_with_version
|
326
|
+
|
327
|
+
def load_metadata_file(self, metadata_file):
|
328
|
+
"""Loads the metadata file to be populated.
|
329
|
+
|
330
|
+
Args:
|
331
|
+
metadata_file: path to the metadata file to be populated.
|
332
|
+
|
333
|
+
Raises:
|
334
|
+
IOError: File not found.
|
335
|
+
ValueError: The metadata to be populated is empty.
|
336
|
+
ValueError: The metadata does not have the expected flatbuffer identifier.
|
337
|
+
ValueError: Cannot get minimum metadata parser version.
|
338
|
+
ValueError: The number of SubgraphMetadata is not 1.
|
339
|
+
ValueError: The number of input/output tensors does not match the number
|
340
|
+
of input/output tensor metadata.
|
341
|
+
"""
|
342
|
+
_assert_file_exist(metadata_file)
|
343
|
+
with _open_file(metadata_file, "rb") as f:
|
344
|
+
metadata_buf = f.read()
|
345
|
+
self.load_metadata_buffer(bytearray(metadata_buf))
|
346
|
+
|
347
|
+
def load_metadata_and_associated_files(self, src_model_buf):
|
348
|
+
"""Loads the metadata and associated files from another model buffer.
|
349
|
+
|
350
|
+
Args:
|
351
|
+
src_model_buf: source model buffer (in bytearray) with metadata and
|
352
|
+
associated files.
|
353
|
+
"""
|
354
|
+
# Load the model metadata from src_model_buf if exist.
|
355
|
+
metadata_buffer = get_metadata_buffer(src_model_buf)
|
356
|
+
if metadata_buffer:
|
357
|
+
self.load_metadata_buffer(metadata_buffer)
|
358
|
+
|
359
|
+
# Load the associated files from src_model_buf if exist.
|
360
|
+
if _is_zipfile(io.BytesIO(src_model_buf)):
|
361
|
+
with _open_as_zipfile(io.BytesIO(src_model_buf)) as zf:
|
362
|
+
self.load_associated_file_buffers(
|
363
|
+
{f: zf.read(f) for f in zf.namelist()})
|
364
|
+
|
365
|
+
def populate(self):
|
366
|
+
"""Populates loaded metadata and associated files into the model file."""
|
367
|
+
self._assert_validate()
|
368
|
+
self._populate_metadata_buffer()
|
369
|
+
self._populate_associated_files()
|
370
|
+
|
371
|
+
def _assert_validate(self):
|
372
|
+
"""Validates the metadata and associated files to be populated.
|
373
|
+
|
374
|
+
Raises:
|
375
|
+
ValueError:
|
376
|
+
File is recorded in the metadata, but is not going to be populated.
|
377
|
+
File has already been packed.
|
378
|
+
"""
|
379
|
+
# Gets files that are recorded in metadata.
|
380
|
+
recorded_files = self.get_recorded_associated_file_list()
|
381
|
+
|
382
|
+
# Gets files that have been packed to self._model_file.
|
383
|
+
packed_files = self.get_packed_associated_file_list()
|
384
|
+
|
385
|
+
# Gets the file name of those associated files to be populated.
|
386
|
+
to_be_populated_files = self._associated_files.keys()
|
387
|
+
|
388
|
+
# Checks all files recorded in the metadata will be populated.
|
389
|
+
for rf in recorded_files:
|
390
|
+
if rf not in to_be_populated_files and rf not in packed_files:
|
391
|
+
raise ValueError("File, '{0}', is recorded in the metadata, but has "
|
392
|
+
"not been loaded into the populator.".format(rf))
|
393
|
+
|
394
|
+
for f in to_be_populated_files:
|
395
|
+
if f in packed_files:
|
396
|
+
raise ValueError("File, '{0}', has already been packed.".format(f))
|
397
|
+
|
398
|
+
if f not in recorded_files:
|
399
|
+
warnings.warn(
|
400
|
+
"File, '{0}', does not exist in the metadata. But packing it to "
|
401
|
+
"tflite model is still allowed.".format(f))
|
402
|
+
|
403
|
+
def _copy_archived_files(self, src_zip, file_list, dst_zip):
|
404
|
+
"""Copy archieved files in file_list from src_zip ro dst_zip."""
|
405
|
+
|
406
|
+
if not _is_zipfile(src_zip):
|
407
|
+
raise ValueError("File, '{0}', is not a zipfile.".format(src_zip))
|
408
|
+
|
409
|
+
with _open_as_zipfile(src_zip, "r") as src_zf, \
|
410
|
+
_open_as_zipfile(dst_zip, "a") as dst_zf:
|
411
|
+
src_list = src_zf.namelist()
|
412
|
+
for f in file_list:
|
413
|
+
if f not in src_list:
|
414
|
+
raise ValueError(
|
415
|
+
"File, '{0}', does not exist in the zipfile, {1}.".format(
|
416
|
+
f, src_zip))
|
417
|
+
file_buffer = src_zf.read(f)
|
418
|
+
dst_zf.writestr(f, file_buffer)
|
419
|
+
|
420
|
+
def _get_associated_files_from_process_units(self, table, field_name):
|
421
|
+
"""Gets the files that are attached the process units field of a table.
|
422
|
+
|
423
|
+
Args:
|
424
|
+
table: a Flatbuffers table object that contains fields of an array of
|
425
|
+
ProcessUnit, such as TensorMetadata and SubGraphMetadata.
|
426
|
+
field_name: the name of the field in the table that represents an array of
|
427
|
+
ProcessUnit. If the table is TensorMetadata, field_name can be
|
428
|
+
"ProcessUnits". If the table is SubGraphMetadata, field_name can be
|
429
|
+
either "InputProcessUnits" or "OutputProcessUnits".
|
430
|
+
|
431
|
+
Returns:
|
432
|
+
A list of AssociatedFileT objects.
|
433
|
+
"""
|
434
|
+
|
435
|
+
if table is None:
|
436
|
+
return []
|
437
|
+
|
438
|
+
file_list = []
|
439
|
+
process_units = getattr(table, field_name)
|
440
|
+
# If the process_units field is not populated, it will be None. Use an
|
441
|
+
# empty list to skip the check.
|
442
|
+
for process_unit in process_units or []:
|
443
|
+
options = process_unit.options
|
444
|
+
if isinstance(options, (_metadata_fb.BertTokenizerOptionsT,
|
445
|
+
_metadata_fb.RegexTokenizerOptionsT)):
|
446
|
+
file_list += self._get_associated_files_from_table(options, "vocabFile")
|
447
|
+
elif isinstance(options, _metadata_fb.SentencePieceTokenizerOptionsT):
|
448
|
+
file_list += self._get_associated_files_from_table(
|
449
|
+
options, "sentencePieceModel")
|
450
|
+
file_list += self._get_associated_files_from_table(options, "vocabFile")
|
451
|
+
return file_list
|
452
|
+
|
453
|
+
def _get_associated_files_from_table(self, table, field_name):
|
454
|
+
"""Gets the associated files that are attached a table directly.
|
455
|
+
|
456
|
+
Args:
|
457
|
+
table: a Flatbuffers table object that contains fields of an array of
|
458
|
+
AssociatedFile, such as TensorMetadata and BertTokenizerOptions.
|
459
|
+
field_name: the name of the field in the table that represents an array of
|
460
|
+
ProcessUnit. If the table is TensorMetadata, field_name can be
|
461
|
+
"AssociatedFiles". If the table is BertTokenizerOptions, field_name can
|
462
|
+
be "VocabFile".
|
463
|
+
|
464
|
+
Returns:
|
465
|
+
A list of AssociatedFileT objects.
|
466
|
+
"""
|
467
|
+
|
468
|
+
if table is None:
|
469
|
+
return []
|
470
|
+
|
471
|
+
# If the associated file field is not populated,
|
472
|
+
# `getattr(table, field_name)` will be None. Return an empty list.
|
473
|
+
return getattr(table, field_name) or []
|
474
|
+
|
475
|
+
def _get_recorded_associated_file_object_list(self, metadata):
|
476
|
+
"""Gets a list of AssociatedFileT objects recorded in the metadata.
|
477
|
+
|
478
|
+
Associated files may be attached to a model, a subgraph, or an input/output
|
479
|
+
tensor.
|
480
|
+
|
481
|
+
Args:
|
482
|
+
metadata: the ModelMetadataT object.
|
483
|
+
|
484
|
+
Returns:
|
485
|
+
List of recorded AssociatedFileT objects.
|
486
|
+
"""
|
487
|
+
recorded_files = []
|
488
|
+
|
489
|
+
# Add associated files attached to ModelMetadata.
|
490
|
+
recorded_files += self._get_associated_files_from_table(
|
491
|
+
metadata, "associatedFiles")
|
492
|
+
|
493
|
+
# Add associated files attached to each SubgraphMetadata.
|
494
|
+
for subgraph in metadata.subgraphMetadata or []:
|
495
|
+
recorded_files += self._get_associated_files_from_table(
|
496
|
+
subgraph, "associatedFiles")
|
497
|
+
|
498
|
+
# Add associated files attached to each input tensor.
|
499
|
+
for tensor_metadata in subgraph.inputTensorMetadata or []:
|
500
|
+
recorded_files += self._get_associated_files_from_table(
|
501
|
+
tensor_metadata, "associatedFiles")
|
502
|
+
recorded_files += self._get_associated_files_from_process_units(
|
503
|
+
tensor_metadata, "processUnits")
|
504
|
+
|
505
|
+
# Add associated files attached to each output tensor.
|
506
|
+
for tensor_metadata in subgraph.outputTensorMetadata or []:
|
507
|
+
recorded_files += self._get_associated_files_from_table(
|
508
|
+
tensor_metadata, "associatedFiles")
|
509
|
+
recorded_files += self._get_associated_files_from_process_units(
|
510
|
+
tensor_metadata, "processUnits")
|
511
|
+
|
512
|
+
# Add associated files attached to the input_process_units.
|
513
|
+
recorded_files += self._get_associated_files_from_process_units(
|
514
|
+
subgraph, "inputProcessUnits")
|
515
|
+
|
516
|
+
# Add associated files attached to the output_process_units.
|
517
|
+
recorded_files += self._get_associated_files_from_process_units(
|
518
|
+
subgraph, "outputProcessUnits")
|
519
|
+
|
520
|
+
return recorded_files
|
521
|
+
|
522
|
+
def _populate_associated_files(self):
|
523
|
+
"""Concatenates associated files after TensorFlow Lite model file.
|
524
|
+
|
525
|
+
If the MetadataPopulator object is created using the method,
|
526
|
+
with_model_file(model_file), the model file will be updated.
|
527
|
+
"""
|
528
|
+
# Opens up the model file in "appending" mode.
|
529
|
+
# If self._model_file already has pack files, zipfile will concatenate
|
530
|
+
# addition files after self._model_file. For example, suppose we have
|
531
|
+
# self._model_file = old_tflite_file | label1.txt | label2.txt
|
532
|
+
# Then after trigger populate() to add label3.txt, self._model_file becomes
|
533
|
+
# self._model_file = old_tflite_file | label1.txt | label2.txt | label3.txt
|
534
|
+
with tempfile.SpooledTemporaryFile() as temp:
|
535
|
+
# (1) Copy content from model file of to temp file.
|
536
|
+
with _open_file(self._model_file, "rb") as f:
|
537
|
+
shutil.copyfileobj(f, temp)
|
538
|
+
|
539
|
+
# (2) Append of to a temp file as a zip.
|
540
|
+
with _open_as_zipfile(temp, "a") as zf:
|
541
|
+
for file_name, file_buffer in self._associated_files.items():
|
542
|
+
zf.writestr(file_name, file_buffer)
|
543
|
+
|
544
|
+
# (3) Copy temp file to model file.
|
545
|
+
temp.seek(0)
|
546
|
+
with _open_file(self._model_file, "wb") as f:
|
547
|
+
shutil.copyfileobj(temp, f)
|
548
|
+
|
549
|
+
def _populate_metadata_buffer(self):
|
550
|
+
"""Populates the metadata buffer (in bytearray) into the model file.
|
551
|
+
|
552
|
+
Inserts metadata_buf into the metadata field of schema.Model. If the
|
553
|
+
MetadataPopulator object is created using the method,
|
554
|
+
with_model_file(model_file), the model file will be updated.
|
555
|
+
|
556
|
+
Existing metadata buffer (if applied) will be overridden by the new metadata
|
557
|
+
buffer.
|
558
|
+
"""
|
559
|
+
|
560
|
+
with _open_file(self._model_file, "rb") as f:
|
561
|
+
model_buf = f.read()
|
562
|
+
|
563
|
+
model = _schema_fb.ModelT.InitFromObj(
|
564
|
+
_schema_fb.Model.GetRootAsModel(model_buf, 0))
|
565
|
+
buffer_field = _schema_fb.BufferT()
|
566
|
+
buffer_field.data = self._metadata_buf
|
567
|
+
|
568
|
+
is_populated = False
|
569
|
+
if not model.metadata:
|
570
|
+
model.metadata = []
|
571
|
+
else:
|
572
|
+
# Check if metadata has already been populated.
|
573
|
+
for meta in model.metadata:
|
574
|
+
if meta.name.decode("utf-8") == self.METADATA_FIELD_NAME:
|
575
|
+
is_populated = True
|
576
|
+
model.buffers[meta.buffer] = buffer_field
|
577
|
+
|
578
|
+
if not is_populated:
|
579
|
+
if not model.buffers:
|
580
|
+
model.buffers = []
|
581
|
+
model.buffers.append(buffer_field)
|
582
|
+
# Creates a new metadata field.
|
583
|
+
metadata_field = _schema_fb.MetadataT()
|
584
|
+
metadata_field.name = self.METADATA_FIELD_NAME
|
585
|
+
metadata_field.buffer = len(model.buffers) - 1
|
586
|
+
model.metadata.append(metadata_field)
|
587
|
+
|
588
|
+
# Packs model back to a flatbuffer binaray file.
|
589
|
+
b = flatbuffers.Builder(0)
|
590
|
+
b.Finish(model.Pack(b), self.TFLITE_FILE_IDENTIFIER)
|
591
|
+
model_buf = b.Output()
|
592
|
+
|
593
|
+
# Saves the updated model buffer to model file.
|
594
|
+
# Gets files that have been packed to self._model_file.
|
595
|
+
packed_files = self.get_packed_associated_file_list()
|
596
|
+
if packed_files:
|
597
|
+
# Writes the updated model buffer and associated files into a new model
|
598
|
+
# file (in memory). Then overwrites the original model file.
|
599
|
+
with tempfile.SpooledTemporaryFile() as temp:
|
600
|
+
temp.write(model_buf)
|
601
|
+
self._copy_archived_files(self._model_file, packed_files, temp)
|
602
|
+
temp.seek(0)
|
603
|
+
with _open_file(self._model_file, "wb") as f:
|
604
|
+
shutil.copyfileobj(temp, f)
|
605
|
+
else:
|
606
|
+
with _open_file(self._model_file, "wb") as f:
|
607
|
+
f.write(model_buf)
|
608
|
+
|
609
|
+
def _use_basename_for_associated_files_in_metadata(self, metadata):
|
610
|
+
"""Removes any associated file local directory (if exists)."""
|
611
|
+
for file in self._get_recorded_associated_file_object_list(metadata):
|
612
|
+
file.name = os.path.basename(file.name)
|
613
|
+
|
614
|
+
def _validate_metadata(self, metadata_buf):
|
615
|
+
"""Validates the metadata to be populated."""
|
616
|
+
_assert_metadata_buffer_identifier(metadata_buf)
|
617
|
+
|
618
|
+
# Verify the number of SubgraphMetadata is exactly one.
|
619
|
+
# TFLite currently only support one subgraph.
|
620
|
+
model_meta = _metadata_fb.ModelMetadata.GetRootAsModelMetadata(
|
621
|
+
metadata_buf, 0)
|
622
|
+
if model_meta.SubgraphMetadataLength() != 1:
|
623
|
+
raise ValueError("The number of SubgraphMetadata should be exactly one, "
|
624
|
+
"but got {0}.".format(
|
625
|
+
model_meta.SubgraphMetadataLength()))
|
626
|
+
|
627
|
+
# Verify if the number of tensor metadata matches the number of tensors.
|
628
|
+
with _open_file(self._model_file, "rb") as f:
|
629
|
+
model_buf = f.read()
|
630
|
+
model = _schema_fb.Model.GetRootAsModel(model_buf, 0)
|
631
|
+
|
632
|
+
num_input_tensors = model.Subgraphs(0).InputsLength()
|
633
|
+
num_input_meta = model_meta.SubgraphMetadata(0).InputTensorMetadataLength()
|
634
|
+
if num_input_tensors != num_input_meta:
|
635
|
+
raise ValueError(
|
636
|
+
"The number of input tensors ({0}) should match the number of "
|
637
|
+
"input tensor metadata ({1})".format(num_input_tensors,
|
638
|
+
num_input_meta))
|
639
|
+
num_output_tensors = model.Subgraphs(0).OutputsLength()
|
640
|
+
num_output_meta = model_meta.SubgraphMetadata(
|
641
|
+
0).OutputTensorMetadataLength()
|
642
|
+
if num_output_tensors != num_output_meta:
|
643
|
+
raise ValueError(
|
644
|
+
"The number of output tensors ({0}) should match the number of "
|
645
|
+
"output tensor metadata ({1})".format(num_output_tensors,
|
646
|
+
num_output_meta))
|
647
|
+
|
648
|
+
|
649
|
+
class _MetadataPopulatorWithBuffer(MetadataPopulator):
|
650
|
+
"""Subclass of MetadataPopulator that populates metadata to a model buffer.
|
651
|
+
|
652
|
+
This class is used to populate metadata into a in-memory model buffer. As we
|
653
|
+
use Zip API to concatenate associated files after tflite model file, the
|
654
|
+
populating operation is developed based on a model file. For in-memory model
|
655
|
+
buffer, we create a tempfile to serve the populating operation. This class is
|
656
|
+
then used to generate this tempfile, and delete the file when the
|
657
|
+
MetadataPopulator object is deleted.
|
658
|
+
"""
|
659
|
+
|
660
|
+
def __init__(self, model_buf):
|
661
|
+
"""Constructor for _MetadataPopulatorWithBuffer.
|
662
|
+
|
663
|
+
Args:
|
664
|
+
model_buf: TensorFlow Lite model buffer in bytearray.
|
665
|
+
|
666
|
+
Raises:
|
667
|
+
ValueError: model_buf is empty.
|
668
|
+
ValueError: model_buf does not have the expected flatbuffer identifier.
|
669
|
+
"""
|
670
|
+
if not model_buf:
|
671
|
+
raise ValueError("model_buf cannot be empty.")
|
672
|
+
|
673
|
+
with tempfile.NamedTemporaryFile() as temp:
|
674
|
+
model_file = temp.name
|
675
|
+
|
676
|
+
with _open_file(model_file, "wb") as f:
|
677
|
+
f.write(model_buf)
|
678
|
+
|
679
|
+
super().__init__(model_file)
|
680
|
+
|
681
|
+
def __del__(self):
|
682
|
+
"""Destructor of _MetadataPopulatorWithBuffer.
|
683
|
+
|
684
|
+
Deletes the tempfile.
|
685
|
+
"""
|
686
|
+
if os.path.exists(self._model_file):
|
687
|
+
os.remove(self._model_file)
|
688
|
+
|
689
|
+
|
690
|
+
class MetadataDisplayer(object):
|
691
|
+
"""Displays metadata and associated file info in human-readable format."""
|
692
|
+
|
693
|
+
def __init__(self, model_buffer, metadata_buffer, associated_file_list):
|
694
|
+
"""Constructor for MetadataDisplayer.
|
695
|
+
|
696
|
+
Args:
|
697
|
+
model_buffer: valid buffer of the model file.
|
698
|
+
metadata_buffer: valid buffer of the metadata file.
|
699
|
+
associated_file_list: list of associate files in the model file.
|
700
|
+
"""
|
701
|
+
_assert_model_buffer_identifier(model_buffer)
|
702
|
+
_assert_metadata_buffer_identifier(metadata_buffer)
|
703
|
+
self._model_buffer = model_buffer
|
704
|
+
self._metadata_buffer = metadata_buffer
|
705
|
+
self._associated_file_list = associated_file_list
|
706
|
+
|
707
|
+
@classmethod
|
708
|
+
def with_model_file(cls, model_file):
|
709
|
+
"""Creates a MetadataDisplayer object for the model file.
|
710
|
+
|
711
|
+
Args:
|
712
|
+
model_file: valid path to a TensorFlow Lite model file.
|
713
|
+
|
714
|
+
Returns:
|
715
|
+
MetadataDisplayer object.
|
716
|
+
|
717
|
+
Raises:
|
718
|
+
IOError: File not found.
|
719
|
+
ValueError: The model does not have metadata.
|
720
|
+
"""
|
721
|
+
_assert_file_exist(model_file)
|
722
|
+
with _open_file(model_file, "rb") as f:
|
723
|
+
return cls.with_model_buffer(f.read())
|
724
|
+
|
725
|
+
@classmethod
|
726
|
+
def with_model_buffer(cls, model_buffer):
|
727
|
+
"""Creates a MetadataDisplayer object for a file buffer.
|
728
|
+
|
729
|
+
Args:
|
730
|
+
model_buffer: TensorFlow Lite model buffer in bytearray.
|
731
|
+
|
732
|
+
Returns:
|
733
|
+
MetadataDisplayer object.
|
734
|
+
"""
|
735
|
+
if not model_buffer:
|
736
|
+
raise ValueError("model_buffer cannot be empty.")
|
737
|
+
metadata_buffer = get_metadata_buffer(model_buffer)
|
738
|
+
if not metadata_buffer:
|
739
|
+
raise ValueError("The model does not have metadata.")
|
740
|
+
associated_file_list = cls._parse_packed_associated_file_list(model_buffer)
|
741
|
+
return cls(model_buffer, metadata_buffer, associated_file_list)
|
742
|
+
|
743
|
+
def get_associated_file_buffer(self, filename):
|
744
|
+
"""Get the specified associated file content in bytearray.
|
745
|
+
|
746
|
+
Args:
|
747
|
+
filename: name of the file to be extracted.
|
748
|
+
|
749
|
+
Returns:
|
750
|
+
The file content in bytearray.
|
751
|
+
|
752
|
+
Raises:
|
753
|
+
ValueError: if the file does not exist in the model.
|
754
|
+
"""
|
755
|
+
if filename not in self._associated_file_list:
|
756
|
+
raise ValueError(
|
757
|
+
"The file, {}, does not exist in the model.".format(filename))
|
758
|
+
|
759
|
+
with _open_as_zipfile(io.BytesIO(self._model_buffer)) as zf:
|
760
|
+
return zf.read(filename)
|
761
|
+
|
762
|
+
def get_metadata_buffer(self):
|
763
|
+
"""Get the metadata buffer in bytearray out from the model."""
|
764
|
+
return copy.deepcopy(self._metadata_buffer)
|
765
|
+
|
766
|
+
def get_metadata_json(self):
|
767
|
+
"""Converts the metadata into a json string."""
|
768
|
+
return convert_to_json(self._metadata_buffer)
|
769
|
+
|
770
|
+
def get_packed_associated_file_list(self):
|
771
|
+
"""Returns a list of associated files that are packed in the model.
|
772
|
+
|
773
|
+
Returns:
|
774
|
+
A name list of associated files.
|
775
|
+
"""
|
776
|
+
return copy.deepcopy(self._associated_file_list)
|
777
|
+
|
778
|
+
@classmethod
|
779
|
+
def _parse_packed_associated_file_list(cls, model_buf):
|
780
|
+
"""Gets a list of associated files packed to the model file.
|
781
|
+
|
782
|
+
Args:
|
783
|
+
model_buf: valid file buffer.
|
784
|
+
|
785
|
+
Returns:
|
786
|
+
List of packed associated files.
|
787
|
+
"""
|
788
|
+
|
789
|
+
try:
|
790
|
+
with _open_as_zipfile(io.BytesIO(model_buf)) as zf:
|
791
|
+
return zf.namelist()
|
792
|
+
except zipfile.BadZipFile:
|
793
|
+
return []
|
794
|
+
|
795
|
+
|
796
|
+
def _get_custom_metadata(metadata_buffer: bytes, name: str):
|
797
|
+
"""Gets the custom metadata in metadata_buffer based on the name.
|
798
|
+
|
799
|
+
Args:
|
800
|
+
metadata_buffer: valid metadata buffer in bytes.
|
801
|
+
name: custom metadata name.
|
802
|
+
|
803
|
+
Returns:
|
804
|
+
Index of custom metadata, custom metadata flatbuffer. Returns (None, None)
|
805
|
+
if the custom metadata is not found.
|
806
|
+
"""
|
807
|
+
model_metadata = _metadata_fb.ModelMetadata.GetRootAs(metadata_buffer)
|
808
|
+
subgraph = model_metadata.SubgraphMetadata(0)
|
809
|
+
if subgraph is None or subgraph.CustomMetadataIsNone():
|
810
|
+
return None, None
|
811
|
+
|
812
|
+
for i in range(subgraph.CustomMetadataLength()):
|
813
|
+
custom_metadata = subgraph.CustomMetadata(i)
|
814
|
+
if custom_metadata.Name().decode("utf-8") == name:
|
815
|
+
return i, custom_metadata.DataAsNumpy().tobytes()
|
816
|
+
return None, None
|
817
|
+
|
818
|
+
|
819
|
+
# Create an individual method for getting the metadata json file, so that it can
|
820
|
+
# be used as a standalone util.
|
821
|
+
def convert_to_json(
|
822
|
+
metadata_buffer, custom_metadata_schema: Optional[Dict[str, str]] = None
|
823
|
+
) -> str:
|
824
|
+
"""Converts the metadata into a json string.
|
825
|
+
|
826
|
+
Args:
|
827
|
+
metadata_buffer: valid metadata buffer in bytes.
|
828
|
+
custom_metadata_schema: A dict of custom metadata schema, in which key is
|
829
|
+
custom metadata name [1], value is the filepath that defines custom
|
830
|
+
metadata schema. For instance, custom_metadata_schema =
|
831
|
+
{"SEGMENTER_METADATA": "metadata/vision_tasks_metadata_schema.fbs"}. [1]:
|
832
|
+
https://github.com/google/mediapipe/blob/46b5c4012d2ef76c9d92bb0d88a6b107aee83814/mediapipe/tasks/metadata/metadata_schema.fbs#L612
|
833
|
+
|
834
|
+
Returns:
|
835
|
+
Metadata in JSON format.
|
836
|
+
|
837
|
+
Raises:
|
838
|
+
ValueError: error occurred when parsing the metadata schema file.
|
839
|
+
"""
|
840
|
+
opt = _pywrap_flatbuffers.IDLOptions()
|
841
|
+
opt.strict_json = True
|
842
|
+
parser = _pywrap_flatbuffers.Parser(opt)
|
843
|
+
with _open_file(_FLATC_TFLITE_METADATA_SCHEMA_FILE) as f:
|
844
|
+
metadata_schema_content = f.read()
|
845
|
+
if not parser.parse(metadata_schema_content):
|
846
|
+
raise ValueError("Cannot parse metadata schema. Reason: " + parser.error)
|
847
|
+
# Json content which may contain binary custom metadata.
|
848
|
+
raw_json_content = _pywrap_flatbuffers.generate_text(parser, metadata_buffer)
|
849
|
+
if not custom_metadata_schema:
|
850
|
+
return raw_json_content
|
851
|
+
|
852
|
+
json_data = json.loads(raw_json_content)
|
853
|
+
# Gets the custom metadata by name and parse the binary custom metadata into
|
854
|
+
# human readable json content.
|
855
|
+
for name, schema_file in custom_metadata_schema.items():
|
856
|
+
idx, custom_metadata = _get_custom_metadata(metadata_buffer, name)
|
857
|
+
if not custom_metadata:
|
858
|
+
logging.info(
|
859
|
+
"No custom metadata with name %s in metadata flatbuffer.", name
|
860
|
+
)
|
861
|
+
continue
|
862
|
+
_assert_file_exist(schema_file)
|
863
|
+
with _open_file(schema_file, "rb") as f:
|
864
|
+
custom_metadata_schema_content = f.read()
|
865
|
+
if not parser.parse(custom_metadata_schema_content):
|
866
|
+
raise ValueError(
|
867
|
+
"Cannot parse custom metadata schema. Reason: " + parser.error
|
868
|
+
)
|
869
|
+
custom_metadata_json = _pywrap_flatbuffers.generate_text(
|
870
|
+
parser, custom_metadata
|
871
|
+
)
|
872
|
+
json_meta = json_data["subgraph_metadata"][0]["custom_metadata"][idx]
|
873
|
+
json_meta["name"] = name
|
874
|
+
json_meta["data"] = json.loads(custom_metadata_json)
|
875
|
+
return json.dumps(json_data, indent=2)
|
876
|
+
|
877
|
+
|
878
|
+
def _assert_file_exist(filename):
|
879
|
+
"""Checks if a file exists."""
|
880
|
+
if not _exists_file(filename):
|
881
|
+
raise IOError("File, '{0}', does not exist.".format(filename))
|
882
|
+
|
883
|
+
|
884
|
+
def _assert_model_file_identifier(model_file):
|
885
|
+
"""Checks if a model file has the expected TFLite schema identifier."""
|
886
|
+
_assert_file_exist(model_file)
|
887
|
+
with _open_file(model_file, "rb") as f:
|
888
|
+
_assert_model_buffer_identifier(f.read())
|
889
|
+
|
890
|
+
|
891
|
+
def _assert_model_buffer_identifier(model_buf):
|
892
|
+
if not _schema_fb.Model.ModelBufferHasIdentifier(model_buf, 0):
|
893
|
+
raise ValueError(
|
894
|
+
"The model provided does not have the expected identifier, and "
|
895
|
+
"may not be a valid TFLite model.")
|
896
|
+
|
897
|
+
|
898
|
+
def _assert_metadata_buffer_identifier(metadata_buf):
|
899
|
+
"""Checks if a metadata buffer has the expected Metadata schema identifier."""
|
900
|
+
if not _metadata_fb.ModelMetadata.ModelMetadataBufferHasIdentifier(
|
901
|
+
metadata_buf, 0):
|
902
|
+
raise ValueError(
|
903
|
+
"The metadata buffer does not have the expected identifier, and may not"
|
904
|
+
" be a valid TFLite Metadata.")
|
905
|
+
|
906
|
+
|
907
|
+
def get_metadata_buffer(model_buf):
|
908
|
+
"""Returns the metadata in the model file as a buffer.
|
909
|
+
|
910
|
+
Args:
|
911
|
+
model_buf: valid buffer of the model file.
|
912
|
+
|
913
|
+
Returns:
|
914
|
+
Metadata buffer. Returns `None` if the model does not have metadata.
|
915
|
+
"""
|
916
|
+
tflite_model = _schema_fb.Model.GetRootAsModel(model_buf, 0)
|
917
|
+
|
918
|
+
# Gets metadata from the model file.
|
919
|
+
for i in range(tflite_model.MetadataLength()):
|
920
|
+
meta = tflite_model.Metadata(i)
|
921
|
+
if meta.Name().decode("utf-8") == MetadataPopulator.METADATA_FIELD_NAME:
|
922
|
+
buffer_index = meta.Buffer()
|
923
|
+
metadata = tflite_model.Buffers(buffer_index)
|
924
|
+
if metadata.DataLength() == 0:
|
925
|
+
continue
|
926
|
+
return metadata.DataAsNumpy().tobytes()
|
927
|
+
|
928
|
+
return None
|