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

ImageEmbedderOption quantize behavior #5290

Closed
1cipher opened this issue Apr 2, 2024 · 5 comments
Closed

ImageEmbedderOption quantize behavior #5290

1cipher opened this issue Apr 2, 2024 · 5 comments
Assignees
Labels
platform:python MediaPipe Python issues platform:raspberry pi Raspberry pi ARM task:image embedding Issues related to Image Embedding: Embed images into feature vectors type:support General questions

Comments

@1cipher
Copy link

1cipher commented Apr 2, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

Raspberry pi 5

MediaPipe Tasks SDK version

No response

Task name (e.g. Image classification, Gesture recognition etc.)

ImageEmbedder

Programming Language and version (e.g. C++, Python, Java)

Python

Describe the actual behavior

The output from the custom tflite model with quantize set to False is slower than when it is set to True. In addition the output when the flag quantize = False the model output are floats, even if the real model output are specified to be uint8

Describe the expected behaviour

We expect that when quantize is false then the computation should be faster since it should not compute any additional operation and also we expect a uint8 output, since our tflite model when called with Interpreter returns an uint8 embedding

Standalone code/steps you may have used to try to get what you need

# Initialize the object detection model
  base_options = python.BaseOptions(model_asset_path=model)
  options = vision.ImageEmbedderOptions(base_options=base_options,
                                         running_mode=vision.RunningMode.IMAGE,
                                         l2_normalize = False, quantize = False,
                                         ) 
  detector = vision.ImageEmbedder.create_from_options(options)


  # Continuously capture images from the camera and run inference
  image = cv2.imread('carpet.png')
  image = cv2.resize(image, (256, 256), interpolation=cv2.INTER_LINEAR)

  image = cv2.flip(image, 1)

  rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  print(rgb_image)
  mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=rgb_image)

  for i in range(100):

    # Run object detection using the model.

    start = time.time()
    em = detector.embed(mp_image)
    print(time.time()-start)
    embed = em.embeddings[0].embedding
    print(np.unique(embed)) ## here the output is float32, while our model gives uint8 results
    print(len(np.unique(embed)))

  detector.close()

Other info / Complete Logs

No response

@1cipher
Copy link
Author

1cipher commented Apr 2, 2024

practically, my concern is to understand the impliances of using whether quantize set to True or false in ImageEmbedderOptions if i provide a custom .tflite model that already present a uint8 tensor as output. In this case i would like to perform dequantization manually since it appears that mediapipe cannot read .tflite quantization parameters

@1cipher 1cipher closed this as completed Apr 2, 2024
@1cipher 1cipher reopened this Apr 2, 2024
@kuaashish kuaashish assigned kuaashish and unassigned ayushgdev Apr 3, 2024
@kuaashish kuaashish added platform:raspberry pi Raspberry pi ARM task:image embedding Issues related to Image Embedding: Embed images into feature vectors platform:python MediaPipe Python issues type:support General questions labels Apr 3, 2024
@schmidt-sebastian
Copy link
Collaborator

In our current pipeline, your model output has to match the output format of the models that our tasks are designed to handle. It seems pretty likely that we are just passing through quantized data from your model as floats. You might be able to read the data back as uint, but that is not officially supported.

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Apr 19, 2024
Copy link

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.

@github-actions github-actions bot added the stale label Apr 27, 2024
Copy link

github-actions bot commented May 4, 2024

This issue was closed due to lack of activity after being marked stale for past 7 days.

@github-actions github-actions bot closed this as completed May 4, 2024
Copy link

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

@kuaashish kuaashish removed stat:awaiting response Waiting for user response stale labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:python MediaPipe Python issues platform:raspberry pi Raspberry pi ARM task:image embedding Issues related to Image Embedding: Embed images into feature vectors type:support General questions
Projects
None yet
Development

No branches or pull requests

4 participants