google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://mediapipe.dev
Apache License 2.0
26.8k stars 5.09k forks source link

Hand Tracking GPU Run Error #150

Closed pablovela5620 closed 4 years ago

pablovela5620 commented 4 years ago

I have no problem build and running the CPU example, and am able to build the GPU hand tracking example but when I run the following command to execute GPU hand tracking

bazel-bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_gpu \ --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_mobile.pbtxt

> E1005 12:33:16.857620 13587 demo_run_graph_main_gpu.cc:181] Failed to run the graph: Graph has errors: 
> Calculator::Open() for node "[TfLiteInferenceCalculator_1, TfLiteInferenceCalculator with output stream: __sg0_detection_tensors]" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argument.: glBufferData in external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_buffer.h:245

May be relevant but I am running this inside a docker container with the file looking like this

FROM nvidia/cuda:10.1-base

MAINTAINER <mediapipe@google.com>

WORKDIR /io
WORKDIR /mediapipe

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        wget \
        unzip \
        python \
        python-pip \
        libopencv-core-dev \
        libopencv-highgui-dev \
        libopencv-imgproc-dev \
        libopencv-video-dev \
        mesa-common-dev \
        libegl1-mesa-dev \
        libgles2-mesa-dev \
        software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && \
    apt-get update && apt-get install -y openjdk-8-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade setuptools
RUN pip install future

# Install bazel
ARG BAZEL_VERSION=0.26.1
RUN mkdir /bazel && \
    wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \
    wget --no-check-certificate -O  /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" && \
    chmod +x /bazel/installer.sh && \
    /bazel/installer.sh  && \
    rm -f /bazel/installer.sh

RUN pip install numpy
RUN pip install opencv-python
COPY . /mediapipe/

# If we want the docker image to contain the pre-built object_detection_offline_demo binary, do the following

RUN bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
RUN bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu
mcclanahoochie commented 4 years ago

I don't believe Docker supports OpenGL by default. Can you try using one of these https://hub.docker.com/search?q=opengl&type=image ? If one of those works, that is great, but we are not currently developing/testing GPU support inside a Docker

pablovela5620 commented 4 years ago

Yep that was my issues, switched my base image from nvidia/cuda:10.1-base to nvidia/cudagl:10.1-base. Thank you for the help!

mgyong commented 4 years ago

Did it worked when you switched over to nvidia/cudagl:10.1-base

Can you share your dockerfile? Thks

On Mon, Oct 7, 2019, 1:33 PM Pablo Vela notifications@github.com wrote:

Yep that was my issues, switched my base image from nvidia/cuda:10.1-base to nvidia/cudagl:10.1-base. Thank you for the help!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/mediapipe/issues/150?email_source=notifications&email_token=AAQTXUJNHCZUSBPEK6WLYM3QNOMIFA5CNFSM4I5XS5P2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEARWVDI#issuecomment-539191949, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQTXUOD5XDRI4BHGQCR2V3QNOMIFANCNFSM4I5XS5PQ .

pablovela5620 commented 4 years ago

Sure, I just changed the base image but this is it below. It worked perfectly for me so long as you do fiddling with the docker run command to ensure you share xhosts and webcam devices


FROM nvidia/cudagl:10.1-base

MAINTAINER <mediapipe@google.com>

WORKDIR /io
WORKDIR /mediapipe

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        wget \
        unzip \
        python \
        python-pip \
        libopencv-core-dev \
        libopencv-highgui-dev \
        libopencv-imgproc-dev \
        libopencv-video-dev \
        mesa-common-dev \
        libegl1-mesa-dev \
        libgles2-mesa-dev \
        software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && \
    apt-get update && apt-get install -y openjdk-8-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade setuptools
RUN pip install future

# Install bazel
ARG BAZEL_VERSION=0.26.1
RUN mkdir /bazel && \
    wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \
    wget --no-check-certificate -O  /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" && \
    chmod +x /bazel/installer.sh && \
    /bazel/installer.sh  && \
    rm -f /bazel/installer.sh

RUN pip install numpy
RUN pip install opencv-python
COPY . /mediapipe/

# If we want the docker image to contain the pre-built hand tracking cpu/gpu binary, do the following
RUN bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
RUN bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu
gitBitHubNet commented 4 years ago

Similar problem, but on Ubuntu. Compilation passed ok, but when I try to run I get:

E1129 13:01:40.700181  2563 demo_run_graph_main_gpu.cc:181] Failed to run the graph: Graph has errors:
Calculator::Open() for node "[TfLiteInferenceCalculator_1, TfLiteInferenceCalculator with output stream: __sg0_detection_tensors]" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argumen
t.: glBufferData in external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_buffer.h:253

The difference that I see is that in my case the code brakes on .../gl_buffer.h:253 instead of .../gl_buffer.h:245.

My laptop has Mobile Intel Graphics Media Accelerator 4500MHD (it is a bit old...), is there perhaps an incompatibility compared to the modern GPUs?

mcclanahoochie commented 4 years ago

Running desktop GPU examples requires a device that supports OpenGL ES 3.1+ , and with EGL drivers installed (usually mesa drivers). It's possible the Intel GMA 4500MHD doesn't have that hardware support and/or appropriate drivers.

alizahidraja commented 4 years ago

Similar problem, but on Ubuntu. Compilation passed ok, but when I try to run I get:

