Views
No views yet
1import torch
2from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
3from transformers.image_utils import load_image
4
5
6# Prepare processor and model
7model_id = "rziga/mm_grounding_dino_tiny_o365v1_goldg_v3det"
8device = "cuda" if torch.cuda.is_available() else "cpu"
9processor = AutoProcessor.from_pretrained(model_id)
10model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
11
12# Prepare inputs
13image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14image = load_image(image_url)
15text_labels = [["a cat", "a remote control"]]
16inputs = processor(images=image, text=text_labels, return_tensors="pt").to(device)
17
18# Run inference
19with torch.no_grad():
20 outputs = model(**inputs)
21
22# Postprocess outputs
23results = processor.post_process_grounded_object_detection(
24 outputs,
25 threshold=0.4,
26 target_sizes=[(image.height, image.width)]
27)
28
29# Retrieve the first image result
30result = results[0]
31for box, score, labels in zip(result["boxes"], result["scores"], result["labels"]):
32 box = [round(x, 2) for x in box.tolist()]
33 print(f"Detected {labels} with confidence {round(score.item(), 3)} at location {box}")| Model | Backbone | Pre-Train Data | Style | COCO mAP |
|---|---|---|---|---|
| mm_grounding_dino_tiny_o365v1_goldg | Swin-T | O365,GoldG | Zero-shot | 50.4(+2.3) |
| mm_grounding_dino_tiny_o365v1_goldg_grit | Swin-T | O365,GoldG,GRIT | Zero-shot | 50.5(+2.1) |
| mm_grounding_dino_tiny_o365v1_goldg_v3det | Swin-T | O365,GoldG,V3Det | Zero-shot | 50.6(+2.2) |
| mm_grounding_dino_tiny_o365v1_goldg_grit_v3det | Swin-T | O365,GoldG,GRIT,V3Det | Zero-shot | 50.4(+2.0) |
| mm_grounding_dino_base_o365v1_goldg_v3det | Swin-B | O365,GoldG,V3Det | Zero-shot | 52.5 |
| mm_grounding_dino_base_all | Swin-B | O365,ALL | - | 59.5 |
| mm_grounding_dino_large_o365v2_oiv6_goldg | Swin-L | O365V2,OpenImageV6,GoldG | Zero-shot | 53.0 |
| mm_grounding_dino_large_all | Swin-L | O365V2,OpenImageV6,ALL | - | 60.3 |
| Model | Pre-Train Data | MiniVal APr | MiniVal APc | MiniVal APf | MiniVal AP | Val1.0 APr | Val1.0 APc | Val1.0 APf | Val1.0 AP |
|---|---|---|---|---|---|---|---|---|---|
| mm_grounding_dino_tiny_o365v1_goldg | O365,GoldG | 28.1 | 30.2 | 42.0 | 35.7(+6.9) | 17.1 | 22.4 | 36.5 | 27.0(+6.9) |
| mm_grounding_dino_tiny_o365v1_goldg_grit | O365,GoldG,GRIT | 26.6 | 32.4 | 41.8 | 36.5(+7.7) | 17.3 | 22.6 | 36.4 | 27.1(+7.0) |
| mm_grounding_dino_tiny_o365v1_goldg_v3det | O365,GoldG,V3Det | 33.0 | 36.0 | 45.9 | 40.5(+11.7) | 21.5 | 25.5 | 40.2 | 30.6(+10.5) |
| mm_grounding_dino_tiny_o365v1_goldg_grit_v3det | O365,GoldG,GRIT,V3Det | 34.2 | 37.4 | 46.2 | 41.4(+12.6) | 23.6 | 27.6 | 40.5 | 31.9(+11.8) |
1@article{zhao2024open,
2 title={An Open and Comprehensive Pipeline for Unified Object Grounding and Detection},
3 author={Zhao, Xiangyu and Chen, Yicheng and Xu, Shilin and Li, Xiangtai and Wang, Xinjiang and Li, Yining and Huang, Haian},
4 journal={arXiv preprint arXiv:2401.02361},
5 year={2024}
6}