Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- vision
|
5 |
+
- object-detection
|
6 |
+
inference: false
|
7 |
+
---
|
8 |
+
|
9 |
+
# Model Card: OWLv2
|
10 |
+
|
11 |
+
## Model Details
|
12 |
+
|
13 |
+
The OWLv2 model (short for Open-World Localization) was proposed in [Scaling Open-Vocabulary Object Detection](https://arxiv.org/abs/2306.09683) by Matthias Minderer, Alexey Gritsenko, Neil Houlsby. OWLv2, like OWL-ViT, is a zero-shot text-conditioned object detection model that can be used to query an image with one or multiple text queries.
|
14 |
+
|
15 |
+
The model uses CLIP as its multi-modal backbone, with a ViT-like Transformer to get visual features and a causal language model to get the text features. To use CLIP for detection, OWL-ViT removes the final token pooling layer of the vision model and attaches a lightweight classification and box head to each transformer output token. Open-vocabulary classification is enabled by replacing the fixed classification layer weights with the class-name embeddings obtained from the text model. The authors first train CLIP from scratch and fine-tune it end-to-end with the classification and box heads on standard detection datasets using a bipartite matching loss. One or multiple text queries per image can be used to perform zero-shot text-conditioned object detection.
|
16 |
+
|
17 |
+
|
18 |
+
### Model Date
|
19 |
+
|
20 |
+
June 2023
|
21 |
+
|
22 |
+
### Model Type
|
23 |
+
|
24 |
+
The model uses a CLIP backbone with a ViT-L/14 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss. The CLIP backbone is trained from scratch and fine-tuned together with the box and class prediction heads with an object detection objective.
|
25 |
+
|
26 |
+
|
27 |
+
### Documents
|
28 |
+
|
29 |
+
- [OWLv2 Paper](https://arxiv.org/abs/2306.09683)
|
30 |
+
|
31 |
+
|
32 |
+
### Use with Transformers
|
33 |
+
|
34 |
+
```python3
|
35 |
+
import requests
|
36 |
+
from PIL import Image
|
37 |
+
import torch
|
38 |
+
|
39 |
+
from transformers import Owlv2Processor, Owlv2ForObjectDetection
|
40 |
+
|
41 |
+
processor = Owlv2Processor.from_pretrained("google/owlv2-large-patch14-ensemble")
|
42 |
+
model = Owlv2ForObjectDetection.from_pretrained("google/owlv2-large-patch14-ensemble")
|
43 |
+
|
44 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
45 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
46 |
+
texts = [["a photo of a cat", "a photo of a dog"]]
|
47 |
+
inputs = processor(text=texts, images=image, return_tensors="pt")
|
48 |
+
outputs = model(**inputs)
|
49 |
+
|
50 |
+
# Target image sizes (height, width) to rescale box predictions [batch_size, 2]
|
51 |
+
target_sizes = torch.Tensor([image.size[::-1]])
|
52 |
+
# Convert outputs (bounding boxes and class logits) to COCO API
|
53 |
+
results = processor.post_process(outputs=outputs, target_sizes=target_sizes)
|
54 |
+
|
55 |
+
i = 0 # Retrieve predictions for the first image for the corresponding text queries
|
56 |
+
text = texts[i]
|
57 |
+
boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
|
58 |
+
|
59 |
+
# Print detected objects and rescaled box coordinates
|
60 |
+
score_threshold = 0.1
|
61 |
+
for box, score, label in zip(boxes, scores, labels):
|
62 |
+
box = [round(i, 2) for i in box.tolist()]
|
63 |
+
if score >= score_threshold:
|
64 |
+
print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
|
65 |
+
```
|
66 |
+
|
67 |
+
|
68 |
+
## Model Use
|
69 |
+
|
70 |
+
### Intended Use
|
71 |
+
|
72 |
+
The model is intended as a research output for research communities. We hope that this model will enable researchers to better understand and explore zero-shot, text-conditioned object detection. We also hope it can be used for interdisciplinary studies of the potential impact of such models, especially in areas that commonly require identifying objects whose label is unavailable during training.
|
73 |
+
|
74 |
+
#### Primary intended uses
|
75 |
+
|
76 |
+
The primary intended users of these models are AI researchers.
|
77 |
+
|
78 |
+
We primarily imagine the model will be used by researchers to better understand robustness, generalization, and other capabilities, biases, and constraints of computer vision models.
|
79 |
+
|
80 |
+
## Data
|
81 |
+
|
82 |
+
The CLIP backbone of the model was trained on publicly available image-caption data. This was done through a combination of crawling a handful of websites and using commonly-used pre-existing image datasets such as [YFCC100M](http://projects.dfki.uni-kl.de/yfcc100m/). A large portion of the data comes from our crawling of the internet. This means that the data is more representative of people and societies most connected to the internet. The prediction heads of OWL-ViT, along with the CLIP backbone, are fine-tuned on publicly available object detection datasets such as [COCO](https://cocodataset.org/#home) and [OpenImages](https://storage.googleapis.com/openimages/web/index.html).
|
83 |
+
|
84 |
+
(to be updated for v2)
|
85 |
+
|
86 |
+
### BibTeX entry and citation info
|
87 |
+
|
88 |
+
```bibtex
|
89 |
+
@misc{minderer2023scaling,
|
90 |
+
title={Scaling Open-Vocabulary Object Detection},
|
91 |
+
author={Matthias Minderer and Alexey Gritsenko and Neil Houlsby},
|
92 |
+
year={2023},
|
93 |
+
eprint={2306.09683},
|
94 |
+
archivePrefix={arXiv},
|
95 |
+
primaryClass={cs.CV}
|
96 |
+
}
|
97 |
+
```
|