google-ai-edge / mediapipe

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

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

Closed Callum-Halton closed 3 days ago

Callum-Halton commented 3 weeks ago

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

kuaashish commented 3 weeks ago

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!!

github-actions[bot] commented 2 weeks 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.

JeongJun-Lee commented 1 week ago

Same here

kuaashish commented 4 days ago

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!!

Callum-Halton commented 4 days ago

Hi @kuaashish

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

kuaashish commented 3 days ago

Hi @Callum-Halton,

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

google-ml-butler[bot] commented 3 days ago

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