mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

<ValueError: Expected a model with 4 output tensors, found 2> when trying to instantiate mp.tasks.vision.ObjectDetector in Python with recommended model

Open Callum-Halton opened this issue 1 year ago • 1 comments

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

No

OS Platform and Distribution

macOS 14.6.1 BuildVersion: 23G93

MediaPipe Tasks SDK version

mediapipe 0.9.1.0

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

Object Detection

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

Python 3.10.9

Describe the actual behavior

<ValueError: Expected a model with 4 output tensors, found 2> when trying to instantiate mp.tasks.vision.ObjectDetector in Python with recommended model

Describe the expected behaviour

mp.tasks.vision.ObjectDetector is successfully instantiated

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

Models Tested

Tried with the models provided here, specifically the latest int8 and latest float32 models

Code Run

import mediapipe as mp

BaseOptions = mp.tasks.BaseOptions
ObjectDetector = mp.tasks.vision.ObjectDetector
ObjectDetectorOptions = mp.tasks.vision.ObjectDetectorOptions
VisionRunningMode = mp.tasks.vision.RunningMode

options = ObjectDetectorOptions(
    base_options=BaseOptions(model_asset_path='models/object detection/efficientdet_lite0.tflite'),
    max_results=5,
    running_mode=VisionRunningMode.IMAGE)

with ObjectDetector.create_from_options(options) as detector:
  print("success")

Output

Traceback (most recent call last):
  File "obj_det.py", line 13, in <module>
    with ObjectDetector.create_from_options(options) as detector:
  File "<python_env>/lib/python3.10/site-packages/mediapipe/tasks/python/vision/object_detector.py", line 207, in create_from_options
    return cls(
  File "<python_env>/lib/python3.10/site-packages/mediapipe/tasks/python/vision/core/base_vision_task_api.py", line 66, in __init__
    self._runner = _TaskRunner.create(graph_config, packet_callback)
ValueError: Expected a model with 4 output tensors, found 2.

Other info / Complete Logs

Trouble Shooting Attempts

  • Tried instantiating ObjectDetector using create_from_model_path
  • Tried using detlite2 models instead
  • Tried reinstalling mediapipe

Callum-Halton avatar Aug 21 '24 19:08 Callum-Halton

Hi @Callum-Halton,

Please update to the latest version, as 0.9.1.0 is outdated and may contain bugs. I successfully ran the code on macOS 14.6.1 with Python 3.10.9 using version 0.10.14, as shown in the attached screenshot. This issue is not limited to macOS; I also reproduced the error in Colab, which confirms the same problem. You can view the details in the attached gist.

Screenshot 2024-08-22 at 12 43 42 PM

Kindly upgrade to the latest version and please let us know if you still encounter the error. Beyond this, there isn't much more we can do to resolve the issue.

Thank you!!

kuaashish avatar Aug 22 '24 07:08 kuaashish

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[bot] avatar Aug 30 '24 01:08 github-actions[bot]

Same here

JeongJun-Lee avatar Sep 05 '24 13:09 JeongJun-Lee

Hi @JeongJun-Lee,

We apologize for the previous delay in response. Based on feedback here, it seems the issue you were experiencing has been resolved in a more recent version. Please confirm if you are using the latest version. If you are still encountering problems, please provide more details. Additionally, @Callum-Halton, please let us know if you have updated to the latest version and if any further action is required.

Thank you!!

kuaashish avatar Sep 12 '24 06:09 kuaashish

Hi @kuaashish

After updating to the latest version the problem was resolved, many thanks!

Callum-Halton avatar Sep 12 '24 15:09 Callum-Halton

Hi @Callum-Halton,

Thank you for the confirmation. As the issue has been resolved, we are closing this and marking it as resolved internally.

kuaashish avatar Sep 13 '24 08:09 kuaashish

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

google-ml-butler[bot] avatar Sep 13 '24 08:09 google-ml-butler[bot]