GithubHelp home page GithubHelp logo

Detections _get_item_() does not handle index arrays of booleans correctly for data dictionary in Detections object. about supervision HOT 3 CLOSED

rolson24 avatar rolson24 commented on May 25, 2024
Detections _get_item_() does not handle index arrays of booleans correctly for data dictionary in Detections object.

from supervision.

Comments (3)

SkalskiP avatar SkalskiP commented on May 25, 2024

Hi @rolson24! 👋🏻 good catch! I conducted my own test, and its results confirm your conclusions.

import numpy as np
import supervision as sv

xyxy = np.array([
    [100, 100, 110, 110],
    [200, 200, 220, 220],
    [300, 300, 330, 330],
    [400, 400, 440, 440],
    [500, 500, 550, 550]
], dtype=float)

confidence = np.array([
    0.1, 0.2, 0.3, 0.4, 0.5
], dtype=float)

class_id = np.array([
    1, 2, 3, 4, 5
], dtype=int)

letter = [
    'a', 'b', 'c', 'd', 'e'
]

detections = sv.Detections(
    xyxy=xyxy,
    class_id=class_id,
    confidence=confidence,
    data={
        "letter": letter
    }
)

detections[[1, 2]]

# Detections(
#     xyxy=array([
#         [200., 200., 220., 220.],
#         [300., 300., 330., 330.]]), 
#     mask=None, 
#     confidence=array([0.2, 0.3]), 
#     class_id=array([2, 3]), 
#     tracker_id=None, 
#     data={'letter': ['b', 'c']}
# )
# OK.

detections[np.array([1, 2])]

# Detections(
#     xyxy=array([
#         [200., 200., 220., 220.],
#         [300., 300., 330., 330.]]), 
#     mask=None, 
#     confidence=array([0.2, 0.3]), 
#     class_id=array([2, 3]), 
#     tracker_id=None, 
#     data={'letter': ['b', 'c']}
# )
# OK.

detections[np.array([1, 1, 1, 1, 1])]

# Detections(
#     xyxy=array([
#         [200., 200., 220., 220.],
#         [200., 200., 220., 220.],
#         [200., 200., 220., 220.],
#         [200., 200., 220., 220.],
#         [200., 200., 220., 220.]]), 
#     mask=None, 
#     confidence=array([0.2, 0.2, 0.2, 0.2, 0.2]), 
#     class_id=array([2, 2, 2, 2, 2]), 
#     tracker_id=None, 
#     data={'letter': ['b', 'b', 'b', 'b', 'b']}
# )
# OK.

detections[np.array([True, True, True, True, True], dtype=bool)]

# Detections(
#     xyxy=array([
#         [100., 100., 110., 110.],
#         [200., 200., 220., 220.],
#         [300., 300., 330., 330.],
#         [400., 400., 440., 440.],
#         [500., 500., 550., 550.]]), 
#     mask=None, 
#     confidence=array([0.1, 0.2, 0.3, 0.4, 0.5]), 
#     class_id=array([1, 2, 3, 4, 5]), 
#     tracker_id=None, 
#     data={'letter': ['b', 'b', 'b', 'b', 'b']}
# )
# WRONG DATA.

detections[np.array([False, False, False, False, False], dtype=bool)]

# ---------------------------------------------------------------------------
# ValueError                                Traceback (most recent call last)
# [<ipython-input-26-634699880563>](https://localhost:8080/#) in <cell line: 1>()
# ----> 1 detections[np.array([False, False, False, False, False], dtype=bool)]
# 
# 4 frames
# [/usr/local/lib/python3.10/dist-packages/supervision/detection/utils.py](https://localhost:8080/#) in validate_data(data, n)
#     724         if isinstance(value, list):
#     725             if len(value) != n:
# --> 726                 raise ValueError(f"Length of list for key '{key}' must be {n}")
#     727         elif isinstance(value, np.ndarray):
#     728             if value.ndim == 1 and value.shape[0] != n:
# 
# ValueError: Length of list for key 'letter' must be 0

from supervision.

SkalskiP avatar SkalskiP commented on May 25, 2024

It was fixed with #1062. Merging!

from supervision.

rolson24 avatar rolson24 commented on May 25, 2024

Great! Thanks!

from supervision.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.