mediapipe-nightly 0.10.21.post20241223__cp310-cp310-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-310-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-310-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-310-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.post20241223.dist-info/LICENSE +218 -0
- mediapipe_nightly-0.10.21.post20241223.dist-info/METADATA +199 -0
- mediapipe_nightly-0.10.21.post20241223.dist-info/RECORD +593 -0
- mediapipe_nightly-0.10.21.post20241223.dist-info/WHEEL +5 -0
- mediapipe_nightly-0.10.21.post20241223.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,1166 @@
|
|
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
|
+
"""Helper classes for common model metadata information."""
|
16
|
+
|
17
|
+
import abc
|
18
|
+
import collections
|
19
|
+
import csv
|
20
|
+
import enum
|
21
|
+
import os
|
22
|
+
from typing import List, Optional, Type, Union
|
23
|
+
|
24
|
+
from mediapipe.tasks.metadata import metadata_schema_py_generated as _metadata_fb
|
25
|
+
from mediapipe.tasks.metadata import schema_py_generated as _schema_fb
|
26
|
+
from mediapipe.tasks.python.metadata.metadata_writers import writer_utils
|
27
|
+
|
28
|
+
# Min and max values for UINT8 tensors.
|
29
|
+
_MIN_UINT8 = 0
|
30
|
+
_MAX_UINT8 = 255
|
31
|
+
|
32
|
+
# Default description for vocabulary files.
|
33
|
+
_VOCAB_FILE_DESCRIPTION = ("Vocabulary file to convert natural language "
|
34
|
+
"words to embedding vectors.")
|
35
|
+
|
36
|
+
|
37
|
+
class GeneralMd:
|
38
|
+
"""A container for common metadata information of a model.
|
39
|
+
|
40
|
+
Attributes:
|
41
|
+
name: name of the model.
|
42
|
+
version: version of the model.
|
43
|
+
description: description of what the model does.
|
44
|
+
author: author of the model.
|
45
|
+
licenses: licenses of the model.
|
46
|
+
"""
|
47
|
+
|
48
|
+
def __init__(self,
|
49
|
+
name: Optional[str] = None,
|
50
|
+
version: Optional[str] = None,
|
51
|
+
description: Optional[str] = None,
|
52
|
+
author: Optional[str] = None,
|
53
|
+
licenses: Optional[str] = None) -> None:
|
54
|
+
self.name = name
|
55
|
+
self.version = version
|
56
|
+
self.description = description
|
57
|
+
self.author = author
|
58
|
+
self.licenses = licenses
|
59
|
+
|
60
|
+
def create_metadata(self) -> _metadata_fb.ModelMetadataT:
|
61
|
+
"""Creates the model metadata based on the general model information.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
A Flatbuffers Python object of the model metadata.
|
65
|
+
"""
|
66
|
+
model_metadata = _metadata_fb.ModelMetadataT()
|
67
|
+
model_metadata.name = self.name
|
68
|
+
model_metadata.version = self.version
|
69
|
+
model_metadata.description = self.description
|
70
|
+
model_metadata.author = self.author
|
71
|
+
model_metadata.license = self.licenses
|
72
|
+
return model_metadata
|
73
|
+
|
74
|
+
|
75
|
+
class AssociatedFileMd:
|
76
|
+
"""A container for common associated file metadata information.
|
77
|
+
|
78
|
+
Attributes:
|
79
|
+
file_path: path to the associated file.
|
80
|
+
description: description of the associated file.
|
81
|
+
file_type: file type of the associated file [1].
|
82
|
+
locale: locale of the associated file [2].
|
83
|
+
[1]:
|
84
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L77
|
85
|
+
[2]:
|
86
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L176
|
87
|
+
"""
|
88
|
+
|
89
|
+
def __init__(
|
90
|
+
self,
|
91
|
+
file_path: str,
|
92
|
+
description: Optional[str] = None,
|
93
|
+
file_type: Optional[int] = _metadata_fb.AssociatedFileType.UNKNOWN,
|
94
|
+
locale: Optional[str] = None) -> None:
|
95
|
+
self.file_path = file_path
|
96
|
+
self.description = description
|
97
|
+
self.file_type = file_type
|
98
|
+
self.locale = locale
|
99
|
+
|
100
|
+
def create_metadata(self) -> _metadata_fb.AssociatedFileT:
|
101
|
+
"""Creates the associated file metadata.
|
102
|
+
|
103
|
+
Returns:
|
104
|
+
A Flatbuffers Python object of the associated file metadata.
|
105
|
+
"""
|
106
|
+
file_metadata = _metadata_fb.AssociatedFileT()
|
107
|
+
file_metadata.name = os.path.basename(self.file_path)
|
108
|
+
file_metadata.description = self.description
|
109
|
+
file_metadata.type = self.file_type
|
110
|
+
file_metadata.locale = self.locale
|
111
|
+
return file_metadata
|
112
|
+
|
113
|
+
|
114
|
+
class LabelFileMd(AssociatedFileMd):
|
115
|
+
"""A container for label file metadata information."""
|
116
|
+
|
117
|
+
_LABEL_FILE_DESCRIPTION = ("Labels for categories that the model can "
|
118
|
+
"recognize.")
|
119
|
+
_FILE_TYPE = _metadata_fb.AssociatedFileType.TENSOR_AXIS_LABELS
|
120
|
+
|
121
|
+
def __init__(self, file_path: str, locale: Optional[str] = None) -> None:
|
122
|
+
"""Creates a LabelFileMd object.
|
123
|
+
|
124
|
+
Args:
|
125
|
+
file_path: file_path of the label file.
|
126
|
+
locale: locale of the label file [1].
|
127
|
+
[1]:
|
128
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L176
|
129
|
+
"""
|
130
|
+
super().__init__(file_path, self._LABEL_FILE_DESCRIPTION, self._FILE_TYPE,
|
131
|
+
locale)
|
132
|
+
|
133
|
+
|
134
|
+
class ScoreCalibrationMd:
|
135
|
+
"""A container for score calibration [1] metadata information.
|
136
|
+
|
137
|
+
[1]:
|
138
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L456
|
139
|
+
"""
|
140
|
+
|
141
|
+
_SCORE_CALIBRATION_FILE_DESCRIPTION = (
|
142
|
+
"Contains sigmoid-based score calibration parameters. The main purposes "
|
143
|
+
"of score calibration is to make scores across classes comparable, so "
|
144
|
+
"that a common threshold can be used for all output classes.")
|
145
|
+
_FILE_TYPE = _metadata_fb.AssociatedFileType.TENSOR_AXIS_SCORE_CALIBRATION
|
146
|
+
|
147
|
+
def __init__(self,
|
148
|
+
score_transformation_type: _metadata_fb.ScoreTransformationType,
|
149
|
+
default_score: float, file_path: str) -> None:
|
150
|
+
"""Creates a ScoreCalibrationMd object.
|
151
|
+
|
152
|
+
Args:
|
153
|
+
score_transformation_type: type of the function used for transforming the
|
154
|
+
uncalibrated score before applying score calibration.
|
155
|
+
default_score: the default calibrated score to apply if the uncalibrated
|
156
|
+
score is below min_score or if no parameters were specified for a given
|
157
|
+
index.
|
158
|
+
file_path: file_path of the score calibration file [1].
|
159
|
+
[1]:
|
160
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L133
|
161
|
+
|
162
|
+
Raises:
|
163
|
+
ValueError: if the score_calibration file is malformed.
|
164
|
+
"""
|
165
|
+
self._score_transformation_type = score_transformation_type
|
166
|
+
self._default_score = default_score
|
167
|
+
self._file_path = file_path
|
168
|
+
|
169
|
+
# Sanity check the score calibration file.
|
170
|
+
with open(self._file_path) as calibration_file:
|
171
|
+
csv_reader = csv.reader(calibration_file, delimiter=",")
|
172
|
+
for row in csv_reader:
|
173
|
+
if row and len(row) != 3 and len(row) != 4:
|
174
|
+
raise ValueError(
|
175
|
+
f"Expected empty lines or 3 or 4 parameters per line in score"
|
176
|
+
f" calibration file, but got {len(row)}.")
|
177
|
+
|
178
|
+
if row and float(row[0]) < 0:
|
179
|
+
raise ValueError(
|
180
|
+
f"Expected scale to be a non-negative value, but got "
|
181
|
+
f"{float(row[0])}.")
|
182
|
+
|
183
|
+
def create_metadata(self) -> _metadata_fb.ProcessUnitT:
|
184
|
+
"""Creates the score calibration metadata based on the information.
|
185
|
+
|
186
|
+
Returns:
|
187
|
+
A Flatbuffers Python object of the score calibration metadata.
|
188
|
+
"""
|
189
|
+
score_calibration = _metadata_fb.ProcessUnitT()
|
190
|
+
score_calibration.optionsType = (
|
191
|
+
_metadata_fb.ProcessUnitOptions.ScoreCalibrationOptions)
|
192
|
+
options = _metadata_fb.ScoreCalibrationOptionsT()
|
193
|
+
options.scoreTransformation = self._score_transformation_type
|
194
|
+
options.defaultScore = self._default_score
|
195
|
+
score_calibration.options = options
|
196
|
+
return score_calibration
|
197
|
+
|
198
|
+
def create_score_calibration_file_md(self) -> AssociatedFileMd:
|
199
|
+
return AssociatedFileMd(self._file_path,
|
200
|
+
self._SCORE_CALIBRATION_FILE_DESCRIPTION,
|
201
|
+
self._FILE_TYPE)
|
202
|
+
|
203
|
+
|
204
|
+
class ScoreThresholdingMd:
|
205
|
+
"""A container for score thresholding [1] metadata information.
|
206
|
+
|
207
|
+
[1]:
|
208
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L468
|
209
|
+
"""
|
210
|
+
|
211
|
+
def __init__(self, global_score_threshold: float) -> None:
|
212
|
+
"""Creates a ScoreThresholdingMd object.
|
213
|
+
|
214
|
+
Args:
|
215
|
+
global_score_threshold: The recommended global threshold below which
|
216
|
+
results are considered low-confidence and should be filtered out.
|
217
|
+
"""
|
218
|
+
self._global_score_threshold = global_score_threshold
|
219
|
+
|
220
|
+
def create_metadata(self) -> _metadata_fb.ProcessUnitT:
|
221
|
+
"""Creates the score thresholding metadata based on the information.
|
222
|
+
|
223
|
+
Returns:
|
224
|
+
A Flatbuffers Python object of the score thresholding metadata.
|
225
|
+
"""
|
226
|
+
score_thresholding = _metadata_fb.ProcessUnitT()
|
227
|
+
score_thresholding.optionsType = (
|
228
|
+
_metadata_fb.ProcessUnitOptions.ScoreThresholdingOptions)
|
229
|
+
options = _metadata_fb.ScoreThresholdingOptionsT()
|
230
|
+
options.globalScoreThreshold = self._global_score_threshold
|
231
|
+
score_thresholding.options = options
|
232
|
+
return score_thresholding
|
233
|
+
|
234
|
+
|
235
|
+
class RegexTokenizerMd:
|
236
|
+
"""A container for the Regex tokenizer [1] metadata information.
|
237
|
+
|
238
|
+
[1]:
|
239
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L500
|
240
|
+
"""
|
241
|
+
|
242
|
+
def __init__(self, delim_regex_pattern: str, vocab_file_path: str):
|
243
|
+
"""Initializes a RegexTokenizerMd object.
|
244
|
+
|
245
|
+
Args:
|
246
|
+
delim_regex_pattern: the regular expression to segment strings and create
|
247
|
+
tokens.
|
248
|
+
vocab_file_path: path to the vocabulary file.
|
249
|
+
"""
|
250
|
+
self._delim_regex_pattern = delim_regex_pattern
|
251
|
+
self._vocab_file_path = vocab_file_path
|
252
|
+
|
253
|
+
def create_metadata(self) -> _metadata_fb.ProcessUnitT:
|
254
|
+
"""Creates the Regex tokenizer metadata based on the information.
|
255
|
+
|
256
|
+
Returns:
|
257
|
+
A Flatbuffers Python object of the Regex tokenizer metadata.
|
258
|
+
"""
|
259
|
+
vocab = _metadata_fb.AssociatedFileT()
|
260
|
+
vocab.name = self._vocab_file_path
|
261
|
+
vocab.description = _VOCAB_FILE_DESCRIPTION
|
262
|
+
vocab.type = _metadata_fb.AssociatedFileType.VOCABULARY
|
263
|
+
|
264
|
+
# Create the RegexTokenizer.
|
265
|
+
tokenizer = _metadata_fb.ProcessUnitT()
|
266
|
+
tokenizer.optionsType = (
|
267
|
+
_metadata_fb.ProcessUnitOptions.RegexTokenizerOptions)
|
268
|
+
tokenizer.options = _metadata_fb.RegexTokenizerOptionsT()
|
269
|
+
tokenizer.options.delimRegexPattern = self._delim_regex_pattern
|
270
|
+
tokenizer.options.vocabFile = [vocab]
|
271
|
+
return tokenizer
|
272
|
+
|
273
|
+
|
274
|
+
class BertTokenizerMd:
|
275
|
+
"""A container for the Bert tokenizer [1] metadata information.
|
276
|
+
|
277
|
+
[1]:
|
278
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L477
|
279
|
+
"""
|
280
|
+
|
281
|
+
def __init__(self, vocab_file_path: str):
|
282
|
+
"""Initializes a BertTokenizerMd object.
|
283
|
+
|
284
|
+
Args:
|
285
|
+
vocab_file_path: path to the vocabulary file.
|
286
|
+
"""
|
287
|
+
self._vocab_file_path = vocab_file_path
|
288
|
+
|
289
|
+
def create_metadata(self) -> _metadata_fb.ProcessUnitT:
|
290
|
+
"""Creates the Bert tokenizer metadata based on the information.
|
291
|
+
|
292
|
+
Returns:
|
293
|
+
A Flatbuffers Python object of the Bert tokenizer metadata.
|
294
|
+
"""
|
295
|
+
vocab = _metadata_fb.AssociatedFileT()
|
296
|
+
vocab.name = self._vocab_file_path
|
297
|
+
vocab.description = _VOCAB_FILE_DESCRIPTION
|
298
|
+
vocab.type = _metadata_fb.AssociatedFileType.VOCABULARY
|
299
|
+
tokenizer = _metadata_fb.ProcessUnitT()
|
300
|
+
tokenizer.optionsType = _metadata_fb.ProcessUnitOptions.BertTokenizerOptions
|
301
|
+
tokenizer.options = _metadata_fb.BertTokenizerOptionsT()
|
302
|
+
tokenizer.options.vocabFile = [vocab]
|
303
|
+
return tokenizer
|
304
|
+
|
305
|
+
|
306
|
+
class SentencePieceTokenizerMd:
|
307
|
+
"""A container for the sentence piece tokenizer [1] metadata information.
|
308
|
+
|
309
|
+
[1]:
|
310
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L485
|
311
|
+
"""
|
312
|
+
|
313
|
+
_SP_MODEL_DESCRIPTION = "The sentence piece model file."
|
314
|
+
_SP_VOCAB_FILE_DESCRIPTION = _VOCAB_FILE_DESCRIPTION + (
|
315
|
+
" This file is optional during tokenization, while the sentence piece "
|
316
|
+
"model is mandatory.")
|
317
|
+
|
318
|
+
def __init__(self,
|
319
|
+
sentence_piece_model_path: str,
|
320
|
+
vocab_file_path: Optional[str] = None):
|
321
|
+
"""Initializes a SentencePieceTokenizerMd object.
|
322
|
+
|
323
|
+
Args:
|
324
|
+
sentence_piece_model_path: path to the sentence piece model file.
|
325
|
+
vocab_file_path: path to the vocabulary file.
|
326
|
+
"""
|
327
|
+
self._sentence_piece_model_path = sentence_piece_model_path
|
328
|
+
self._vocab_file_path = vocab_file_path
|
329
|
+
|
330
|
+
def create_metadata(self) -> _metadata_fb.ProcessUnitT:
|
331
|
+
"""Creates the sentence piece tokenizer metadata based on the information.
|
332
|
+
|
333
|
+
Returns:
|
334
|
+
A Flatbuffers Python object of the sentence piece tokenizer metadata.
|
335
|
+
"""
|
336
|
+
tokenizer = _metadata_fb.ProcessUnitT()
|
337
|
+
tokenizer.optionsType = (
|
338
|
+
_metadata_fb.ProcessUnitOptions.SentencePieceTokenizerOptions)
|
339
|
+
tokenizer.options = _metadata_fb.SentencePieceTokenizerOptionsT()
|
340
|
+
|
341
|
+
sp_model = _metadata_fb.AssociatedFileT()
|
342
|
+
sp_model.name = self._sentence_piece_model_path
|
343
|
+
sp_model.description = self._SP_MODEL_DESCRIPTION
|
344
|
+
tokenizer.options.sentencePieceModel = [sp_model]
|
345
|
+
if self._vocab_file_path:
|
346
|
+
vocab = _metadata_fb.AssociatedFileT()
|
347
|
+
vocab.name = self._vocab_file_path
|
348
|
+
vocab.description = self._SP_VOCAB_FILE_DESCRIPTION
|
349
|
+
vocab.type = _metadata_fb.AssociatedFileType.VOCABULARY
|
350
|
+
tokenizer.options.vocabFile = [vocab]
|
351
|
+
return tokenizer
|
352
|
+
|
353
|
+
|
354
|
+
class ValueRangeMd:
|
355
|
+
"""A container for value range metadata information."""
|
356
|
+
|
357
|
+
def __init__(self, min_value: int, max_value: int) -> None:
|
358
|
+
self.min_value = min_value
|
359
|
+
self.max_value = max_value
|
360
|
+
|
361
|
+
def create_metadata(self) -> _metadata_fb.ValueRangeT:
|
362
|
+
"""Creates the value range metadata based on the information."""
|
363
|
+
value_range_metadata = _metadata_fb.ValueRangeT()
|
364
|
+
value_range_metadata.min = self.min_value
|
365
|
+
value_range_metadata.max = self.max_value
|
366
|
+
return value_range_metadata
|
367
|
+
|
368
|
+
|
369
|
+
class TensorMd:
|
370
|
+
"""A container for common tensor metadata information.
|
371
|
+
|
372
|
+
Attributes:
|
373
|
+
name: name of the tensor.
|
374
|
+
description: description of what the tensor is.
|
375
|
+
min_values: per-channel minimum value of the tensor.
|
376
|
+
max_values: per-channel maximum value of the tensor.
|
377
|
+
content_type: content_type of the tensor.
|
378
|
+
associated_files: information of the associated files in the tensor.
|
379
|
+
tensor_name: name of the corresponding tensor [1] in the TFLite model. It is
|
380
|
+
used to locate the corresponding tensor and decide the order of the tensor
|
381
|
+
metadata [2] when populating model metadata.
|
382
|
+
content_range_md: information of content range [3].
|
383
|
+
[1]:
|
384
|
+
https://github.com/tensorflow/tensorflow/blob/cb67fef35567298b40ac166b0581cd8ad68e5a3a/tensorflow/lite/schema/schema.fbs#L1129-L1136
|
385
|
+
[2]:
|
386
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L623-L640
|
387
|
+
[3]:
|
388
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L385
|
389
|
+
"""
|
390
|
+
|
391
|
+
def __init__(
|
392
|
+
self,
|
393
|
+
name: Optional[str] = None,
|
394
|
+
description: Optional[str] = None,
|
395
|
+
min_values: Optional[List[float]] = None,
|
396
|
+
max_values: Optional[List[float]] = None,
|
397
|
+
content_type: int = _metadata_fb.ContentProperties.FeatureProperties,
|
398
|
+
associated_files: Optional[List[Type[AssociatedFileMd]]] = None,
|
399
|
+
tensor_name: Optional[str] = None,
|
400
|
+
content_range_md: Optional[ValueRangeMd] = None,
|
401
|
+
) -> None:
|
402
|
+
self.name = name
|
403
|
+
self.description = description
|
404
|
+
self.min_values = min_values
|
405
|
+
self.max_values = max_values
|
406
|
+
self.content_type = content_type
|
407
|
+
self.associated_files = associated_files
|
408
|
+
self.tensor_name = tensor_name
|
409
|
+
self.content_range_md = content_range_md
|
410
|
+
|
411
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
412
|
+
"""Creates the input tensor metadata based on the information.
|
413
|
+
|
414
|
+
Returns:
|
415
|
+
A Flatbuffers Python object of the input metadata.
|
416
|
+
"""
|
417
|
+
tensor_metadata = _metadata_fb.TensorMetadataT()
|
418
|
+
tensor_metadata.name = self.name
|
419
|
+
tensor_metadata.description = self.description
|
420
|
+
|
421
|
+
# Create min and max values
|
422
|
+
stats = _metadata_fb.StatsT()
|
423
|
+
stats.max = self.max_values
|
424
|
+
stats.min = self.min_values
|
425
|
+
tensor_metadata.stats = stats
|
426
|
+
|
427
|
+
# Create content properties
|
428
|
+
content = _metadata_fb.ContentT()
|
429
|
+
if self.content_type is _metadata_fb.ContentProperties.FeatureProperties:
|
430
|
+
content.contentProperties = _metadata_fb.FeaturePropertiesT()
|
431
|
+
elif self.content_type is _metadata_fb.ContentProperties.ImageProperties:
|
432
|
+
content.contentProperties = _metadata_fb.ImagePropertiesT()
|
433
|
+
elif self.content_type is (
|
434
|
+
_metadata_fb.ContentProperties.BoundingBoxProperties):
|
435
|
+
content.contentProperties = _metadata_fb.BoundingBoxPropertiesT()
|
436
|
+
elif self.content_type is _metadata_fb.ContentProperties.AudioProperties:
|
437
|
+
content.contentProperties = _metadata_fb.AudioPropertiesT()
|
438
|
+
|
439
|
+
content.contentPropertiesType = self.content_type
|
440
|
+
tensor_metadata.content = content
|
441
|
+
if self.content_range_md:
|
442
|
+
tensor_metadata.content.range = self.content_range_md.create_metadata()
|
443
|
+
|
444
|
+
# TODO: check if multiple label files have populated locale.
|
445
|
+
# Create associated files
|
446
|
+
if self.associated_files:
|
447
|
+
tensor_metadata.associatedFiles = [
|
448
|
+
file.create_metadata() for file in self.associated_files
|
449
|
+
]
|
450
|
+
return tensor_metadata
|
451
|
+
|
452
|
+
|
453
|
+
class InputImageTensorMd(TensorMd):
|
454
|
+
"""A container for input image tensor metadata information.
|
455
|
+
|
456
|
+
Attributes:
|
457
|
+
norm_mean: the mean value used in tensor normalization [1].
|
458
|
+
norm_std: the std value used in the tensor normalization [1]. norm_mean and
|
459
|
+
norm_std must have the same dimension.
|
460
|
+
color_space_type: the color space type of the input image [2].
|
461
|
+
[1]:
|
462
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L389
|
463
|
+
[2]:
|
464
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L198
|
465
|
+
"""
|
466
|
+
|
467
|
+
# Min and max float values for image pixels.
|
468
|
+
_MIN_PIXEL = 0.0
|
469
|
+
_MAX_PIXEL = 255.0
|
470
|
+
|
471
|
+
def __init__(
|
472
|
+
self,
|
473
|
+
name: Optional[str] = None,
|
474
|
+
description: Optional[str] = None,
|
475
|
+
norm_mean: Optional[List[float]] = None,
|
476
|
+
norm_std: Optional[List[float]] = None,
|
477
|
+
color_space_type: Optional[int] = _metadata_fb.ColorSpaceType.UNKNOWN,
|
478
|
+
tensor_type: Optional["_schema_fb.TensorType"] = None) -> None:
|
479
|
+
"""Initializes the instance of InputImageTensorMd.
|
480
|
+
|
481
|
+
Args:
|
482
|
+
name: name of the tensor.
|
483
|
+
description: description of what the tensor is.
|
484
|
+
norm_mean: the mean value used in tensor normalization [1].
|
485
|
+
norm_std: the std value used in the tensor normalization [1]. norm_mean
|
486
|
+
and norm_std must have the same dimension.
|
487
|
+
color_space_type: the color space type of the input image [2].
|
488
|
+
tensor_type: data type of the tensor.
|
489
|
+
[1]:
|
490
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L389
|
491
|
+
[2]:
|
492
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L198
|
493
|
+
|
494
|
+
Raises:
|
495
|
+
ValueError: if norm_mean and norm_std have different dimensions.
|
496
|
+
"""
|
497
|
+
if norm_std and norm_mean and len(norm_std) != len(norm_mean):
|
498
|
+
raise ValueError(
|
499
|
+
f"norm_mean and norm_std are expected to be the same dim. But got "
|
500
|
+
f"{len(norm_mean)} and {len(norm_std)}")
|
501
|
+
|
502
|
+
if tensor_type is _schema_fb.TensorType.UINT8:
|
503
|
+
min_values = [_MIN_UINT8]
|
504
|
+
max_values = [_MAX_UINT8]
|
505
|
+
elif tensor_type is _schema_fb.TensorType.FLOAT32 and norm_std and norm_mean:
|
506
|
+
min_values = [
|
507
|
+
float(self._MIN_PIXEL - mean) / std
|
508
|
+
for mean, std in zip(norm_mean, norm_std)
|
509
|
+
]
|
510
|
+
max_values = [
|
511
|
+
float(self._MAX_PIXEL - mean) / std
|
512
|
+
for mean, std in zip(norm_mean, norm_std)
|
513
|
+
]
|
514
|
+
else:
|
515
|
+
# Uint8 and Float32 are the two major types currently. And Task library
|
516
|
+
# doesn't support other types so far.
|
517
|
+
min_values = None
|
518
|
+
max_values = None
|
519
|
+
|
520
|
+
super().__init__(name, description, min_values, max_values,
|
521
|
+
_metadata_fb.ContentProperties.ImageProperties)
|
522
|
+
self.norm_mean = norm_mean
|
523
|
+
self.norm_std = norm_std
|
524
|
+
self.color_space_type = color_space_type
|
525
|
+
|
526
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
527
|
+
"""Creates the input image metadata based on the information.
|
528
|
+
|
529
|
+
Returns:
|
530
|
+
A Flatbuffers Python object of the input image metadata.
|
531
|
+
"""
|
532
|
+
tensor_metadata = super().create_metadata()
|
533
|
+
tensor_metadata.content.contentProperties.colorSpace = self.color_space_type
|
534
|
+
# Create normalization parameters
|
535
|
+
if self.norm_mean and self.norm_std:
|
536
|
+
normalization = _metadata_fb.ProcessUnitT()
|
537
|
+
normalization.optionsType = (
|
538
|
+
_metadata_fb.ProcessUnitOptions.NormalizationOptions)
|
539
|
+
normalization.options = _metadata_fb.NormalizationOptionsT()
|
540
|
+
normalization.options.mean = self.norm_mean
|
541
|
+
normalization.options.std = self.norm_std
|
542
|
+
tensor_metadata.processUnits = [normalization]
|
543
|
+
return tensor_metadata
|
544
|
+
|
545
|
+
|
546
|
+
class InputTextTensorMd(TensorMd):
|
547
|
+
"""A container for the input text tensor metadata information.
|
548
|
+
|
549
|
+
Attributes:
|
550
|
+
tokenizer_md: information of the tokenizer in the input text tensor, if any.
|
551
|
+
"""
|
552
|
+
|
553
|
+
def __init__(self,
|
554
|
+
name: Optional[str] = None,
|
555
|
+
description: Optional[str] = None,
|
556
|
+
tokenizer_md: Optional[RegexTokenizerMd] = None):
|
557
|
+
"""Initializes the instance of InputTextTensorMd.
|
558
|
+
|
559
|
+
Args:
|
560
|
+
name: name of the tensor.
|
561
|
+
description: description of what the tensor is.
|
562
|
+
tokenizer_md: information of the tokenizer in the input text tensor, if
|
563
|
+
any. Only `RegexTokenizer` [1] is currently supported. If the tokenizer
|
564
|
+
is `BertTokenizer` [2] or `SentencePieceTokenizer` [3], refer to
|
565
|
+
`BertInputTensorsMd` class.
|
566
|
+
[1]:
|
567
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L500
|
568
|
+
[2]:
|
569
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L477
|
570
|
+
[3]:
|
571
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L485
|
572
|
+
"""
|
573
|
+
super().__init__(name, description)
|
574
|
+
self.tokenizer_md = tokenizer_md
|
575
|
+
|
576
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
577
|
+
"""Creates the input text metadata based on the information.
|
578
|
+
|
579
|
+
Returns:
|
580
|
+
A Flatbuffers Python object of the input text metadata.
|
581
|
+
|
582
|
+
Raises:
|
583
|
+
ValueError: if the type of tokenizer_md is unsupported.
|
584
|
+
"""
|
585
|
+
if not isinstance(self.tokenizer_md, (type(None), RegexTokenizerMd)):
|
586
|
+
raise ValueError(
|
587
|
+
f"The type of tokenizer_options, {type(self.tokenizer_md)}, is "
|
588
|
+
f"unsupported")
|
589
|
+
|
590
|
+
tensor_metadata = super().create_metadata()
|
591
|
+
if self.tokenizer_md:
|
592
|
+
tensor_metadata.processUnits = [self.tokenizer_md.create_metadata()]
|
593
|
+
return tensor_metadata
|
594
|
+
|
595
|
+
|
596
|
+
def _get_file_paths(files: List[_metadata_fb.AssociatedFileT]) -> List[str]:
|
597
|
+
"""Gets file paths from a list of associated files."""
|
598
|
+
if not files:
|
599
|
+
return []
|
600
|
+
return [file.name for file in files]
|
601
|
+
|
602
|
+
|
603
|
+
def _get_tokenizer_associated_files(
|
604
|
+
tokenizer_options: Optional[
|
605
|
+
Union[_metadata_fb.BertTokenizerOptionsT,
|
606
|
+
_metadata_fb.SentencePieceTokenizerOptionsT]]
|
607
|
+
) -> List[str]:
|
608
|
+
"""Gets a list of associated files packed in the tokenizer_options.
|
609
|
+
|
610
|
+
Args:
|
611
|
+
tokenizer_options: a tokenizer metadata object. Support the following
|
612
|
+
tokenizer types:
|
613
|
+
1. BertTokenizerOptions:
|
614
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L477
|
615
|
+
2. SentencePieceTokenizerOptions:
|
616
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L485
|
617
|
+
|
618
|
+
Returns:
|
619
|
+
A list of associated files included in tokenizer_options.
|
620
|
+
"""
|
621
|
+
|
622
|
+
if not tokenizer_options:
|
623
|
+
return []
|
624
|
+
|
625
|
+
if isinstance(tokenizer_options, _metadata_fb.BertTokenizerOptionsT):
|
626
|
+
return _get_file_paths(tokenizer_options.vocabFile)
|
627
|
+
elif isinstance(tokenizer_options,
|
628
|
+
_metadata_fb.SentencePieceTokenizerOptionsT):
|
629
|
+
return _get_file_paths(tokenizer_options.vocabFile) + _get_file_paths(
|
630
|
+
tokenizer_options.sentencePieceModel)
|
631
|
+
else:
|
632
|
+
return []
|
633
|
+
|
634
|
+
|
635
|
+
class BertInputTensorsMd:
|
636
|
+
"""A container for the input tensor metadata information of Bert models."""
|
637
|
+
|
638
|
+
_IDS_NAME = "ids"
|
639
|
+
_IDS_DESCRIPTION = "Tokenized ids of the input text."
|
640
|
+
_MASK_NAME = "mask"
|
641
|
+
_MASK_DESCRIPTION = ("Mask with 1 for real tokens and 0 for padding "
|
642
|
+
"tokens.")
|
643
|
+
_SEGMENT_IDS_NAME = "segment_ids"
|
644
|
+
_SEGMENT_IDS_DESCRIPTION = (
|
645
|
+
"0 for the first sequence, 1 for the second sequence if exists.")
|
646
|
+
|
647
|
+
def __init__(self,
|
648
|
+
model_buffer: bytearray,
|
649
|
+
ids_name: str,
|
650
|
+
mask_name: str,
|
651
|
+
segment_name: str,
|
652
|
+
tokenizer_md: Union[None, BertTokenizerMd,
|
653
|
+
SentencePieceTokenizerMd] = None):
|
654
|
+
"""Initializes a BertInputTensorsMd object.
|
655
|
+
|
656
|
+
`ids_name`, `mask_name`, and `segment_name` correspond to the `Tensor.name`
|
657
|
+
in the TFLite schema, which help to determine the tensor order when
|
658
|
+
populating metadata.
|
659
|
+
|
660
|
+
Args:
|
661
|
+
model_buffer: valid buffer of the model file.
|
662
|
+
ids_name: name of the ids tensor, which represents the tokenized ids of
|
663
|
+
the input text.
|
664
|
+
mask_name: name of the mask tensor, which represents the mask with `1` for
|
665
|
+
real tokens and `0` for padding tokens.
|
666
|
+
segment_name: name of the segment ids tensor, where `0` stands for the
|
667
|
+
first sequence, and `1` stands for the second sequence if exists.
|
668
|
+
tokenizer_md: information of the tokenizer used to process the input
|
669
|
+
string, if any. Supported tokenizers are: `BertTokenizer` [1] and
|
670
|
+
`SentencePieceTokenizer` [2]. If the tokenizer is `RegexTokenizer` [3],
|
671
|
+
refer to `InputTensorsMd`.
|
672
|
+
[1]:
|
673
|
+
https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L436
|
674
|
+
[2]:
|
675
|
+
https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L473
|
676
|
+
[3]:
|
677
|
+
https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L475
|
678
|
+
"""
|
679
|
+
# Verify that tflite_input_names (read from the model) and
|
680
|
+
# input_name (collected from users) are aligned.
|
681
|
+
tflite_input_names = writer_utils.get_input_tensor_names(model_buffer)
|
682
|
+
input_names = [ids_name, mask_name, segment_name]
|
683
|
+
if collections.Counter(tflite_input_names) != collections.Counter(
|
684
|
+
input_names):
|
685
|
+
raise ValueError(
|
686
|
+
f"The input tensor names ({input_names}) do not match the tensor "
|
687
|
+
f"names read from the model ({tflite_input_names}).")
|
688
|
+
|
689
|
+
ids_md = TensorMd(
|
690
|
+
name=self._IDS_NAME,
|
691
|
+
description=self._IDS_DESCRIPTION,
|
692
|
+
tensor_name=ids_name)
|
693
|
+
|
694
|
+
mask_md = TensorMd(
|
695
|
+
name=self._MASK_NAME,
|
696
|
+
description=self._MASK_DESCRIPTION,
|
697
|
+
tensor_name=mask_name)
|
698
|
+
|
699
|
+
segment_ids_md = TensorMd(
|
700
|
+
name=self._SEGMENT_IDS_NAME,
|
701
|
+
description=self._SEGMENT_IDS_DESCRIPTION,
|
702
|
+
tensor_name=segment_name)
|
703
|
+
|
704
|
+
self._input_md = [ids_md, mask_md, segment_ids_md]
|
705
|
+
|
706
|
+
if not isinstance(tokenizer_md,
|
707
|
+
(type(None), BertTokenizerMd, SentencePieceTokenizerMd)):
|
708
|
+
raise ValueError(
|
709
|
+
f"The type of tokenizer_options, {type(tokenizer_md)}, is unsupported"
|
710
|
+
)
|
711
|
+
|
712
|
+
self._tokenizer_md = tokenizer_md
|
713
|
+
|
714
|
+
def create_input_process_unit_metadata(
|
715
|
+
self) -> List[_metadata_fb.ProcessUnitT]:
|
716
|
+
"""Creates the input process unit metadata."""
|
717
|
+
if self._tokenizer_md:
|
718
|
+
return [self._tokenizer_md.create_metadata()]
|
719
|
+
else:
|
720
|
+
return []
|
721
|
+
|
722
|
+
def get_tokenizer_associated_files(self) -> List[str]:
|
723
|
+
"""Gets the associated files that are packed in the tokenizer."""
|
724
|
+
if self._tokenizer_md:
|
725
|
+
return _get_tokenizer_associated_files(
|
726
|
+
self._tokenizer_md.create_metadata().options)
|
727
|
+
else:
|
728
|
+
return []
|
729
|
+
|
730
|
+
@property
|
731
|
+
def input_md(self) -> List[TensorMd]:
|
732
|
+
return self._input_md
|
733
|
+
|
734
|
+
|
735
|
+
class ClassificationTensorMd(TensorMd):
|
736
|
+
"""A container for the classification tensor metadata information.
|
737
|
+
|
738
|
+
Attributes:
|
739
|
+
label_files: information of the label files [1] in the classification
|
740
|
+
tensor.
|
741
|
+
score_calibration_md: information of the score calibration operation [2] in
|
742
|
+
the classification tensor.
|
743
|
+
score_thresholding_md: information of the score thresholding [3] in the
|
744
|
+
classification tensor.
|
745
|
+
[1]:
|
746
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L99
|
747
|
+
[2]:
|
748
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L456
|
749
|
+
[3]:
|
750
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L468
|
751
|
+
"""
|
752
|
+
|
753
|
+
# Min and max float values for classification results.
|
754
|
+
_MIN_FLOAT = 0.0
|
755
|
+
_MAX_FLOAT = 1.0
|
756
|
+
|
757
|
+
def __init__(
|
758
|
+
self,
|
759
|
+
name: Optional[str] = None,
|
760
|
+
description: Optional[str] = None,
|
761
|
+
label_files: Optional[List[LabelFileMd]] = None,
|
762
|
+
tensor_type: Optional[int] = None,
|
763
|
+
score_calibration_md: Optional[ScoreCalibrationMd] = None,
|
764
|
+
tensor_name: Optional[str] = None,
|
765
|
+
score_thresholding_md: Optional[ScoreThresholdingMd] = None,
|
766
|
+
content_range_md: Optional[ValueRangeMd] = None,
|
767
|
+
) -> None:
|
768
|
+
"""Initializes the instance of ClassificationTensorMd.
|
769
|
+
|
770
|
+
Args:
|
771
|
+
name: name of the tensor.
|
772
|
+
description: description of what the tensor is.
|
773
|
+
label_files: information of the label files [1] in the classification
|
774
|
+
tensor.
|
775
|
+
tensor_type: data type of the tensor.
|
776
|
+
score_calibration_md: information of the score calibration files operation
|
777
|
+
[2] in the classification tensor.
|
778
|
+
tensor_name: name of the corresponding tensor [3] in the TFLite model. It
|
779
|
+
is used to locate the corresponding classification tensor and decide the
|
780
|
+
order of the tensor metadata [4] when populating model metadata.
|
781
|
+
score_thresholding_md: information of the score thresholding [5] in the
|
782
|
+
classification tensor.
|
783
|
+
content_range_md: information of content range [6].
|
784
|
+
[1]:
|
785
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L99
|
786
|
+
[2]:
|
787
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L456
|
788
|
+
[3]:
|
789
|
+
https://github.com/tensorflow/tensorflow/blob/cb67fef35567298b40ac166b0581cd8ad68e5a3a/tensorflow/lite/schema/schema.fbs#L1129-L1136
|
790
|
+
[4]:
|
791
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L623-L640
|
792
|
+
[5]:
|
793
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L468
|
794
|
+
[6]:
|
795
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L385
|
796
|
+
"""
|
797
|
+
self.score_calibration_md = score_calibration_md
|
798
|
+
self.score_thresholding_md = score_thresholding_md
|
799
|
+
|
800
|
+
if tensor_type is _schema_fb.TensorType.UINT8:
|
801
|
+
min_values = [_MIN_UINT8]
|
802
|
+
max_values = [_MAX_UINT8]
|
803
|
+
elif tensor_type is _schema_fb.TensorType.FLOAT32:
|
804
|
+
min_values = [self._MIN_FLOAT]
|
805
|
+
max_values = [self._MAX_FLOAT]
|
806
|
+
else:
|
807
|
+
# Uint8 and Float32 are the two major types currently. And Task library
|
808
|
+
# doesn't support other types so far.
|
809
|
+
min_values = None
|
810
|
+
max_values = None
|
811
|
+
|
812
|
+
associated_files = label_files or []
|
813
|
+
if self.score_calibration_md:
|
814
|
+
associated_files.append(
|
815
|
+
score_calibration_md.create_score_calibration_file_md())
|
816
|
+
|
817
|
+
super().__init__(
|
818
|
+
name,
|
819
|
+
description,
|
820
|
+
min_values,
|
821
|
+
max_values,
|
822
|
+
_metadata_fb.ContentProperties.FeatureProperties,
|
823
|
+
associated_files,
|
824
|
+
tensor_name,
|
825
|
+
content_range_md,
|
826
|
+
)
|
827
|
+
|
828
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
829
|
+
"""Creates the classification tensor metadata based on the information."""
|
830
|
+
tensor_metadata = super().create_metadata()
|
831
|
+
if self.score_calibration_md:
|
832
|
+
tensor_metadata.processUnits = [
|
833
|
+
self.score_calibration_md.create_metadata()
|
834
|
+
]
|
835
|
+
if self.score_thresholding_md:
|
836
|
+
if tensor_metadata.processUnits:
|
837
|
+
tensor_metadata.processUnits.append(
|
838
|
+
self.score_thresholding_md.create_metadata())
|
839
|
+
else:
|
840
|
+
tensor_metadata.processUnits = [
|
841
|
+
self.score_thresholding_md.create_metadata()
|
842
|
+
]
|
843
|
+
return tensor_metadata
|
844
|
+
|
845
|
+
|
846
|
+
class LocationTensorMd(TensorMd):
|
847
|
+
"""A container for the detection location tensor metadata information."""
|
848
|
+
|
849
|
+
# The default order is {left, top, right, bottom}. Denote the order to be
|
850
|
+
# {top, left, bottom, right}.
|
851
|
+
_BOUNDING_BOX_INDEX = (1, 0, 3, 2)
|
852
|
+
|
853
|
+
def __init__(
|
854
|
+
self,
|
855
|
+
name: Optional[str] = None,
|
856
|
+
description: Optional[str] = None,
|
857
|
+
content_range_md: Optional[ValueRangeMd] = None,
|
858
|
+
) -> None:
|
859
|
+
super().__init__(
|
860
|
+
name=name, description=description, content_range_md=content_range_md
|
861
|
+
)
|
862
|
+
|
863
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
864
|
+
"""Creates the detection location tensor metadata."""
|
865
|
+
content = _metadata_fb.ContentT()
|
866
|
+
content.contentPropertiesType = (
|
867
|
+
_metadata_fb.ContentProperties.BoundingBoxProperties
|
868
|
+
)
|
869
|
+
properties = _metadata_fb.BoundingBoxPropertiesT()
|
870
|
+
properties.index = list(self._BOUNDING_BOX_INDEX)
|
871
|
+
properties.type = _metadata_fb.BoundingBoxType.BOUNDARIES
|
872
|
+
properties.coordinateType = _metadata_fb.CoordinateType.RATIO
|
873
|
+
content.contentProperties = properties
|
874
|
+
if self.content_range_md:
|
875
|
+
content.range = self.content_range_md.create_metadata()
|
876
|
+
location_metadata = super().create_metadata()
|
877
|
+
location_metadata.content = content
|
878
|
+
return location_metadata
|
879
|
+
|
880
|
+
|
881
|
+
class CategoryTensorMd(TensorMd):
|
882
|
+
"""A container for the category tensor metadata information."""
|
883
|
+
|
884
|
+
def __init__(
|
885
|
+
self,
|
886
|
+
name: Optional[str] = None,
|
887
|
+
description: Optional[str] = None,
|
888
|
+
label_files: Optional[List[LabelFileMd]] = None,
|
889
|
+
content_range_md: Optional[ValueRangeMd] = None,
|
890
|
+
):
|
891
|
+
"""Initializes a CategoryTensorMd object.
|
892
|
+
|
893
|
+
Args:
|
894
|
+
name: name of the tensor.
|
895
|
+
description: description of what the tensor is.
|
896
|
+
label_files: information of the label files [1] in the category tensor.
|
897
|
+
content_range_md: information of content range [2].
|
898
|
+
[1]:
|
899
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L116
|
900
|
+
[2]:
|
901
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L385
|
902
|
+
"""
|
903
|
+
# In category tensors, label files are in the type of TENSOR_VALUE_LABELS.
|
904
|
+
if label_files:
|
905
|
+
for file in label_files:
|
906
|
+
file.file_type = _metadata_fb.AssociatedFileType.TENSOR_VALUE_LABELS
|
907
|
+
|
908
|
+
super().__init__(
|
909
|
+
name=name,
|
910
|
+
description=description,
|
911
|
+
associated_files=label_files,
|
912
|
+
content_range_md=content_range_md,
|
913
|
+
)
|
914
|
+
|
915
|
+
|
916
|
+
class DetectionOutputTensorsMd:
|
917
|
+
"""A container for the output tensor metadata of detection models."""
|
918
|
+
|
919
|
+
_LOCATION_NAME = "location"
|
920
|
+
_LOCATION_DESCRIPTION = "The locations of the detected boxes."
|
921
|
+
_CATRGORY_NAME = "category"
|
922
|
+
_CATEGORY_DESCRIPTION = "The categories of the detected boxes."
|
923
|
+
_SCORE_NAME = "score"
|
924
|
+
_SCORE_DESCRIPTION = "The scores of the detected boxes."
|
925
|
+
_NUMBER_NAME = "number of detections"
|
926
|
+
_NUMBER_DESCRIPTION = "The number of the detected boxes."
|
927
|
+
_CONTENT_VALUE_DIM = 2
|
928
|
+
|
929
|
+
def __init__(
|
930
|
+
self,
|
931
|
+
model_buffer: bytearray,
|
932
|
+
label_files: Optional[List[LabelFileMd]] = None,
|
933
|
+
score_calibration_md: Optional[ScoreCalibrationMd] = None,
|
934
|
+
) -> None:
|
935
|
+
"""Initializes the instance of DetectionOutputTensorsMd.
|
936
|
+
|
937
|
+
Args:
|
938
|
+
model_buffer: A valid flatbuffer loaded from the TFLite model file.
|
939
|
+
label_files: information of the label files [1] in the classification
|
940
|
+
tensor.
|
941
|
+
score_calibration_md: information of the score calibration files operation
|
942
|
+
[2] in the classification tensor.
|
943
|
+
[1]:
|
944
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L99
|
945
|
+
[2]:
|
946
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L456
|
947
|
+
"""
|
948
|
+
content_range_md = ValueRangeMd(
|
949
|
+
min_value=self._CONTENT_VALUE_DIM, max_value=self._CONTENT_VALUE_DIM
|
950
|
+
)
|
951
|
+
location_md = LocationTensorMd(
|
952
|
+
name=self._LOCATION_NAME,
|
953
|
+
description=self._LOCATION_DESCRIPTION,
|
954
|
+
content_range_md=content_range_md,
|
955
|
+
)
|
956
|
+
category_md = CategoryTensorMd(
|
957
|
+
name=self._CATRGORY_NAME,
|
958
|
+
description=self._CATEGORY_DESCRIPTION,
|
959
|
+
label_files=label_files,
|
960
|
+
content_range_md=content_range_md,
|
961
|
+
)
|
962
|
+
score_md = ClassificationTensorMd(
|
963
|
+
name=self._SCORE_NAME,
|
964
|
+
description=self._SCORE_DESCRIPTION,
|
965
|
+
score_calibration_md=score_calibration_md,
|
966
|
+
content_range_md=content_range_md,
|
967
|
+
)
|
968
|
+
number_md = TensorMd(
|
969
|
+
name=self._NUMBER_NAME, description=self._NUMBER_DESCRIPTION
|
970
|
+
)
|
971
|
+
|
972
|
+
# Get the tensor indices of tflite outputs and then gets the order of the
|
973
|
+
# output metadata by the value of tensor indices. The output tensor indices
|
974
|
+
# follow the order as [location, category, score,# detections]. For
|
975
|
+
# instance, if the output indices are [601, 599, 598, 600], tensor names and
|
976
|
+
# indices aligned as below:
|
977
|
+
# - (598, location)
|
978
|
+
# - (599, category)
|
979
|
+
# - (600, score)
|
980
|
+
# - (601, number of detections)
|
981
|
+
# because of the op's ports of TFLITE_DETECTION_POST_PROCESS
|
982
|
+
# (https://github.com/tensorflow/tensorflow/blob/a4fe268ea084e7d323133ed7b986e0ae259a2bc7/tensorflow/lite/kernels/detection_postprocess.cc#L47-L50).
|
983
|
+
# Thus, the metadata of tensors are paired with output tensor indices & name
|
984
|
+
# in this way.
|
985
|
+
|
986
|
+
# Get the output tensor indices and names from the tflite model.
|
987
|
+
tensor_indices_and_names = zip(
|
988
|
+
writer_utils.get_output_tensor_indices(model_buffer),
|
989
|
+
writer_utils.get_output_tensor_names(model_buffer),
|
990
|
+
)
|
991
|
+
# Sort by the output tensor indices.
|
992
|
+
tensor_indices_and_names = sorted(tensor_indices_and_names)
|
993
|
+
|
994
|
+
# Align tensor names with metadata.
|
995
|
+
self._output_mds = [location_md, category_md, score_md, number_md]
|
996
|
+
if len(self._output_mds) != len(tensor_indices_and_names):
|
997
|
+
raise ValueError(
|
998
|
+
"The size of TFLite output should be " + str(len(self._output_mds))
|
999
|
+
)
|
1000
|
+
for i, output_md in enumerate(self._output_mds):
|
1001
|
+
output_md.tensor_name = tensor_indices_and_names[i][1]
|
1002
|
+
|
1003
|
+
@property
|
1004
|
+
def output_mds(self) -> List[TensorMd]:
|
1005
|
+
return self._output_mds
|
1006
|
+
|
1007
|
+
|
1008
|
+
class RawDetectionOutputTensorsOrder(enum.Enum):
|
1009
|
+
"""Output tensors order for detection models without postprocessing.
|
1010
|
+
|
1011
|
+
Because it is not able to determined the order of output tensors for models
|
1012
|
+
without postprocessing, it is needed to specify the output tensors order for
|
1013
|
+
metadata writer.
|
1014
|
+
"""
|
1015
|
+
|
1016
|
+
UNSPECIFIED = 0
|
1017
|
+
# The first tensor is score, and the second tensor is location.
|
1018
|
+
SCORE_LOCATION = 1
|
1019
|
+
# The first tensor is location, and the second tensor is score.
|
1020
|
+
LOCATION_SCORE = 2
|
1021
|
+
|
1022
|
+
|
1023
|
+
class RawDetectionOutputTensorsMd:
|
1024
|
+
"""A container for the output tensor metadata of detection models without postprocessing."""
|
1025
|
+
|
1026
|
+
_LOCATION_NAME = "location"
|
1027
|
+
_LOCATION_DESCRIPTION = "The locations of the detected boxes."
|
1028
|
+
_SCORE_NAME = "score"
|
1029
|
+
_SCORE_DESCRIPTION = "The scores of the detected boxes."
|
1030
|
+
_CONTENT_VALUE_DIM = 2
|
1031
|
+
|
1032
|
+
def __init__(
|
1033
|
+
self,
|
1034
|
+
model_buffer: bytearray,
|
1035
|
+
label_files: Optional[List[LabelFileMd]] = None,
|
1036
|
+
output_tensors_order: RawDetectionOutputTensorsOrder = RawDetectionOutputTensorsOrder.UNSPECIFIED,
|
1037
|
+
) -> None:
|
1038
|
+
"""Initializes the instance of DetectionOutputTensorsMd.
|
1039
|
+
|
1040
|
+
Args:
|
1041
|
+
model_buffer: A valid flatbuffer loaded from the TFLite model file.
|
1042
|
+
label_files: information of the label files [1] in the classification
|
1043
|
+
tensor.
|
1044
|
+
output_tensors_order: the order of the output tensors.
|
1045
|
+
[1]:
|
1046
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L9
|
1047
|
+
"""
|
1048
|
+
# Get the output tensor indices and names from the tflite model.
|
1049
|
+
tensor_indices_and_names = list(
|
1050
|
+
zip(
|
1051
|
+
writer_utils.get_output_tensor_indices(model_buffer),
|
1052
|
+
writer_utils.get_output_tensor_names(model_buffer),
|
1053
|
+
)
|
1054
|
+
)
|
1055
|
+
location_md = LocationTensorMd(
|
1056
|
+
name=self._LOCATION_NAME,
|
1057
|
+
description=self._LOCATION_DESCRIPTION,
|
1058
|
+
)
|
1059
|
+
score_md = ClassificationTensorMd(
|
1060
|
+
name=self._SCORE_NAME,
|
1061
|
+
description=self._SCORE_DESCRIPTION,
|
1062
|
+
label_files=label_files,
|
1063
|
+
)
|
1064
|
+
|
1065
|
+
if output_tensors_order == RawDetectionOutputTensorsOrder.SCORE_LOCATION:
|
1066
|
+
self._output_mds = [score_md, location_md]
|
1067
|
+
elif output_tensors_order == RawDetectionOutputTensorsOrder.LOCATION_SCORE:
|
1068
|
+
self._output_mds = [location_md, score_md]
|
1069
|
+
else:
|
1070
|
+
raise ValueError(
|
1071
|
+
f"Unsupported OutputTensorsOrder value: {output_tensors_order}"
|
1072
|
+
)
|
1073
|
+
|
1074
|
+
if len(self._output_mds) != len(tensor_indices_and_names):
|
1075
|
+
raise ValueError(
|
1076
|
+
"The size of TFLite output should be " + str(len(self._output_mds))
|
1077
|
+
)
|
1078
|
+
for i, output_md in enumerate(self._output_mds):
|
1079
|
+
output_md.tensor_name = tensor_indices_and_names[i][1]
|
1080
|
+
|
1081
|
+
@property
|
1082
|
+
def output_mds(self) -> List[TensorMd]:
|
1083
|
+
return self._output_mds
|
1084
|
+
|
1085
|
+
|
1086
|
+
class TensorGroupMd:
|
1087
|
+
"""A container for a group of tensor metadata information."""
|
1088
|
+
|
1089
|
+
def __init__(
|
1090
|
+
self, name: Optional[str] = None, tensor_names: Optional[List[str]] = None
|
1091
|
+
) -> None:
|
1092
|
+
"""Initializes a CategoryTensorMd object.
|
1093
|
+
|
1094
|
+
Args:
|
1095
|
+
name: name of tensor group.
|
1096
|
+
tensor_names: Names of the tensors to group together, corresponding to
|
1097
|
+
TensorMetadata.name [1].
|
1098
|
+
[1]:
|
1099
|
+
https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L564
|
1100
|
+
"""
|
1101
|
+
self.name = name
|
1102
|
+
self.tensor_names = tensor_names
|
1103
|
+
|
1104
|
+
def create_metadata(self) -> _metadata_fb.TensorGroupT:
|
1105
|
+
"""Creates the tensor group metadata."""
|
1106
|
+
group = _metadata_fb.TensorGroupT()
|
1107
|
+
group.name = self.name
|
1108
|
+
group.tensorNames = self.tensor_names
|
1109
|
+
return group
|
1110
|
+
|
1111
|
+
|
1112
|
+
class SegmentationMaskMd(TensorMd):
|
1113
|
+
"""A container for the segmentation mask metadata information."""
|
1114
|
+
|
1115
|
+
# The output tensor is in the shape of [1, ImageHeight, ImageWidth, N], where
|
1116
|
+
# N is the number of objects that the segmentation model can recognize. The
|
1117
|
+
# output tensor is essentially a list of grayscale bitmaps, where each value
|
1118
|
+
# is the probability of the corresponding pixel belonging to a certain object
|
1119
|
+
# type. Therefore, the content dimension range of the output tensor is [1, 2].
|
1120
|
+
_CONTENT_DIM_MIN = 1
|
1121
|
+
_CONTENT_DIM_MAX = 2
|
1122
|
+
|
1123
|
+
def __init__(
|
1124
|
+
self,
|
1125
|
+
name: Optional[str] = None,
|
1126
|
+
description: Optional[str] = None,
|
1127
|
+
label_files: Optional[List[LabelFileMd]] = None,
|
1128
|
+
):
|
1129
|
+
self.name = name
|
1130
|
+
self.description = description
|
1131
|
+
associated_files = label_files or []
|
1132
|
+
super().__init__(
|
1133
|
+
name=name, description=description, associated_files=associated_files
|
1134
|
+
)
|
1135
|
+
|
1136
|
+
def create_metadata(self) -> _metadata_fb.TensorMetadataT:
|
1137
|
+
"""Creates the metadata for the segmentation masks tensor."""
|
1138
|
+
masks_metadata = super().create_metadata()
|
1139
|
+
|
1140
|
+
# Create tensor content information.
|
1141
|
+
content = _metadata_fb.ContentT()
|
1142
|
+
content.contentProperties = _metadata_fb.ImagePropertiesT()
|
1143
|
+
content.contentProperties.colorSpace = _metadata_fb.ColorSpaceType.GRAYSCALE
|
1144
|
+
content.contentPropertiesType = (
|
1145
|
+
_metadata_fb.ContentProperties.ImageProperties
|
1146
|
+
)
|
1147
|
+
# Add the content range. See
|
1148
|
+
# https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L323-L385
|
1149
|
+
dim_range = _metadata_fb.ValueRangeT()
|
1150
|
+
dim_range.min = self._CONTENT_DIM_MIN
|
1151
|
+
dim_range.max = self._CONTENT_DIM_MAX
|
1152
|
+
content.range = dim_range
|
1153
|
+
masks_metadata.content = content
|
1154
|
+
|
1155
|
+
return masks_metadata
|
1156
|
+
|
1157
|
+
|
1158
|
+
class CustomMetadataMd(abc.ABC):
|
1159
|
+
"""An abstract class of a container for the custom metadata information."""
|
1160
|
+
|
1161
|
+
def __init__(self, name: Optional[str] = None):
|
1162
|
+
self.name = name
|
1163
|
+
|
1164
|
+
@abc.abstractmethod
|
1165
|
+
def create_metadata(self) -> _metadata_fb.CustomMetadataT:
|
1166
|
+
"""Creates the custom metadata based on the information."""
|