BRD owlvit
Browse files
app.py
CHANGED
|
@@ -19,11 +19,9 @@ model.eval()
|
|
| 19 |
processor = OwlViTProcessor.from_pretrained("google/owlvit-large-patch14")
|
| 20 |
|
| 21 |
|
| 22 |
-
def query_image(
|
| 23 |
text_queries = text_queries.split(",")
|
| 24 |
|
| 25 |
-
response = requests.get(img_url)
|
| 26 |
-
img = Image.open(BytesIO(response.content))
|
| 27 |
img = np.array(img)
|
| 28 |
|
| 29 |
target_sizes = torch.Tensor([img.shape[:2]])
|
|
@@ -56,9 +54,6 @@ def query_image(img_url, text_queries, score_threshold):
|
|
| 56 |
|
| 57 |
|
| 58 |
description = """
|
| 59 |
-
Gradio demo for <a href="https://huggingface.co/docs/transformers/main/en/model_doc/owlvit">OWL-ViT</a>,
|
| 60 |
-
introduced in <a href="https://arxiv.org/abs/2205.06230">Simple Open-Vocabulary Object Detection
|
| 61 |
-
with Vision Transformers</a>.
|
| 62 |
\n\nYou can use OWL-ViT to query images with text descriptions of any object.
|
| 63 |
To use it, simply input the URL of an image and enter comma separated text descriptions of objects you want to query the image for. You
|
| 64 |
can also use the score threshold slider to set a threshold to filter out low probability predictions.
|
|
@@ -70,7 +65,9 @@ hence you can get better predictions by querying the image with text templates u
|
|
| 70 |
"""
|
| 71 |
demo = gr.Interface(
|
| 72 |
query_image,
|
| 73 |
-
inputs=[
|
|
|
|
|
|
|
| 74 |
outputs="image",
|
| 75 |
title="Zero-Shot Object Detection with OWL-ViT",
|
| 76 |
description=description,
|
|
|
|
| 19 |
processor = OwlViTProcessor.from_pretrained("google/owlvit-large-patch14")
|
| 20 |
|
| 21 |
|
| 22 |
+
def query_image(img, text_queries, score_threshold):
|
| 23 |
text_queries = text_queries.split(",")
|
| 24 |
|
|
|
|
|
|
|
| 25 |
img = np.array(img)
|
| 26 |
|
| 27 |
target_sizes = torch.Tensor([img.shape[:2]])
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
description = """
|
|
|
|
|
|
|
|
|
|
| 57 |
\n\nYou can use OWL-ViT to query images with text descriptions of any object.
|
| 58 |
To use it, simply input the URL of an image and enter comma separated text descriptions of objects you want to query the image for. You
|
| 59 |
can also use the score threshold slider to set a threshold to filter out low probability predictions.
|
|
|
|
| 65 |
"""
|
| 66 |
demo = gr.Interface(
|
| 67 |
query_image,
|
| 68 |
+
inputs=[gr.Image(source="upload"),
|
| 69 |
+
"text",
|
| 70 |
+
gr.Slider(0, 1, value=0.1)],
|
| 71 |
outputs="image",
|
| 72 |
title="Zero-Shot Object Detection with OWL-ViT",
|
| 73 |
description=description,
|