mediapipe
mediapipe copied to clipboard
Make it possible to let mediapipe be installed in headless environments
Please make sure that this is a feature request.
System information (Please provide as much relevant information as possible) Official python docker image python:3.9-slim (Debian based)
- MediaPipe Solution (you are using): mediapipe python package installed via pip
- Programming language : Python
- Are you willing to contribute it (Yes/No): Maybe (Need to check CLAs with my employer first)
Describe the feature and the current behavior/state: Reopen from https://github.com/google/mediapipe/issues/3403 It would be great to be able to install mediapipe in a headless version. Currently mediapipe in python depends on opencv-contrib-python which needs a lot of GUI components not needed in headless environments such as slimmed down docker containers. Due to this a lot of overhead is created for people using mediapipe in a streamlined environment without GUI interaction. In order to make mediapipe run in headless environments, the opencv-contrib-python requirement could be swapped for opencv-python-headless .
I see three possible approaches for this:
- Just swap it completely
- Create a fork/alternative version (mediapipe-headless)
- Create a version with extras for the headless version (mediapipe[headless]
Will this change the current api? How? In the headless version, maybe some features need to be turned off. I am not familiar with the complete set of features of mediapipe, so I am not sure if GUI features from opencv-contrib-python are used anywhere. For my usecase everything seems to work fine.
Who will benefit with this feature? Anyone running mediapipe in headless environments.
Please specify the use cases for this feature: Create a service to be deployed in a cloud setting that takes an image and processes it with mediapipe. No GUI features needed there.
Any Other info: Sample docker file to demonstrate current problem:
FROM python:3.9-slim
RUN pip install mediapipe
ENTRYPOINT [ "python" , "-c"]
CMD [ "import mediapipe" ]
Ping
I would suggest either
- an explicit headless package e.g.
mediapipe-headlessor - an installation option e.g.
mediapipe[headless]
Bump
I am also looking an elegant solution to containerize mediapipe and opencv to Python Docker image.
Hello everyone, I'm trying to build a headless version of Mediapipe. I downloaded the repo and made a few changes but facing the build problem. I can't build the Python package. can anyone help me?
This is the error I got.
INFO: Repository flatbuffers instantiated at:
D:/python/mp-headless/mediapipe/WORKSPACE:205:12: in <toplevel>
D:/python/mp-headless/mediapipe/third_party/flatbuffers/workspace.bzl:6:29: in repo
Repository rule third_party_http_archive defined at:
D:/python/mp-headless/mediapipe/third_party/repo.bzl:132:43: in <toplevel>
INFO: repository @flatbuffers' used the following cache hits instead of downloading the corresponding file.
* Hash '1cce06b17cddd896b6d73cc047e36a254fb8df4d7ea18a46acf16c4c0cd3f3f3' for https://github.com/google/flatbuffers/archive/v23.5.26.tar.gz
If the definition of 'repository @flatbuffers' was updated, verify that the hashes were also updated.
ERROR: An error occurred during the fetch of repository 'flatbuffers':
Traceback (most recent call last):
File "D:/python/mp-headless/mediapipe/third_party/repo.bzl", line 113, column 26, in _third_party_http_archive
_apply_delete(ctx, ctx.attr.delete)
File "D:/python/mp-headless/mediapipe/third_party/repo.bzl", line 72, column 32, in _apply_delete
_execute_and_check_ret_code(ctx, cmd)
File "D:/python/mp-headless/mediapipe/third_party/repo.bzl", line 50, column 13, in _execute_and_check_ret_code
fail(("Non-zero return code({1}) when executing '{0}':\n" + "Stdout: {2}\n" +
Error in fail: Non-zero return code(1) when executing 'C:\WINDOWS\system32\bash.exe -l -c "rm" "-rf" "C:/users/ayush/_bazel_ayush/k5wytjhj/external/flatbuffers/build_defs.bzl" "C:/users/ayush/_bazel_ayush/k5wytjhj/external/flatbuffers/BUILD.bazel"':
Stdout:
Stderr: <3>WSL (8) ERROR: CreateProcessEntryCommon:577: execvpe /bin/bash failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:586: Create process not expected to return
ERROR: D:/python/mp-headless/mediapipe/WORKSPACE:205:12: fetching third_party_http_archive rule //external:flatbuffers: Traceback (most recent call last):
File "D:/python/mp-headless/mediapipe/third_party/repo.bzl", line 113, column 26, in _third_party_http_archive
Stdout:
Stderr: <3>WSL (8) ERROR: CreateProcessEntryCommon:577: execvpe /bin/bash failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:586: Create process not expected to return
INFO: Elapsed time: 14.984s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
currently loading: mediapipe/tasks/metadata
Command '['bazel', 'build', '--compilation_mode=opt', '--action_env=PYTHON_BIN_PATH=D:/Python/mp-headless/mediapipe/venv/Scripts/python.exe', '//mediapipe/tasks/metadata:image_segmenter_metadata_schema_py', '--define=MEDIAPIPE_DISABLE_GPU=1']' returned non-zero exit status 1.
Me too. Looking for headless installation of mediapipe (opencv-contrib-python-headless instead of opencv-contrib-python for underlying dep).
is there any work around for this problem right now, or how people solve this problem
is there any work around for this problem right now, or how people solve this problem
I had to install mediapipe Python library and Mesa package on Linux to support it:
apt-get update && \
apt-get install --no-install-recommends -y \
libegl1-mesa-dev \
libglib2.0-0
Not elegant solution at all.
is there any work around for this problem right now, or how people solve this problem
I had to install
mediapipePython library and Mesa package on Linux to support it:apt-get update && \ apt-get install --no-install-recommends -y \ libegl1-mesa-dev \ libglib2.0-0Not elegant solution at all.
i changed the docker image to FROM python:3.10-bookworm AS builder and with couple of packages as well
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libffi-dev \
gcc \
musl-dev \
# libgcc \
# freetype-dev \
libpng-dev \
libavcodec-dev \
ffmpeg
i think it's working for me
Hi!
I think I've found the solution, I've written a gist for it: https://gist.github.com/FrankwaP/f45c9180cf85e5abe563d97f0af84ae5
Basically before installing Mediapipe, you install opencv-contrib-python-headless and for each folder created you generate the corresponding "opencv-contrib-python" symbolic link.