E1129 13:01:40.700181  2563 demo_run_graph_main_gpu.cc:181] Failed to run the graph: Graph has errors:
Calculator::Open() for node "[TfLiteInferenceCalculator_1, TfLiteInferenceCalculator with output stream: __sg0_detection_tensors]" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argumen
t.: glBufferData in external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_buffer.h:253

The difference that I see is that in my case the code brakes on .../gl_buffer.h:253 instead of .../gl_buffer.h:245.

My laptop has Mobile Intel Graphics Media Accelerator 4500MHD (it is a bit old...), is there perhaps an incompatibility compared to the modern GPUs?

Had the same error on google cloud, this is what to do if you have successfully installed all drivers but still this error comes up: just run the MultiHandTrackingGpu for android first, and then for desktop you're good to go

gitBitHubNet commented 4 years ago

Had the same error on google cloud, this is what to do if you have successfully installed all drivers but still this error comes up: just run the MultiHandTrackingGpu for android first, and then for desktop you're good to go

@alizahidraja When you say 'run' you mean compile for Android and the compile for desktop? I will try it, but how does this fix the issue?Yet, I am ready to be surprised!

alizahidraja commented 4 years ago

Hey sorry no it didn’t compile it gave a different error! :( Can you please help me with it? I’m working on a cloud server and the cpu example runs fine but the gpu gives error on GL and I’ve done everything!

mcclanahoochie commented 4 years ago

Please check your gpu driver supports OpenGL ES

$ sudo apt-get install mesa-utils
$ glxinfo | grep -i opengl

My linux box prints

$ glxinfo | grep -i opengl
...
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 430.50
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

^ notice the OpenGL ES 3.2 ^

To run MediaPipe GPU on desktop, you need to see ES 3.1 or greater printed

If OpenGL ES is not printed, or is below 3.1, then the GPU inference will not run

AlexYiningLiu commented 4 years ago

Sure, I just changed the base image but this is it below. It worked perfectly for me so long as you do fiddling with the docker run command to ensure you share xhosts and webcam devices


FROM nvidia/cudagl:10.1-base

MAINTAINER <mediapipe@google.com>

WORKDIR /io
WORKDIR /mediapipe

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        wget \
        unzip \
        python \
        python-pip \
        libopencv-core-dev \
        libopencv-highgui-dev \
        libopencv-imgproc-dev \
        libopencv-video-dev \
        mesa-common-dev \
        libegl1-mesa-dev \
        libgles2-mesa-dev \
        software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && \
    apt-get update && apt-get install -y openjdk-8-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade setuptools
RUN pip install future

# Install bazel
ARG BAZEL_VERSION=0.26.1
RUN mkdir /bazel && \
    wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \
    wget --no-check-certificate -O  /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" && \
    chmod +x /bazel/installer.sh && \
    /bazel/installer.sh  && \
    rm -f /bazel/installer.sh

RUN pip install numpy
RUN pip install opencv-python
COPY . /mediapipe/

# If we want the docker image to contain the pre-built hand tracking cpu/gpu binary, do the following
RUN bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
RUN bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu

@pablovela5620 I am using the exact same base image cudagl:10.1-base in my dockerfile, but when I run mediapipe gpu example in docker, I am still getting the same error that you are originally getting with "unacceptable value is specified by an enumerated argument". Can you please let me know how you are running the docker container with the xhost and webcam access and also if you changed anything else to fix the issue? Thanks.

AlexYiningLiu commented 4 years ago

Please check your gpu driver supports OpenGL ES

$ sudo apt-get install mesa-utils
$ glxinfo | grep -i opengl

My linux box prints

$ glxinfo | grep -i opengl
...
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 430.50
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

^ notice the OpenGL ES 3.2 ^

To run MediaPipe GPU on desktop, you need to see ES 3.1 or greater printed

If OpenGL ES is not printed, or is below 3.1, then the GPU inference will not run

@mcclanahoochie I have the same issue as @pablovela5620 . I know that my GPU is compatible with ES 3.2 because I checked it and ran Mediapipe GPU outside of docker with no problem. However when I use glxinfo within Docker to check, I get the following:

root@fb89acd43129:/mediapipe# glxinfo | grep -i opengl
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  54
  Current serial number in output stream:  53
wingedrasengan927 commented 3 years ago

Sure, I just changed the base image but this is it below. It worked perfectly for me so long as you do fiddling with the docker run command to ensure you share xhosts and webcam devices


FROM nvidia/cudagl:10.1-base

MAINTAINER <mediapipe@google.com>

WORKDIR /io
WORKDIR /mediapipe

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        wget \
        unzip \
        python \
        python-pip \
        libopencv-core-dev \
        libopencv-highgui-dev \
        libopencv-imgproc-dev \
        libopencv-video-dev \
        mesa-common-dev \
        libegl1-mesa-dev \
        libgles2-mesa-dev \
        software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && \
    apt-get update && apt-get install -y openjdk-8-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade setuptools
RUN pip install future

# Install bazel
ARG BAZEL_VERSION=0.26.1
RUN mkdir /bazel && \
    wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \
    wget --no-check-certificate -O  /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" && \
    chmod +x /bazel/installer.sh && \
    /bazel/installer.sh  && \
    rm -f /bazel/installer.sh

RUN pip install numpy
RUN pip install opencv-python
COPY . /mediapipe/

# If we want the docker image to contain the pre-built hand tracking cpu/gpu binary, do the following
RUN bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
RUN bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu

@pablovela5620, Please tell how did you share xhosts and webcam services. The docker command would be really helpful