google-ai-edge / mediapipe

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

Failed to read the geometry pipeline metadata from file #2304

Closed RafaelMiquelino closed 3 years ago

RafaelMiquelino commented 3 years ago

Please make sure that this is a build/installation issue and also refer to the troubleshooting documentation before raising any issues.

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

Describe the problem:

I get the error Calculator::Open() for node "facegeometryfromdetection__FaceGeometryPipelineCalculator" failed: ; Error while reading file: /Users/***/.virtualenvs/mediapipe/lib/python3.7/site-packages; Failed to read content blob! Resolved path = /Users/***/.virtualenvs/mediapipe/lib/python3.7/site-packages; Failed to read a metadata blob from file!; Failed to read the geometry pipeline metadata from file! when trying to run my custom graph from Python.

I run through #1253 and #1584 and there are valuable information there and I compiled the file and placed that on a specific place, however I don't understanding why my path is resolving to the Python site-packages folder and of course there is no geometry pipeline metadata file there.

Provide the exact sequence of commands / steps that you executed before running into the problem:

I added the custom graphs to the mediapipe/BUILD file as recommended in #1578:

cc_library(
    name = "builtin_calculators",
    deps = [
        ...
        "//mediapipe/graphs/face_effect/subgraphs:single_face_geometry_from_detection_cpu",
        "//mediapipe/graphs/face_effect/subgraphs:single_face_geometry_from_landmarks_cpu",
    ],
)

The I call my graph and try to process an image from python using the SolutionBase class:

from mediapipe.python.solution_base import SolutionBase
mp_face_geometry = SolutionBase(
    binary_graph_path='/xxx/mediapipe/bazel-bin/mediapipe/graphs/face_effect/subgraphs/single_face_geometry_from_detection_cpu.binarypb',
    outputs=['multi_face_geometry']
)

rgb_img = cv2.cvtColor(cv2.imread('/***/Image_0001.jpg'), cv2.COLOR_BGR2RGB)

results = mp_face_geometry.process(input_data={'input_image': rgb_img})

The I get the mentioned error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/***/.virtualenvs/mediapipe/lib/python3.7/site-packages/mediapipe/python/solution_base.py", line 312, in process
    data).at(self._simulated_timestamp))
RuntimeError: Graph has errors: 
Calculator::Open() for node "facegeometryfromdetection__FaceGeometryPipelineCalculator" failed: ; Error while reading file: /Users/***/.virtualenvs/mediapipe/lib/python3.7/site-packages; Failed to read content blob! Resolved path = /Users/***/.virtualenvs/mediapipe/lib/python3.7/site-packages; Failed to read a metadata blob from file!; Failed to read the geometry pipeline metadata from file!

The custom graphs are attached (in .txt for compatibility reasons):

The BUILD config for the two graphs are also below:

mediapipe_simple_subgraph(
    name = "single_face_geometry_from_detection_cpu",
    graph = "single_face_geometry_from_detection_cpu.pbtxt",
    register_as = "SingleFaceGeometryFromDetectionCpu",
    deps = [
        ":face_landmarks_smoothing",
        "//mediapipe/calculators/core:concatenate_detection_vector_calculator",
        "//mediapipe/calculators/core:split_vector_calculator",
        "//mediapipe/calculators/image:image_properties_calculator",
        "//mediapipe/modules/face_detection:face_detection_short_range_cpu",
        "//mediapipe/modules/face_geometry:face_geometry_from_detection",
        "//mediapipe/modules/face_geometry:env_generator_calculator",
    ],
)

mediapipe_simple_subgraph(
    name = "single_face_geometry_from_landmarks_cpu",
    graph = "single_face_geometry_from_landmarks_cpu.pbtxt",
    register_as = "SingleFaceGeometryFromLandmarksCpu",
    deps = [
        ":face_landmarks_smoothing",
        "//mediapipe/calculators/core:concatenate_vector_calculator",
        "//mediapipe/calculators/core:constant_side_packet_calculator",
        "//mediapipe/calculators/core:split_vector_calculator",
        "//mediapipe/calculators/image:image_properties_calculator",
        "//mediapipe/calculators/util:landmarks_smoothing_calculator",
        "//mediapipe/modules/face_geometry:face_geometry_from_landmarks",
        "//mediapipe/modules/face_landmark:face_landmark_front_cpu",
        "//mediapipe/modules/face_geometry:env_generator_calculator",
    ],
)

Complete Logs: Include Complete Log information 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:

kostyaby commented 3 years ago

Thanks for reaching out! This sounds like an issue with reading a file from a file system in Python, not a Face Geometry pipeline logic issue. @jiuqiant will be the person to help you navigate through this

jiuqiant commented 3 years ago

Currently, you need to import all the calculator options the graph uses in the python file to make it read the graph correctly. Here is how we do this for face mesh: https://github.com/google/mediapipe/blob/master/mediapipe/python/solutions/face_mesh.py#L23. We will have some improvements soon to do this automatically soon.

RafaelMiquelino commented 3 years ago

Thanks, it did the trick.