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

Confidence of detections in Florence2 #3

Open
annabasiljose1 opened this issue Aug 12, 2024 · 0 comments
Open

Confidence of detections in Florence2 #3

annabasiljose1 opened this issue Aug 12, 2024 · 0 comments

Comments

@annabasiljose1
Copy link

Hey,
I can see that the confidence is being hardcoded as '1.0' in the file specified below. Is there a specific reason to do that or are you planning to change it?

path: autodistill/autodistill/detection/detection_base_model.py

@DataClass
class Florence2(DetectionBaseModel):
ontology: CaptionOntology

def __init__(self, ontology: CaptionOntology):
    model_id = "microsoft/Florence-2-large"
    self.model = AutoModelForCausalLM.from_pretrained(
        model_id, trust_remote_code=True, device_map="cuda"
    ).eval()
    self.processor = AutoProcessor.from_pretrained(
        model_id, trust_remote_code=True, device_map="cuda"
    )
    self.ontology = ontology

def predict(self, input: str, confidence: int = 0.5) -> sv.Detections:
    image = load_image(input, return_format="PIL")
    ontology_classes = self.ontology.classes()
    result = run_example(
        "<CAPTION_TO_PHRASE_GROUNDING>",
        self.processor,
        self.model,
        image,
        "A photo of " + ", and ".join(ontology_classes) + ".",
    )

    results = result["<CAPTION_TO_PHRASE_GROUNDING>"]

    boxes_and_labels = list(zip(results["bboxes"], results["labels"]))

    if (
        len(
            [
                box
                for box, label in boxes_and_labels
                if label in ontology_classes and ontology_classes
            ]
        )
        == 0
    ):
        return sv.Detections.empty()

    detections = sv.Detections(
        xyxy=np.array(
            [
                box
                for box, label in boxes_and_labels
                if label in ontology_classes and ontology_classes
            ]
        ),
        class_id=np.array(
            [
                ontology_classes.index(label)
                for box, label in boxes_and_labels
                if label in ontology_classes and ontology_classes
            ]
        ),
        **confidence=np.array(
            [
                1.0
                for box, label in boxes_and_labels
                if label in ontology_classes and ontology_classes
            ]
        ),**
    )

    detections = detections[detections.confidence > confidence]

    return detections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant