Upload countgdpp.py with huggingface_hub
Browse files118 unmodified lines119120121122122123124125125126127128127129130131132133134135136137138139140141142143118 unmodified lines): """Count objects in `image`.
text: what to count, e.g. "strawberry". text: what to count, e.g. "strawberry". Use "" for exemplars only. exemplar_boxes: optional visual exemplars [[x1, y1, x2, y2], ...] in pixels, drawn on `exemplar_image` (defaults to `image`). negative_texts: optional things NOT to count, e.g. ["blueberry"]. negative_texts: optional things NOT to count, e.g. ["blueberry"]. Use "" for a negative given by exemplars only. If omitted while negative exemplars are given, each negative gets "" as its text. negative_exemplar_boxes / negative_exemplar_images: optional, one entry per negative text, same format as the positive ones. negative, same format as the positive ones.
Returns dict with "count", "boxes" (normalized cx, cy, w, h) and "scores". """ if not text and not exemplar_boxes: raise ValueError("Give a positive text, positive exemplar boxes, or both.") device = next(model.parameters()).device transform = build_transform() image = _load(image) pos_img = _load(exemplar_image) if exemplar_image is not None else image if negative_texts is None and negative_exemplar_boxes: negative_texts = [""] * len(negative_exemplar_boxes) negative_texts = list(negative_texts or []) n_neg = len(negative_texts) neg_boxes = list(negative_exemplar_boxes or [None] * n_neg)countgdpp.py+9-3