Upload countgdpp.py with huggingface_hub
Browse files118 unmodified lines119120121122123124125126127128129130131132133134135136137118 unmodified lines):"""Count objects in `image`.text: what to count, e.g. "strawberry".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_exemplar_boxes / negative_exemplar_images: optional, one entry pernegative text, same format as the positive ones.Returns dict with "count", "boxes" (normalized cx, cy, w, h) and "scores"."""device = next(model.parameters()).devicetransform = build_transform()image = _load(image)pos_img = _load(exemplar_image) if exemplar_image is not None else imagenegative_texts = list(negative_texts or [])n_neg = len(negative_texts)neg_boxes = list(negative_exemplar_boxes or [None] * n_neg)118 unmodified lines119120121122123124125126127128129130131132133134135136137138139140141142143118 unmodified lines):"""Count objects in `image`.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"]. Use "" fora negative given by exemplars only. If omitted while negative exemplarsare given, each negative gets "" as its text.negative_exemplar_boxes / negative_exemplar_images: optional, one entry pernegative, 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()).devicetransform = build_transform()image = _load(image)pos_img = _load(exemplar_image) if exemplar_image is not None else imageif 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