Datasets:
Download scripts/dets.py from oneryalcin/ui-controls-web: direct link, hf CLI and curl.
- Browser
- Download file 879 Bytes
-
https://huggingface.co/datasets/oneryalcin/ui-controls-web/resolve/main/scripts/dets.py
- Command line
-
hf download hf://datasets/oneryalcin/ui-controls-web/scripts/dets.py
-
curl -L -o dets.py https://huggingface.co/datasets/oneryalcin/ui-controls-web/resolve/main/scripts/dets.py
879 Bytes
| """Run an RF-DETR checkpoint over a dataset's test pages and save its boxes for eval_dets.py. | |
| Usage: python dets.py <weights> <resolution> <dataset dir under data/> <out.json>""" | |
| import json, sys | |
| from pathlib import Path | |
| import numpy as np | |
| from PIL import Image | |
| from rfdetr import RFDETRMedium | |
| weights, res, data, out = sys.argv[1], int(sys.argv[2]), Path(__file__).parent / "data" / sys.argv[3] / "test", sys.argv[4] | |
| model = RFDETRMedium(pretrain_weights=weights, resolution=res) | |
| dets = {} | |
| for im in json.load(open(data / "_annotations.coco.json"))["images"]: | |
| r = model.predict(np.array(Image.open(data / im["file_name"]).convert("RGB")), threshold=0.05) | |
| dets[im["file_name"][:-4]] = [[float(s), [float(v) for v in b], int(k)] for s, b, k in zip(r.confidence, r.xyxy, r.class_id)] | |
| json.dump(dets, open(out, "w")) | |
| print(out, sum(len(v) for v in dets.values()), "boxes") | |