Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to let mediapipe be installed in headless environments #3661

Open
gentnm opened this issue Sep 3, 2022 · 9 comments
Open
Assignees
Labels
platform:docker Issues with docker platform:python MediaPipe Python issues stat:awaiting googler Waiting for Google Engineer's Response type:feature Enhancement in the New Functionality or Request for a New Solution

Comments

@gentnm
Copy link

gentnm commented Sep 3, 2022

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 #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:

  1. Just swap it completely
  2. Create a fork/alternative version (mediapipe-headless)
  3. 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" ]
@gentnm gentnm added the type:feature Enhancement in the New Functionality or Request for a New Solution label Sep 3, 2022
@kuaashish kuaashish added platform:python MediaPipe Python issues platform:docker Issues with docker labels Sep 5, 2022
@kuaashish kuaashish assigned jiuqiant and unassigned kuaashish Sep 5, 2022
@kuaashish kuaashish added the stat:awaiting googler Waiting for Google Engineer's Response label Sep 5, 2022
@gentnm gentnm closed this as completed Sep 27, 2022
@gentnm
Copy link
Author

gentnm commented Sep 27, 2022

Ping

@gentnm gentnm reopened this Sep 27, 2022
@Franky1
Copy link

Franky1 commented Apr 12, 2023

I would suggest either

  • an explicit headless package e.g. mediapipe-headless or
  • an installation option e.g. mediapipe[headless]

@sskender
Copy link

Bump

I am also looking an elegant solution to containerize mediapipe and opencv to Python Docker image.

@ARajgor
Copy link

ARajgor commented Sep 30, 2023

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.

@jackie-pc
Copy link

Me too. Looking for headless installation of mediapipe (opencv-contrib-python-headless instead of opencv-contrib-python for underlying dep).

@nagy-nabil
Copy link

is there any work around for this problem right now, or how people solve this problem

@sskender
Copy link

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.

@nagy-nabil
Copy link

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.

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

@FrankwaP
Copy link

FrankwaP commented Feb 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:docker Issues with docker platform:python MediaPipe Python issues stat:awaiting googler Waiting for Google Engineer's Response type:feature Enhancement in the New Functionality or Request for a New Solution
Projects
None yet
Development

No branches or pull requests

10 participants