Skip to content

AttributeError: type object 'Detections' has no attribute 'from_roboflow'. Did you mean: 'from_tensorflow'? #1958

@yjseok

Description

@yjseok

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

Hi,

I want to use "Use sahi" from the Code Snippets → Utilities section on the following page:
https://universe.roboflow.com/conedetection-6g6uc/cone-detection-6ltmn/model/3

from roboflow import Roboflow
import supervision as sv
import numpy as np
import cv2
import tempfile

image_path = "/home/vision01/sitevision/assets/emseong_data/image/cctv1.png"

rf = Roboflow(api_key="l4ccSLMANVHBmR0s1ywX")
project = rf.workspace().project("10k_cones")
model = project.version(1).model

def callback(image: np.ndarray) -> sv.Detections:
    with tempfile.NamedTemporaryFile(suffix=".jpg") as f:
        cv2.imwrite(f.name, image)
        result = model.predict(f.name, confidence=40, overlap=30).json()

    detections = sv.Detections.from_roboflow(result)
    return detections

image = cv2.imread(image_path)

slicer = sv.InferenceSlicer(callback=callback)

detections = slicer(image=image)

# add your classes from Roboflow, as they appear in the "Classes" section of the "Overview" tab of your model
classes = ["orange_cone"]

prediction_num = len(detections.xyxy)

box_annotator = sv.BoxAnnotator()

annotated_frame = box_annotator.annotate(
    scene=image.copy(),
    detections=detections,
    labels=[classes[detections.class_id[i]] for i in range(prediction_num)],
)

sv.plot_image(image=annotated_frame, size=(16, 16))

But I get the following error:
AttributeError: type object 'Detections' has no attribute 'from_roboflow'. Did you mean: 'from_tensorflow'?

How can I fix this?

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions