Closed garyli03 closed 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
Sorry, Copied wrong file name. The one I am looking for is:
detection_unique_id_calculator.proto
The description of this issue is updated.
Hi @garyli03, Could you please elaborate with respect of use case and complete details about the issue. Thank you!
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:
"//mediapipe/modules/object_tracking:object_tracking_cpu",
in /master/mediapipe/python/BUILD import mediapipe.python.solutions.object_tracking
in /mediapipe/python/solutions/init.py
#
#
#
"""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
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
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})
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
Please make sure that this is a solution issue.
System information (Please provide as much relevant information as possible)
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: