mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

How change graph vertical_fov_degrees value with input_side_packet or other way [python]

Open tensorware opened this issue 1 year ago • 4 comments

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

Ubuntu 22.04.4

Task name (e.g. Image classification, Gesture recognition etc.)

face_landmarker_v2_with_blendshapes.task

Programming Language and version (e.g. C++, Python, Java)

Python

Describe the actual behavior

vision.FaceLandmarker.create_from_options(options) uses default environment for perspective_camera

Describe the expected behaviour

vision.FaceLandmarker.create_from_options(options) should allow side_inputs for perspective_camera

Standalone code/steps you may have used to try to get what you need

This is more or less the same question as in #3953, but by using the newer Task Solution API via Python. I'm using Face Landmarks Detection with MediaPipe Tasks similar to this example but with video live stream.

I want to improve the results (depth estimations) as mentioned here #3402, by setting camera parameters. See also: https://github.com/google/mediapipe/blob/72e4d3ee61953af2295fbb958c4ee32d27489d95/mediapipe/tasks/cc/vision/face_landmarker/face_landmarker_graph.cc#L207

How this can be done with MediaPipe v0.10.11 python bindings, without re-building from source?

Other info / Complete Logs

To summarize:

Is there a way to change vertical_fov_degrees using the latest python bindings,

# STEP 1: Import the necessary modules.
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision

# STEP 2: Create an FaceLandmarker object.
base_options = python.BaseOptions(model_asset_path='face_landmarker_v2_with_blendshapes.task')
options = vision.FaceLandmarkerOptions(base_options=base_options,
                                       output_face_blendshapes=True,
                                       output_facial_transformation_matrixes=True,
                                       num_faces=1)
detector = vision.FaceLandmarker.create_from_options(options)

by injecting side packets (or otherwise) before or after the detector instantiation?

I traced it down to be somewhere here: https://github.com/google/mediapipe/blob/72e4d3ee61953af2295fbb958c4ee32d27489d95/mediapipe/tasks/python/vision/face_landmarker.py#L3104

Any suggestions are welcome, thanks.

tensorware avatar Mar 28 '24 06:03 tensorware

Hi @tensorware,

Following our internal discussion, please be informed that at present, accomplishing this task requires rebuilding from the source. However, we acknowledge that simplifying this process is a priority for us in the near future.

Thank you!!

kuaashish avatar Apr 08 '24 10:04 kuaashish

Many thanks for the answer. In the meantime, is there any other way to change the graph config or the task file?

  • I have seen that the graph config can be accessed from the detector. Is there a way to update the config object before inference?
# STEP 1: Import the necessary modules.
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision

# STEP 2: Create an FaceLandmarker object.
base_options = python.BaseOptions(model_asset_path='face_landmarker_v2_with_blendshapes.task')
options = vision.FaceLandmarkerOptions(base_options=base_options,
                                       output_face_blendshapes=True,
                                       output_facial_transformation_matrixes=True,
                                       num_faces=1)
detector = vision.FaceLandmarker.create_from_options(options)

with open('graph.pbtxt', 'w') as file:
    config = detector.get_graph_config() # Update this config ?
    file.write(str(config))
  • Would it be possible to create a custom face_landmarker_v2_with_blendshapes.task file, instead of re-building everything from source?

tensorware avatar Apr 15 '24 07:04 tensorware

Hi @tensorware,

Apologies for the delay in responding. After receiving additional input from our team, It is currently not possible. The only remaining option is to rebuild from the source by altering the graph.

Thank you!!

kuaashish avatar Apr 23 '24 06:04 kuaashish

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar May 09 '24 01:05 github-actions[bot]

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

google-ml-butler[bot] avatar May 09 '24 01:05 google-ml-butler[bot]