google-ai-edge / mediapipe

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

Understanding Xnnpack warning #4944

Open szreik opened 10 months ago

szreik commented 10 months ago

Hello! I am getting the following output below when running Mediapipe on a remote server and I just wanted to see if anyone had insight on what this warning means, if it is changing any functionality with Mediapipe, and if not, how I can get it to stop printing out? I know there is an old issue discussing this but there were no useful replies. Thank you!

WARNING: Logging before InitGoogleLogging() is written to STDERR W20231107 20:04:23.744423 377746 face_landmarker_graph.cc:168] Face blendshape model contains CPU only ops. Sets FaceBlendshapesGraph acceleration to Xnnpack. INFO: Created TensorFlow Lite XNNPACK delegate for CPU.

schmidt-sebastian commented 10 months ago

This means that we cannot run the model on GPU and are instead running on CPU. You can likely ignore this warning and possibly silence it by explicitly using a CPU graph. Which API entry point are you using?

kuaashish commented 10 months ago

Hi @szreik,

Can you please review the previous comment and provide the necessary information?

c4b4d4 commented 10 months ago

Is there any way to force it or set it up correctly so it uses GPU? Instead of CPU.

schmidt-sebastian commented 10 months ago

It depends on what API you are using. We would need to know more details.

c4b4d4 commented 10 months ago

It depends on what API you are using. We would need to know more details.

In my case, I'm using the Face landmark detection for Web and willing to use with GPU, as well for the Pose landmark detection for Web

c4b4d4 commented 10 months ago

Sorry, I just read OP wants to remove the warning and not really interested in using GPU, so I guess my comment in this topic is irrelevant then, but will leave it if it helps on anything.

schmidt-sebastian commented 10 months ago

For Web, you need to set the GPU delegate:

objectDetector = await ObjectDetector.createFromOptions(vision, {
    baseOptions: {
      modelAssetPath: `https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite`,
      delegate: "GPU"
    },
    scoreThreshold: 0.5,
    runningMode: runningMode
  });

See https://codepen.io/mediapipe-preview/pen/vYrWvNg

szreik commented 10 months ago

Hello! Sorry for the delay in response. Here is how I am initializing the face detector object. Screenshot 2023-11-14 at 10 01 16 AM

Would I just modify base_options to be: base_options = python.BaseOptions(model_asset_path='face_landmarker_v2_with_blendshapes.task', delegate= "GPU") ? Thank you for your help!

schmidt-sebastian commented 10 months ago

Yes

google-ml-butler[bot] commented 10 months ago

Are you satisfied with the resolution of your issue? Yes No

c4b4d4 commented 10 months ago

Yes

Using the web API. I actually have it delegated to GPU and still showing that warning.

I can even replicate it in the codepen shared by the online guide.

Screenshot 2023-11-14 at 11 05 59 p m

In my case, this is how I init it:

FaceLandmark = await TasksVision.FaceLandmarker.createFromOptions(
TasksVision.vision,
{
    baseOptions: {
modelAssetPath: "/neural/face/face_landmarker.task",
delegate: "GPU"
    },
    runningMode: "VIDEO",
    outputFaceBlendshapes:true,
    outputFacialTransformationMatrixes:true,
    numFaces: 1
});
c4b4d4 commented 10 months ago

@szreik Can you re-open it since it's not really fully resolved. I posted how to replicate it in my previous comment.

szreik commented 10 months ago

@schmidt-sebastian I tried it out using the code I wrote above and I got the following error:

TypeError: BaseOptions.__init__() got an unexpected keyword argument 'delegate'

Screenshot: Screenshot 2023-11-15 at 10 08 46 AM

schmidt-sebastian commented 10 months ago

What version are you using? It should work in the latest version - see https://developers.google.com/mediapipe/api/solutions/python/mp/tasks/BaseOptions

c4b4d4 commented 10 months ago

In my case I'm using the latest JavaScript tasks-vision library: https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm (Note latest)

c4b4d4 commented 10 months ago

I'm also in Chrome, Apple M1 2020. Don't know if the OS affects, so worth mentioning it.

kuaashish commented 9 months ago

Hi @szreik,

To enable GPU support in the Python, follow the steps outlined below to enable functionality:

base_options = python.BaseOptions(model_asset_path='face_landmarker_v2_with_blendshapes.task', delegate=python.BaseOptions.Delegate.GPU)

If you encounter any further issues, please inform us. Thank you!!

github-actions[bot] commented 9 months ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

Geometrein commented 9 months ago

The original question has been hijacked by those wanting to delegate GPU..

The question was: How to suppress this warning?

This setup based on the official Sound Classification API example:

    BaseOptions = mp.tasks.BaseOptions
    AudioClassifier = mp.tasks.audio.AudioClassifier
    AudioClassifierOptions = mp.tasks.audio.AudioClassifierOptions
    AudioRunningMode = mp.tasks.audio.RunningMode

    options = AudioClassifierOptions(
        base_options=BaseOptions(model_asset_path=model_path),
        max_results=2,
        score_threshold=0.9,
        running_mode=AudioRunningMode.AUDIO_CLIPS
    )

    AudioData = mp.tasks.components.containers.AudioData
    with AudioClassifier.create_from_options(options) as classifier:
    ...

This line:

with AudioClassifier.create_from_options(options) as classifier:

Is throwing this log:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1701780695.911066       1 gl_context.cc:344] GL version: 2.1 (2.1 Metal - 88), renderer: Apple M2 Max
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.

How can this be suppressed? (The issue is not exclusive to Face Landmark API.)

Hamed-Hassanzadeh commented 6 months ago

For Web, you need to set the GPU delegate:

objectDetector = await ObjectDetector.createFromOptions(vision, {
    baseOptions: {
      modelAssetPath: `https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite`,
      delegate: "GPU"
    },
    scoreThreshold: 0.5,
    runningMode: runningMode
  });

See https://codepen.io/mediapipe-preview/pen/vYrWvNg

@schmidt-sebastian I ran the MediaPipe Object Detector task codepen you shared and I con confirm that the INFO: Created TensorFlow Lite XNNPACK delegate for CPU. warning is not displayed. However I ran the official MediaPipe FaceLandmarker task codepen and I can see CPU the warning. I ran both link on the same machine/browser. Any idea what might be causing the issue?

RandomUserUsingGitHub commented 1 month ago

For Web, you need to set the GPU delegate:

objectDetector = await ObjectDetector.createFromOptions(vision, {
    baseOptions: {
      modelAssetPath: `https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite`,
      delegate: "GPU"
    },
    scoreThreshold: 0.5,
    runningMode: runningMode
  });

See https://codepen.io/mediapipe-preview/pen/vYrWvNg

@schmidt-sebastian I ran the MediaPipe Object Detector task codepen you shared and I con confirm that the INFO: Created TensorFlow Lite XNNPACK delegate for CPU. warning is not displayed. However I ran the official MediaPipe FaceLandmarker task codepen and I can see CPU the warning. I ran both link on the same machine/browser. Any idea what might be causing the issue?

I have the same problem and I wonder if It's the reason why Mediapipe FaceLandmarker (web) perform so poorly on android devices. Based on my experience, android devices don't utilize GPU, and hence, they lack speed.