1

I am trying to follow the getting started guide for the hand landmarks in mediapipe for python but when I try to run it I get a runtime error.

Traceback (most recent call last):
  File "C:\Users\Tom\PycharmProjects\MediaPipe\mediapipe_static.py", line 12, in <module>
    with HandLandmarker.create_from_options(options) as landmarker:
  File "C:\Users\Tom\PycharmProjects\MediaPipe\venv\lib\site-packages\mediapipe\tasks\python\vision\hand_landmarker.py", line 271, in create_from_options
    return cls(
  File "C:\Users\Tom\PycharmProjects\MediaPipe\venv\lib\site-packages\mediapipe\tasks\python\vision\core\base_vision_task_api.py", line 66, in __init__
    self._runner = _TaskRunner.create(graph_config, packet_callback)
RuntimeError: Unable to initialize runfiles: ERROR: external/bazel_tools/tools/cpp/runfiles/runfiles.cc(120): cannot find runfiles (argv0="")

I am running on:

  • python 3.10.8
  • pip 23.0.1
  • mediapipe 0.9.2.1

This is the code I ran

import mediapipe as mp

BaseOptions = mp.tasks.BaseOptions
HandLandmarker = mp.tasks.vision.HandLandmarker
HandLandmarkerOptions = mp.tasks.vision.HandLandmarkerOptions
VisionRunningMode = mp.tasks.vision.RunningMode

# Create a hand landmarker instance with the image mode:
options = HandLandmarkerOptions(
    base_options=BaseOptions(model_asset_path='[path to hand_landmark.task]'),
    running_mode=VisionRunningMode.IMAGE)
with HandLandmarker.create_from_options(options) as landmarker:
    # Load the input image from an image file.
...

I tried changing the model_asset_path but this seemed to not be the issue here.

Pollcosso
  • 11
  • 1
  • This seems to be an open issue with media pipe at the moment. https://github.com/google/mediapipe/issues/4272 – Pollcosso Apr 11 '23 at 11:18

1 Answers1

0

This appears to be a known issue with MediaPipe right now, as @Pollcosso mentioned. The best solution is to use the media_asset_buffer option, which requires you to load the file as bytes and then pass the byte object to the factory method:

    model_file = open('hand_landmarker.task', "rb")
    model_data = model_file.read()
    model_file.close()
    
    base_options = python.BaseOptions(model_asset_buffer=model_data)
    options = vision.HandLandmarkerOptions(base_options=base_options, num_hands=2)
    detector = vision.HandLandmarker.create_from_options(options)
nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57