google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
26.82k stars 5.09k forks source link

How to generate detection_unique_id_calculator.proto by myself? #3550

Closed garyli03 closed 2 years ago

garyli03 commented 2 years ago

Please make sure that this is a solution issue.

System information (Please provide as much relevant information as possible)

  • Have I written custom code (as opposed to using a stock example script provided in Mediapipe): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04, Android 11, iOS 14.4): Ubuntu 20.04
  • MediaPipe version: 0.8.10.1
  • Bazel version: 5.2.0
  • Solution (e.g. FaceMesh, Pose, Holistic): Box Tracking
  • Programming Language and version ( e.g. C++, Python, Java): Python

Describe the expected behavior: Generate Python code to please the demo

Standalone code you may have used to try to get what you need :

How to generate .proto file for _detection_unique_idcalculator.cc? I want to implement python solution for box tracking. But I finally found the _detection_unique_id_calculatorpb2.py which the solution depends on cannot be generated because the source code doesn't contain _mediapipe/calculators/util/detection_unique_idcalculator.proto. I wonder is there a way to generate this .proto file by myself?

Other info / Complete Logs : Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached:

onuralpszr commented 2 years ago

Is this file you looking for ?: https://github.com/google/mediapipe/blob/master/mediapipe/calculators/util/detections_to_render_data_calculator.proto

Also you wanna create your own proto file you may want to take look for further information

https://developers.google.com/protocol-buffers

garyli03 commented 2 years ago

Sorry, Copied wrong file name. The one I am looking for is:

detection_unique_id_calculator.proto

The description of this issue is updated.

kuaashish commented 2 years ago

Hi @garyli03, Could you please elaborate with respect of use case and complete details about the issue. Thank you!

garyli03 commented 2 years ago

Hi, kuaashish, I am trying to implement Python API for Object tracking. I already implemented object detection Python API by referring https://github.com/google/mediapipe/issues/1903. Now, I want do similar thing for Object Tracking https://google.github.io/mediapipe/solutions/box_tracking.html .

The build process by running

python3 stup.py install --link-opencv

succeeded. But when I ran the following code:

     import mediapipe as mp
     object_tracking = mp.solution.object_tracking

An error occurred said no Module named detection_unique_id_calculator_pb2. I believe this was because we don't have proto file for detection_unique_id_calculator.cc, so the related py file can't be generated.

What I did to implement the feature are:

Copyright 2021 The MediaPipe Authors.

#

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

#

http://www.apache.org/licenses/LICENSE-2.0

#

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

"""MediaPipe Object Detection."""

import enum from typing import NamedTuple, Union

import numpy as np from mediapipe.framework.formats import detection_pb2 from mediapipe.framework.formats import location_data_pb2

The following imports are needed because python pb2 silently discards

unknown protobuf fields.

pylint: disable=unused-import

from mediapipe.calculators.core import packet_resampler_calculator_pb2 from mediapipe.calculators.video import box_tracker_calculator_pb2 from mediapipe.calculators.video import flow_packager_calculator_pb2 from mediapipe.calculators.video import motion_analysis_calculator_pb2 from mediapipe.calculators.video import tracked_detection_manager_calculator_pb2 from mediapipe.calculators.image import image_transformation_calculator_pb2 from mediapipe.calculators.tflite import tflite_converter_calculator_pb2 from mediapipe.calculators.tflite import tflite_inference_calculator_pb2 from mediapipe.calculators.tflite import ssd_anchors_calculator_pb2 from mediapipe.calculators.tflite import tflite_tensors_to_detections_calculator_pb2 from mediapipe.calculators.util import non_max_suppression_calculator_pb2 from mediapipe.calculators.util import detection_label_id_to_text_calculator_pb2 from mediapipe.calculators.util import detection_unique_id_calculator_pb2 from mediapipe.calculators.util import detections_to_timed_box_list_calculator_pb2 from mediapipe.calculators.util import annotation_overlay_calculator_pb2 from mediapipe.calculators.util import detections_to_render_data_calculator_pb2 from mediapipe.calculators.util import rect_to_render_data_calculator_pb2

pylint: enable=unused-import

from mediapipe.python.solutions import download_utils from mediapipe.python.solution_base import SolutionBase

BINARYPB_FILE_PATH = 'mediapipe/modules/object_tracking/object_tracking_cpu.binarypb'

def _download_oss_object_detection_model(): download_utils.download_oss_model( 'mediapipe/modules/object_detection/object_detection.tflite') download_utils.download_oss_model( 'mediapipe/modules/object_detection/object_detection_label.txt')

class ObjectTracking(SolutionBase): """MediaPipe Object Tracking.

MediaPipe Object tracking processes an RGB video and returns a list of the
detected object location data along with the detection labels and tracking ids.

Please refer to
https://solutions.mediapipe.dev/object_tracling#python-solution-api
for usage examples.
"""

def __init__(self, frame_rate=3):
    """Initializes a MediaPipe Object Detection object.

    Args:
      max_object_detection:
      min_detection_confidence: Minimum confidence value ([0.0, 1.0]) for object
          detection to be considered successful. See details in
          https://solutions.mediapipe.dev/object_detection#min_detection_confidence.
      min_suppression_threshold:
    """
    # _download_oss_object_detection_model()
    super().__init__(
        binary_graph_path=BINARYPB_FILE_PATH,
        calculator_params={
            'PacketResamplerCalculator.PeriodIndexToTimestamp':
                frame_rate,
        },
        outputs=['output_video'])

def process(self, image: np.ndarray) -> NamedTuple:
    """Processes an RGB image and returns a list of the detected object data.

    Args:
      image: An RGB image represented as a numpy ndarray.

    Raises:
      RuntimeError: If the underlying graph throws any error.
      ValueError: If the input image is not three channel RGB.

    Returns:
      A NamedTuple object with a "detections" field that contains a list of the
      detected object data.
    """

    return super().process(input_data={'image': image})
garyli03 commented 2 years ago

I figured out that the proto file is not required because the calculator doesn't have options. Simply remove from mediapipe.calculators.util import detection_unique_id_calculator_pb2 works

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No