Upload countgdpp.py with huggingface_hub
Browse files- countgdpp.py +9 -3
countgdpp.py
CHANGED
|
@@ -119,19 +119,25 @@ def count(
|
|
| 119 |
):
|
| 120 |
"""Count objects in `image`.
|
| 121 |
|
| 122 |
-
text: what to count, e.g. "strawberry".
|
| 123 |
exemplar_boxes: optional visual exemplars [[x1, y1, x2, y2], ...] in pixels,
|
| 124 |
drawn on `exemplar_image` (defaults to `image`).
|
| 125 |
-
negative_texts: optional things NOT to count, e.g. ["blueberry"].
|
|
|
|
|
|
|
| 126 |
negative_exemplar_boxes / negative_exemplar_images: optional, one entry per
|
| 127 |
-
negative
|
| 128 |
|
| 129 |
Returns dict with "count", "boxes" (normalized cx, cy, w, h) and "scores".
|
| 130 |
"""
|
|
|
|
|
|
|
| 131 |
device = next(model.parameters()).device
|
| 132 |
transform = build_transform()
|
| 133 |
image = _load(image)
|
| 134 |
pos_img = _load(exemplar_image) if exemplar_image is not None else image
|
|
|
|
|
|
|
| 135 |
negative_texts = list(negative_texts or [])
|
| 136 |
n_neg = len(negative_texts)
|
| 137 |
neg_boxes = list(negative_exemplar_boxes or [None] * n_neg)
|
|
|
|
| 119 |
):
|
| 120 |
"""Count objects in `image`.
|
| 121 |
|
| 122 |
+
text: what to count, e.g. "strawberry". Use "" for exemplars only.
|
| 123 |
exemplar_boxes: optional visual exemplars [[x1, y1, x2, y2], ...] in pixels,
|
| 124 |
drawn on `exemplar_image` (defaults to `image`).
|
| 125 |
+
negative_texts: optional things NOT to count, e.g. ["blueberry"]. Use "" for
|
| 126 |
+
a negative given by exemplars only. If omitted while negative exemplars
|
| 127 |
+
are given, each negative gets "" as its text.
|
| 128 |
negative_exemplar_boxes / negative_exemplar_images: optional, one entry per
|
| 129 |
+
negative, same format as the positive ones.
|
| 130 |
|
| 131 |
Returns dict with "count", "boxes" (normalized cx, cy, w, h) and "scores".
|
| 132 |
"""
|
| 133 |
+
if not text and not exemplar_boxes:
|
| 134 |
+
raise ValueError("Give a positive text, positive exemplar boxes, or both.")
|
| 135 |
device = next(model.parameters()).device
|
| 136 |
transform = build_transform()
|
| 137 |
image = _load(image)
|
| 138 |
pos_img = _load(exemplar_image) if exemplar_image is not None else image
|
| 139 |
+
if negative_texts is None and negative_exemplar_boxes:
|
| 140 |
+
negative_texts = [""] * len(negative_exemplar_boxes)
|
| 141 |
negative_texts = list(negative_texts or [])
|
| 142 |
n_neg = len(negative_texts)
|
| 143 |
neg_boxes = list(negative_exemplar_boxes or [None] * n_neg)
|