Instructions to use ustc-community/dfine-small-obj365 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ustc-community/dfine-small-obj365 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("object-detection", model="ustc-community/dfine-small-obj365")# Load model directly from transformers import AutoTokenizer, AutoModelForObjectDetection tokenizer = AutoTokenizer.from_pretrained("ustc-community/dfine-small-obj365") model = AutoModelForObjectDetection.from_pretrained("ustc-community/dfine-small-obj365", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| library_name: transformers | |
| This is the HF transformers implementation for D-FINE | |
| Model: D-FINE-S-OBJ365-COCO | |
| D-FINE, a powerful real-time object detector that achieves outstanding localization precision by redefining the bounding box regression task in DETR models. D-FINE comprises two key components: Fine-grained Distribution Refinement (FDR) and Global Optimal Localization Self-Distillation (GO-LSD). | |
| Usage: | |
| ```python | |
| import torch | |
| import requests | |
| from PIL import Image | |
| from transformers import DFineForObjectDetection, AutoImageProcessor | |
| url = 'http://images.cocodataset.org/val2017/000000039769.jpg' | |
| image = Image.open(requests.get(url, stream=True).raw) | |
| image_processor = AutoImageProcessor.from_pretrained("vladislavbro/dfine_s_obj365") | |
| model = DFineForObjectDetection.from_pretrained("vladislavbro/dfine_s_obj365") | |
| inputs = image_processor(images=image, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3) | |
| for result in results: | |
| for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]): | |
| score, label = score.item(), label_id.item() | |
| box = [round(i, 2) for i in box.tolist()] | |
| print(f"{model.config.id2label[label]}: {score:.2f} {box}") |