import{S as Wn,i as Hn,s as Cn,e as o,k as r,w as u,t as m,M as Fn,c as l,d as e,m as p,a as i,x as g,h,b as c,N as B,G as a,g as n,y as f,L as Bn,q as d,o as b,B as j,v as Zn}from"../../chunks/vendor-hf-doc-builder.js";import{I as me}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as x}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Gn}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Yn(Oa){let v,he,$,I,Xs,Z,zt,Js,Et,ue,G,ge,P,It,ys,Pt,Tt,fe,T,Lt,vs,At,Dt,de,L,Ot,$s,Vt,Nt,be,qs,Mt,je,ks,St,xe,_,Ks,Wt,Ht,Qs,Ct,Ft,se,Bt,_e,zs,Zt,we,Y,ye,q,A,ee,R,Gt,te,Yt,ve,w,Rt,Es,Ut,Xt,U,Jt,Kt,$e,X,qe,D,Qt,J,sa,ea,ke,K,ze,Q,Is,Va,Ee,Ps,ta,Ie,ss,Pe,Ts,aa,Te,es,Le,ts,Ls,Na,Ae,k,O,ae,as,na,ne,oa,De,As,la,Oe,V,ia,ns,ra,pa,Ve,os,Ne,Ds,ca,Me,ls,Se,is,Os,Ma,We,N,ma,Vs,ha,ua,He,rs,Ce,M,ga,Ns,fa,da,Fe,ps,Be,cs,Ms,Sa,Ze,z,S,oe,ms,ba,le,ja,Ge,Ss,xa,Ye,hs,Re,W,_a,ie,wa,ya,Ue,us,Xe,gs,Ws,Wa,Je,E,H,re,fs,va,pe,$a,Ke,Hs,qa,Qe,Cs,ka,st,ds,et,Fs,za,tt,bs,at,js,Bs,Ha,nt,C,Ea,ce,Ia,Pa,ot,xs,lt,F,Ta,Zs,La,Aa,it,_s,rt,ws,Gs,Ca,pt,Ys,Da,ct,y,Fa,mt;return Z=new me({}),G=new Gn({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/zero_shot_object_detection.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/zero_shot_object_detection.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/zero_shot_object_detection.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/zero_shot_object_detection.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/zero_shot_object_detection.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/zero_shot_object_detection.ipynb"}]}}),Y=new x({props:{code:"pip install -q transformers",highlighted:"pip install -q transformers"}}),R=new me({}),X=new x({props:{code:`from transformers import pipeline

checkpoint = "google/owlvit-base-patch32"
detector = pipeline(model=checkpoint, task="zero-shot-object-detection")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;google/owlvit-base-patch32&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>detector = pipeline(model=checkpoint, task=<span class="hljs-string">&quot;zero-shot-object-detection&quot;</span>)`}}),K=new x({props:{code:`import skimage
import numpy as np
from PIL import Image

image = skimage.data.astronaut()
image = Image.fromarray(np.uint8(image)).convert("RGB")

image`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> skimage
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span>image = skimage.data.astronaut()
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.fromarray(np.uint8(image)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>image`}}),ss=new x({props:{code:`predictions = detector(
    image,
    candidate_labels=["human face", "rocket", "nasa badge", "star-spangled banner"],
)
predictions`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predictions = detector(
<span class="hljs-meta">... </span>    image,
<span class="hljs-meta">... </span>    candidate_labels=[<span class="hljs-string">&quot;human face&quot;</span>, <span class="hljs-string">&quot;rocket&quot;</span>, <span class="hljs-string">&quot;nasa badge&quot;</span>, <span class="hljs-string">&quot;star-spangled banner&quot;</span>],
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>predictions
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.3571370542049408</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;human face&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">180</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: <span class="hljs-number">71</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">271</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">178</span>}},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.28099656105041504</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;nasa badge&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">129</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: <span class="hljs-number">348</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">206</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">427</span>}},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.2110239565372467</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;rocket&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">350</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: -<span class="hljs-number">1</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">468</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">288</span>}},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.13790413737297058</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;star-spangled banner&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">105</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">509</span>}},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.11950037628412247</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;nasa badge&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">277</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: <span class="hljs-number">338</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">327</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">380</span>}},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.10649408400058746</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;rocket&#x27;</span>,
  <span class="hljs-string">&#x27;box&#x27;</span>: {<span class="hljs-string">&#x27;xmin&#x27;</span>: <span class="hljs-number">358</span>, <span class="hljs-string">&#x27;ymin&#x27;</span>: <span class="hljs-number">64</span>, <span class="hljs-string">&#x27;xmax&#x27;</span>: <span class="hljs-number">424</span>, <span class="hljs-string">&#x27;ymax&#x27;</span>: <span class="hljs-number">280</span>}}]`}}),es=new x({props:{code:`from PIL import ImageDraw

draw = ImageDraw.Draw(image)

for prediction in predictions:
    box = prediction["box"]
    label = prediction["label"]
    score = prediction["score"]

    xmin, ymin, xmax, ymax = box.values()
    draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
    draw.text((xmin, ymin), f"{label}: {round(score,2)}", fill="white")

image`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> ImageDraw

<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(image)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> prediction <span class="hljs-keyword">in</span> predictions:
<span class="hljs-meta">... </span>    box = prediction[<span class="hljs-string">&quot;box&quot;</span>]
<span class="hljs-meta">... </span>    label = prediction[<span class="hljs-string">&quot;label&quot;</span>]
<span class="hljs-meta">... </span>    score = prediction[<span class="hljs-string">&quot;score&quot;</span>]

<span class="hljs-meta">... </span>    xmin, ymin, xmax, ymax = box.values()
<span class="hljs-meta">... </span>    draw.rectangle((xmin, ymin, xmax, ymax), outline=<span class="hljs-string">&quot;red&quot;</span>, width=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    draw.text((xmin, ymin), <span class="hljs-string">f&quot;<span class="hljs-subst">{label}</span>: <span class="hljs-subst">{<span class="hljs-built_in">round</span>(score,<span class="hljs-number">2</span>)}</span>&quot;</span>, fill=<span class="hljs-string">&quot;white&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>image`}}),as=new me({}),os=new x({props:{code:`from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection

model = AutoModelForZeroShotObjectDetection.from_pretrained(checkpoint)
processor = AutoProcessor.from_pretrained(checkpoint)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, AutoModelForZeroShotObjectDetection

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForZeroShotObjectDetection.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(checkpoint)`}}),ls=new x({props:{code:`import requests

url = "https://unsplash.com/photos/oj0zeY2Ltk4/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MTR8fHBpY25pY3xlbnwwfHx8fDE2Nzc0OTE1NDk&force=true&w=640"
im = Image.open(requests.get(url, stream=True).raw)
im`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://unsplash.com/photos/oj0zeY2Ltk4/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MTR8fHBpY25pY3xlbnwwfHx8fDE2Nzc0OTE1NDk&amp;force=true&amp;w=640&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>im = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
<span class="hljs-meta">&gt;&gt;&gt; </span>im`}}),rs=new x({props:{code:`text_queries = ["hat", "book", "sunglasses", "camera"]
inputs = processor(text=text_queries, images=im, return_tensors="pt")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>text_queries = [<span class="hljs-string">&quot;hat&quot;</span>, <span class="hljs-string">&quot;book&quot;</span>, <span class="hljs-string">&quot;sunglasses&quot;</span>, <span class="hljs-string">&quot;camera&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(text=text_queries, images=im, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),ps=new x({props:{code:`import torch

with torch.no_grad():
    outputs = model(**inputs)
    target_sizes = torch.tensor([im.size[::-1]])
    results = processor.post_process_object_detection(outputs, threshold=0.1, target_sizes=target_sizes)[0]

draw = ImageDraw.Draw(im)

scores = results["scores"].tolist()
labels = results["labels"].tolist()
boxes = results["boxes"].tolist()

for box, score, label in zip(boxes, scores, labels):
    xmin, ymin, xmax, ymax = box
    draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
    draw.text((xmin, ymin), f"{text_queries[label]}: {round(score,2)}", fill="white")

im`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(**inputs)
<span class="hljs-meta">... </span>    target_sizes = torch.tensor([im.size[::-<span class="hljs-number">1</span>]])
<span class="hljs-meta">... </span>    results = processor.post_process_object_detection(outputs, threshold=<span class="hljs-number">0.1</span>, target_sizes=target_sizes)[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(im)

<span class="hljs-meta">&gt;&gt;&gt; </span>scores = results[<span class="hljs-string">&quot;scores&quot;</span>].tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = results[<span class="hljs-string">&quot;labels&quot;</span>].tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes = results[<span class="hljs-string">&quot;boxes&quot;</span>].tolist()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> box, score, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(boxes, scores, labels):
<span class="hljs-meta">... </span>    xmin, ymin, xmax, ymax = box
<span class="hljs-meta">... </span>    draw.rectangle((xmin, ymin, xmax, ymax), outline=<span class="hljs-string">&quot;red&quot;</span>, width=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    draw.text((xmin, ymin), <span class="hljs-string">f&quot;<span class="hljs-subst">{text_queries[label]}</span>: <span class="hljs-subst">{<span class="hljs-built_in">round</span>(score,<span class="hljs-number">2</span>)}</span>&quot;</span>, fill=<span class="hljs-string">&quot;white&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>im`}}),ms=new me({}),hs=new x({props:{code:`images = [image, im]
text_queries = [
    ["human face", "rocket", "nasa badge", "star-spangled banner"],
    ["hat", "book", "sunglasses", "camera"],
]
inputs = processor(text=text_queries, images=images, return_tensors="pt")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>images = [image, im]
<span class="hljs-meta">&gt;&gt;&gt; </span>text_queries = [
<span class="hljs-meta">... </span>    [<span class="hljs-string">&quot;human face&quot;</span>, <span class="hljs-string">&quot;rocket&quot;</span>, <span class="hljs-string">&quot;nasa badge&quot;</span>, <span class="hljs-string">&quot;star-spangled banner&quot;</span>],
<span class="hljs-meta">... </span>    [<span class="hljs-string">&quot;hat&quot;</span>, <span class="hljs-string">&quot;book&quot;</span>, <span class="hljs-string">&quot;sunglasses&quot;</span>, <span class="hljs-string">&quot;camera&quot;</span>],
<span class="hljs-meta">... </span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(text=text_queries, images=images, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),us=new x({props:{code:`with torch.no_grad():
    outputs = model(**inputs)
    target_sizes = [x.size[::-1] for x in images]
    results = processor.post_process_object_detection(outputs, threshold=0.1, target_sizes=target_sizes)

image_idx = 1
draw = ImageDraw.Draw(images[image_idx])

scores = results[image_idx]["scores"].tolist()
labels = results[image_idx]["labels"].tolist()
boxes = results[image_idx]["boxes"].tolist()

for box, score, label in zip(boxes, scores, labels):
    xmin, ymin, xmax, ymax = box
    draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
    draw.text((xmin, ymin), f"{text_queries[image_idx][label]}: {round(score,2)}", fill="white")

images[image_idx]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(**inputs)
<span class="hljs-meta">... </span>    target_sizes = [x.size[::-<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> images]
<span class="hljs-meta">... </span>    results = processor.post_process_object_detection(outputs, threshold=<span class="hljs-number">0.1</span>, target_sizes=target_sizes)

<span class="hljs-meta">&gt;&gt;&gt; </span>image_idx = <span class="hljs-number">1</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(images[image_idx])

<span class="hljs-meta">&gt;&gt;&gt; </span>scores = results[image_idx][<span class="hljs-string">&quot;scores&quot;</span>].tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = results[image_idx][<span class="hljs-string">&quot;labels&quot;</span>].tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes = results[image_idx][<span class="hljs-string">&quot;boxes&quot;</span>].tolist()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> box, score, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(boxes, scores, labels):
<span class="hljs-meta">... </span>    xmin, ymin, xmax, ymax = box
<span class="hljs-meta">... </span>    draw.rectangle((xmin, ymin, xmax, ymax), outline=<span class="hljs-string">&quot;red&quot;</span>, width=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    draw.text((xmin, ymin), <span class="hljs-string">f&quot;<span class="hljs-subst">{text_queries[image_idx][label]}</span>: <span class="hljs-subst">{<span class="hljs-built_in">round</span>(score,<span class="hljs-number">2</span>)}</span>&quot;</span>, fill=<span class="hljs-string">&quot;white&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>images[image_idx]`}}),fs=new me({}),ds=new x({props:{code:`url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image_target = Image.open(requests.get(url, stream=True).raw)

query_url = "http://images.cocodataset.org/val2017/000000524280.jpg"
query_image = Image.open(requests.get(query_url, stream=True).raw)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_target = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

<span class="hljs-meta">&gt;&gt;&gt; </span>query_url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000524280.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>query_image = Image.<span class="hljs-built_in">open</span>(requests.get(query_url, stream=<span class="hljs-literal">True</span>).raw)`}}),bs=new x({props:{code:`import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 2)
ax[0].imshow(image_target)
ax[1].imshow(query_image)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-meta">&gt;&gt;&gt; </span>fig, ax = plt.subplots(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>ax[<span class="hljs-number">0</span>].imshow(image_target)
<span class="hljs-meta">&gt;&gt;&gt; </span>ax[<span class="hljs-number">1</span>].imshow(query_image)`}}),xs=new x({props:{code:'inputs = processor(images=image_target, query_images=query_image, return_tensors="pt")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(images=image_target, query_images=query_image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)'}}),_s=new x({props:{code:`with torch.no_grad():
    outputs = model.image_guided_detection(**inputs)
    target_sizes = torch.tensor([image_target.size[::-1]])
    results = processor.post_process_image_guided_detection(outputs=outputs, target_sizes=target_sizes)[0]

draw = ImageDraw.Draw(image_target)

scores = results["scores"].tolist()
boxes = results["boxes"].tolist()

for box, score, label in zip(boxes, scores, labels):
    xmin, ymin, xmax, ymax = box
    draw.rectangle((xmin, ymin, xmax, ymax), outline="white", width=4)

image_target`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model.image_guided_detection(**inputs)
<span class="hljs-meta">... </span>    target_sizes = torch.tensor([image_target.size[::-<span class="hljs-number">1</span>]])
<span class="hljs-meta">... </span>    results = processor.post_process_image_guided_detection(outputs=outputs, target_sizes=target_sizes)[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(image_target)

<span class="hljs-meta">&gt;&gt;&gt; </span>scores = results[<span class="hljs-string">&quot;scores&quot;</span>].tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes = results[<span class="hljs-string">&quot;boxes&quot;</span>].tolist()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> box, score, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(boxes, scores, labels):
<span class="hljs-meta">... </span>    xmin, ymin, xmax, ymax = box
<span class="hljs-meta">... </span>    draw.rectangle((xmin, ymin, xmax, ymax), outline=<span class="hljs-string">&quot;white&quot;</span>, width=<span class="hljs-number">4</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>image_target`}}),{c(){v=o("meta"),he=r(),$=o("h1"),I=o("a"),Xs=o("span"),u(Z.$$.fragment),zt=r(),Js=o("span"),Et=m("Zero-shot object detection"),ue=r(),u(G.$$.fragment),ge=r(),P=o("p"),It=m("Traditionally, models used for "),ys=o("a"),Pt=m("object detection"),Tt=m(` require labeled image datasets for training,
and are limited to detecting the set of classes from the training data.`),fe=r(),T=o("p"),Lt=m("Zero-shot object detection is supported by the "),vs=o("a"),At=m("OWL-ViT"),Dt=m(` model which uses a different approach. OWL-ViT
is an open-vocabulary object detector. It means that it can detect objects in images based on free-text queries without
the need to fine-tune the model on labeled datasets.`),de=r(),L=o("p"),Ot=m("OWL-ViT leverages multi-modal representations to perform open-vocabulary detection. It combines "),$s=o("a"),Vt=m("CLIP"),Nt=m(` with
lightweight object classification and localization heads. Open-vocabulary detection is achieved by embedding free-text queries with the text encoder of CLIP and using them as input to the object classification and localization heads.
associate images and their corresponding textual descriptions, and ViT processes image patches as inputs. The authors
of OWL-ViT first trained CLIP from scratch and then fine-tuned OWL-ViT end to end on standard object detection datasets using
a bipartite matching loss.`),be=r(),qs=o("p"),Mt=m("With this approach, the model can detect objects based on textual descriptions without prior training on labeled datasets."),je=r(),ks=o("p"),St=m("In this guide, you will learn how to use OWL-ViT:"),xe=r(),_=o("ul"),Ks=o("li"),Wt=m("to detect objects based on text prompts"),Ht=r(),Qs=o("li"),Ct=m("for batch object detection"),Ft=r(),se=o("li"),Bt=m("for image-guided object detection"),_e=r(),zs=o("p"),Zt=m("Before you begin, make sure you have all the necessary libraries installed:"),we=r(),u(Y.$$.fragment),ye=r(),q=o("h2"),A=o("a"),ee=o("span"),u(R.$$.fragment),Gt=r(),te=o("span"),Yt=m("Zero-shot object detection pipeline"),ve=r(),w=o("p"),Rt=m("The simplest way to try out inference with OWL-ViT is to use it in a "),Es=o("a"),Ut=m("pipeline()"),Xt=m(`. Instantiate a pipeline
for zero-shot object detection from a `),U=o("a"),Jt=m("checkpoint on the Hugging Face Hub"),Kt=m(":"),$e=r(),u(X.$$.fragment),qe=r(),D=o("p"),Qt=m(`Next, choose an image you\u2019d like to detect objects in. Here we\u2019ll use the image of astronaut Eileen Collins that is
a part of the `),J=o("a"),sa=m("NASA"),ea=m(" Great Images dataset."),ke=r(),u(K.$$.fragment),ze=r(),Q=o("div"),Is=o("img"),Ee=r(),Ps=o("p"),ta=m(`Pass the image and the candidate object labels to look for to the pipeline.
Here we pass the image directly; other suitable options include a local path to an image or an image url. We also pass text descriptions for all items we want to query the image for.`),Ie=r(),u(ss.$$.fragment),Pe=r(),Ts=o("p"),aa=m("Let\u2019s visualize the predictions:"),Te=r(),u(es.$$.fragment),Le=r(),ts=o("div"),Ls=o("img"),Ae=r(),k=o("h2"),O=o("a"),ae=o("span"),u(as.$$.fragment),na=r(),ne=o("span"),oa=m("Text-prompted zero-shot object detection by hand"),De=r(),As=o("p"),la=m(`Now that you\u2019ve seen how to use the zero-shot object detection pipeline, let\u2019s replicate the same
result manually.`),Oe=r(),V=o("p"),ia=m("Start by loading the model and associated processor from a "),ns=o("a"),ra=m("checkpoint on the Hugging Face Hub"),pa=m(`.
Here we\u2019ll use the same checkpoint as before:`),Ve=r(),u(os.$$.fragment),Ne=r(),Ds=o("p"),ca=m("Let\u2019s take a different image to switch things up."),Me=r(),u(ls.$$.fragment),Se=r(),is=o("div"),Os=o("img"),We=r(),N=o("p"),ma=m(`Use the processor to prepare the inputs for the model. The processor combines an image processor that prepares the
image for the model by resizing and normalizing it, and a `),Vs=o("a"),ha=m("CLIPTokenizer"),ua=m(" that takes care of the text inputs."),He=r(),u(rs.$$.fragment),Ce=r(),M=o("p"),ga=m(`Pass the inputs through the model, post-process, and visualize the results. Since the image processor resized images before
feeding them to the model, you need to use the `),Ns=o("a"),fa=m("post_process_object_detection()"),da=m(` method to make sure the predicted bounding
boxes have the correct coordinates relative to the original image:`),Fe=r(),u(ps.$$.fragment),Be=r(),cs=o("div"),Ms=o("img"),Ze=r(),z=o("h2"),S=o("a"),oe=o("span"),u(ms.$$.fragment),ba=r(),le=o("span"),ja=m("Batch processing"),Ge=r(),Ss=o("p"),xa=m(`You can pass multiple sets of images and text queries to search for different (or same) objects in several images.
Let\u2019s use both an astronaut image and the beach image together.
For batch processing, you should pass text queries as a nested list to the processor and images as lists of PIL images,
PyTorch tensors, or NumPy arrays.`),Ye=r(),u(hs.$$.fragment),Re=r(),W=o("p"),_a=m(`Previously for post-processing you passed the single image\u2019s size as a tensor, but you can also pass a tuple, or, in case
of several images, a list of tuples. Let\u2019s create predictions for the two examples, and visualize the second one (`),ie=o("code"),wa=m("image_idx = 1"),ya=m(")."),Ue=r(),u(us.$$.fragment),Xe=r(),gs=o("div"),Ws=o("img"),Je=r(),E=o("h2"),H=o("a"),re=o("span"),u(fs.$$.fragment),va=r(),pe=o("span"),$a=m("Image-guided object detection"),Ke=r(),Hs=o("p"),qa=m(`In addition to zero-shot object detection with text queries, OWL-ViT offers image-guided object detection. This means
you can use an image query to find similar objects in the target image.
Unlike text queries, only a single example image is allowed.`),Qe=r(),Cs=o("p"),ka=m(`Let\u2019s take an image with two cats on a couch as a target image, and an image of a single cat
as a query:`),st=r(),u(ds.$$.fragment),et=r(),Fs=o("p"),za=m("Let\u2019s take a quick look at the images:"),tt=r(),u(bs.$$.fragment),at=r(),js=o("div"),Bs=o("img"),nt=r(),C=o("p"),Ea=m("In the preprocessing step, instead of text queries, you now need to use "),ce=o("code"),Ia=m("query_images"),Pa=m(":"),ot=r(),u(xs.$$.fragment),lt=r(),F=o("p"),Ta=m("For predictions, instead of passing the inputs to the model, pass them to "),Zs=o("a"),La=m("image_guided_detection()"),Aa=m(`. Draw the predictions
as before except now there are no labels.`),it=r(),u(_s.$$.fragment),rt=r(),ws=o("div"),Gs=o("img"),pt=r(),Ys=o("p"),Da=m("If you\u2019d like to interactively try out inference with OWL-ViT, check out this demo:"),ct=r(),y=o("iframe"),this.h()},l(s){const t=Fn('[data-svelte="svelte-1phssyn"]',document.head);v=l(t,"META",{name:!0,content:!0}),t.forEach(e),he=p(s),$=l(s,"H1",{class:!0});var ht=i($);I=l(ht,"A",{id:!0,class:!0,href:!0});var Ba=i(I);Xs=l(Ba,"SPAN",{});var Za=i(Xs);g(Z.$$.fragment,Za),Za.forEach(e),Ba.forEach(e),zt=p(ht),Js=l(ht,"SPAN",{});var Ga=i(Js);Et=h(Ga,"Zero-shot object detection"),Ga.forEach(e),ht.forEach(e),ue=p(s),g(G.$$.fragment,s),ge=p(s),P=l(s,"P",{});var ut=i(P);It=h(ut,"Traditionally, models used for "),ys=l(ut,"A",{href:!0});var Ya=i(ys);Pt=h(Ya,"object detection"),Ya.forEach(e),Tt=h(ut,` require labeled image datasets for training,
and are limited to detecting the set of classes from the training data.`),ut.forEach(e),fe=p(s),T=l(s,"P",{});var gt=i(T);Lt=h(gt,"Zero-shot object detection is supported by the "),vs=l(gt,"A",{href:!0});var Ra=i(vs);At=h(Ra,"OWL-ViT"),Ra.forEach(e),Dt=h(gt,` model which uses a different approach. OWL-ViT
is an open-vocabulary object detector. It means that it can detect objects in images based on free-text queries without
the need to fine-tune the model on labeled datasets.`),gt.forEach(e),de=p(s),L=l(s,"P",{});var ft=i(L);Ot=h(ft,"OWL-ViT leverages multi-modal representations to perform open-vocabulary detection. It combines "),$s=l(ft,"A",{href:!0});var Ua=i($s);Vt=h(Ua,"CLIP"),Ua.forEach(e),Nt=h(ft,` with
lightweight object classification and localization heads. Open-vocabulary detection is achieved by embedding free-text queries with the text encoder of CLIP and using them as input to the object classification and localization heads.
associate images and their corresponding textual descriptions, and ViT processes image patches as inputs. The authors
of OWL-ViT first trained CLIP from scratch and then fine-tuned OWL-ViT end to end on standard object detection datasets using
a bipartite matching loss.`),ft.forEach(e),be=p(s),qs=l(s,"P",{});var Xa=i(qs);Mt=h(Xa,"With this approach, the model can detect objects based on textual descriptions without prior training on labeled datasets."),Xa.forEach(e),je=p(s),ks=l(s,"P",{});var Ja=i(ks);St=h(Ja,"In this guide, you will learn how to use OWL-ViT:"),Ja.forEach(e),xe=p(s),_=l(s,"UL",{});var Rs=i(_);Ks=l(Rs,"LI",{});var Ka=i(Ks);Wt=h(Ka,"to detect objects based on text prompts"),Ka.forEach(e),Ht=p(Rs),Qs=l(Rs,"LI",{});var Qa=i(Qs);Ct=h(Qa,"for batch object detection"),Qa.forEach(e),Ft=p(Rs),se=l(Rs,"LI",{});var sn=i(se);Bt=h(sn,"for image-guided object detection"),sn.forEach(e),Rs.forEach(e),_e=p(s),zs=l(s,"P",{});var en=i(zs);Zt=h(en,"Before you begin, make sure you have all the necessary libraries installed:"),en.forEach(e),we=p(s),g(Y.$$.fragment,s),ye=p(s),q=l(s,"H2",{class:!0});var dt=i(q);A=l(dt,"A",{id:!0,class:!0,href:!0});var tn=i(A);ee=l(tn,"SPAN",{});var an=i(ee);g(R.$$.fragment,an),an.forEach(e),tn.forEach(e),Gt=p(dt),te=l(dt,"SPAN",{});var nn=i(te);Yt=h(nn,"Zero-shot object detection pipeline"),nn.forEach(e),dt.forEach(e),ve=p(s),w=l(s,"P",{});var Us=i(w);Rt=h(Us,"The simplest way to try out inference with OWL-ViT is to use it in a "),Es=l(Us,"A",{href:!0});var on=i(Es);Ut=h(on,"pipeline()"),on.forEach(e),Xt=h(Us,`. Instantiate a pipeline
for zero-shot object detection from a `),U=l(Us,"A",{href:!0,rel:!0});var ln=i(U);Jt=h(ln,"checkpoint on the Hugging Face Hub"),ln.forEach(e),Kt=h(Us,":"),Us.forEach(e),$e=p(s),g(X.$$.fragment,s),qe=p(s),D=l(s,"P",{});var bt=i(D);Qt=h(bt,`Next, choose an image you\u2019d like to detect objects in. Here we\u2019ll use the image of astronaut Eileen Collins that is
a part of the `),J=l(bt,"A",{href:!0,rel:!0});var rn=i(J);sa=h(rn,"NASA"),rn.forEach(e),ea=h(bt," Great Images dataset."),bt.forEach(e),ke=p(s),g(K.$$.fragment,s),ze=p(s),Q=l(s,"DIV",{class:!0});var pn=i(Q);Is=l(pn,"IMG",{src:!0,alt:!0}),pn.forEach(e),Ee=p(s),Ps=l(s,"P",{});var cn=i(Ps);ta=h(cn,`Pass the image and the candidate object labels to look for to the pipeline.
Here we pass the image directly; other suitable options include a local path to an image or an image url. We also pass text descriptions for all items we want to query the image for.`),cn.forEach(e),Ie=p(s),g(ss.$$.fragment,s),Pe=p(s),Ts=l(s,"P",{});var mn=i(Ts);aa=h(mn,"Let\u2019s visualize the predictions:"),mn.forEach(e),Te=p(s),g(es.$$.fragment,s),Le=p(s),ts=l(s,"DIV",{class:!0});var hn=i(ts);Ls=l(hn,"IMG",{src:!0,alt:!0}),hn.forEach(e),Ae=p(s),k=l(s,"H2",{class:!0});var jt=i(k);O=l(jt,"A",{id:!0,class:!0,href:!0});var un=i(O);ae=l(un,"SPAN",{});var gn=i(ae);g(as.$$.fragment,gn),gn.forEach(e),un.forEach(e),na=p(jt),ne=l(jt,"SPAN",{});var fn=i(ne);oa=h(fn,"Text-prompted zero-shot object detection by hand"),fn.forEach(e),jt.forEach(e),De=p(s),As=l(s,"P",{});var dn=i(As);la=h(dn,`Now that you\u2019ve seen how to use the zero-shot object detection pipeline, let\u2019s replicate the same
result manually.`),dn.forEach(e),Oe=p(s),V=l(s,"P",{});var xt=i(V);ia=h(xt,"Start by loading the model and associated processor from a "),ns=l(xt,"A",{href:!0,rel:!0});var bn=i(ns);ra=h(bn,"checkpoint on the Hugging Face Hub"),bn.forEach(e),pa=h(xt,`.
Here we\u2019ll use the same checkpoint as before:`),xt.forEach(e),Ve=p(s),g(os.$$.fragment,s),Ne=p(s),Ds=l(s,"P",{});var jn=i(Ds);ca=h(jn,"Let\u2019s take a different image to switch things up."),jn.forEach(e),Me=p(s),g(ls.$$.fragment,s),Se=p(s),is=l(s,"DIV",{class:!0});var xn=i(is);Os=l(xn,"IMG",{src:!0,alt:!0}),xn.forEach(e),We=p(s),N=l(s,"P",{});var _t=i(N);ma=h(_t,`Use the processor to prepare the inputs for the model. The processor combines an image processor that prepares the
image for the model by resizing and normalizing it, and a `),Vs=l(_t,"A",{href:!0});var _n=i(Vs);ha=h(_n,"CLIPTokenizer"),_n.forEach(e),ua=h(_t," that takes care of the text inputs."),_t.forEach(e),He=p(s),g(rs.$$.fragment,s),Ce=p(s),M=l(s,"P",{});var wt=i(M);ga=h(wt,`Pass the inputs through the model, post-process, and visualize the results. Since the image processor resized images before
feeding them to the model, you need to use the `),Ns=l(wt,"A",{href:!0});var wn=i(Ns);fa=h(wn,"post_process_object_detection()"),wn.forEach(e),da=h(wt,` method to make sure the predicted bounding
boxes have the correct coordinates relative to the original image:`),wt.forEach(e),Fe=p(s),g(ps.$$.fragment,s),Be=p(s),cs=l(s,"DIV",{class:!0});var yn=i(cs);Ms=l(yn,"IMG",{src:!0,alt:!0}),yn.forEach(e),Ze=p(s),z=l(s,"H2",{class:!0});var yt=i(z);S=l(yt,"A",{id:!0,class:!0,href:!0});var vn=i(S);oe=l(vn,"SPAN",{});var $n=i(oe);g(ms.$$.fragment,$n),$n.forEach(e),vn.forEach(e),ba=p(yt),le=l(yt,"SPAN",{});var qn=i(le);ja=h(qn,"Batch processing"),qn.forEach(e),yt.forEach(e),Ge=p(s),Ss=l(s,"P",{});var kn=i(Ss);xa=h(kn,`You can pass multiple sets of images and text queries to search for different (or same) objects in several images.
Let\u2019s use both an astronaut image and the beach image together.
For batch processing, you should pass text queries as a nested list to the processor and images as lists of PIL images,
PyTorch tensors, or NumPy arrays.`),kn.forEach(e),Ye=p(s),g(hs.$$.fragment,s),Re=p(s),W=l(s,"P",{});var vt=i(W);_a=h(vt,`Previously for post-processing you passed the single image\u2019s size as a tensor, but you can also pass a tuple, or, in case
of several images, a list of tuples. Let\u2019s create predictions for the two examples, and visualize the second one (`),ie=l(vt,"CODE",{});var zn=i(ie);wa=h(zn,"image_idx = 1"),zn.forEach(e),ya=h(vt,")."),vt.forEach(e),Ue=p(s),g(us.$$.fragment,s),Xe=p(s),gs=l(s,"DIV",{class:!0});var En=i(gs);Ws=l(En,"IMG",{src:!0,alt:!0}),En.forEach(e),Je=p(s),E=l(s,"H2",{class:!0});var $t=i(E);H=l($t,"A",{id:!0,class:!0,href:!0});var In=i(H);re=l(In,"SPAN",{});var Pn=i(re);g(fs.$$.fragment,Pn),Pn.forEach(e),In.forEach(e),va=p($t),pe=l($t,"SPAN",{});var Tn=i(pe);$a=h(Tn,"Image-guided object detection"),Tn.forEach(e),$t.forEach(e),Ke=p(s),Hs=l(s,"P",{});var Ln=i(Hs);qa=h(Ln,`In addition to zero-shot object detection with text queries, OWL-ViT offers image-guided object detection. This means
you can use an image query to find similar objects in the target image.
Unlike text queries, only a single example image is allowed.`),Ln.forEach(e),Qe=p(s),Cs=l(s,"P",{});var An=i(Cs);ka=h(An,`Let\u2019s take an image with two cats on a couch as a target image, and an image of a single cat
as a query:`),An.forEach(e),st=p(s),g(ds.$$.fragment,s),et=p(s),Fs=l(s,"P",{});var Dn=i(Fs);za=h(Dn,"Let\u2019s take a quick look at the images:"),Dn.forEach(e),tt=p(s),g(bs.$$.fragment,s),at=p(s),js=l(s,"DIV",{class:!0});var On=i(js);Bs=l(On,"IMG",{src:!0,alt:!0}),On.forEach(e),nt=p(s),C=l(s,"P",{});var qt=i(C);Ea=h(qt,"In the preprocessing step, instead of text queries, you now need to use "),ce=l(qt,"CODE",{});var Vn=i(ce);Ia=h(Vn,"query_images"),Vn.forEach(e),Pa=h(qt,":"),qt.forEach(e),ot=p(s),g(xs.$$.fragment,s),lt=p(s),F=l(s,"P",{});var kt=i(F);Ta=h(kt,"For predictions, instead of passing the inputs to the model, pass them to "),Zs=l(kt,"A",{href:!0});var Nn=i(Zs);La=h(Nn,"image_guided_detection()"),Nn.forEach(e),Aa=h(kt,`. Draw the predictions
as before except now there are no labels.`),kt.forEach(e),it=p(s),g(_s.$$.fragment,s),rt=p(s),ws=l(s,"DIV",{class:!0});var Mn=i(ws);Gs=l(Mn,"IMG",{src:!0,alt:!0}),Mn.forEach(e),pt=p(s),Ys=l(s,"P",{});var Sn=i(Ys);Da=h(Sn,"If you\u2019d like to interactively try out inference with OWL-ViT, check out this demo:"),Sn.forEach(e),ct=p(s),y=l(s,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),i(y).forEach(e),this.h()},h(){c(v,"name","hf:doc:metadata"),c(v,"content",JSON.stringify(Rn)),c(I,"id","zeroshot-object-detection"),c(I,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(I,"href","#zeroshot-object-detection"),c($,"class","relative group"),c(ys,"href","object_detection"),c(vs,"href","../model_doc/owlvit"),c($s,"href","../model_doc/clip"),c(A,"id","zeroshot-object-detection-pipeline"),c(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(A,"href","#zeroshot-object-detection-pipeline"),c(q,"class","relative group"),c(Es,"href","/docs/transformers/v4.29.0/en/main_classes/pipelines#transformers.pipeline"),c(U,"href","https://huggingface.co/models?other=owlvit"),c(U,"rel","nofollow"),c(J,"href","https://www.nasa.gov/multimedia/imagegallery/index.html"),c(J,"rel","nofollow"),B(Is.src,Va="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_1.png")||c(Is,"src",Va),c(Is,"alt","Astronaut Eileen Collins"),c(Q,"class","flex justify-center"),B(Ls.src,Na="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_2.png")||c(Ls,"src",Na),c(Ls,"alt","Visualized predictions on NASA image"),c(ts,"class","flex justify-center"),c(O,"id","textprompted-zeroshot-object-detection-by-hand"),c(O,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(O,"href","#textprompted-zeroshot-object-detection-by-hand"),c(k,"class","relative group"),c(ns,"href","https://huggingface.co/models?other=owlvit"),c(ns,"rel","nofollow"),B(Os.src,Ma="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_3.png")||c(Os,"src",Ma),c(Os,"alt","Beach photo"),c(is,"class","flex justify-center"),c(Vs,"href","/docs/transformers/v4.29.0/en/model_doc/clip#transformers.CLIPTokenizer"),c(Ns,"href","/docs/transformers/v4.29.0/en/model_doc/owlvit#transformers.OwlViTImageProcessor.post_process_object_detection"),B(Ms.src,Sa="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_4.png")||c(Ms,"src",Sa),c(Ms,"alt","Beach photo with detected objects"),c(cs,"class","flex justify-center"),c(S,"id","batch-processing"),c(S,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(S,"href","#batch-processing"),c(z,"class","relative group"),B(Ws.src,Wa="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_4.png")||c(Ws,"src",Wa),c(Ws,"alt","Beach photo with detected objects"),c(gs,"class","flex justify-center"),c(H,"id","imageguided-object-detection"),c(H,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(H,"href","#imageguided-object-detection"),c(E,"class","relative group"),B(Bs.src,Ha="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_5.png")||c(Bs,"src",Ha),c(Bs,"alt","Cats"),c(js,"class","flex justify-center"),c(Zs,"href","/docs/transformers/v4.29.0/en/model_doc/owlvit#transformers.OwlViTForObjectDetection.image_guided_detection"),B(Gs.src,Ca="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_6.png")||c(Gs,"src",Ca),c(Gs,"alt","Cats with bounding boxes"),c(ws,"class","flex justify-center"),B(y.src,Fa="https://adirik-owl-vit.hf.space")||c(y,"src",Fa),c(y,"frameborder","0"),c(y,"width","850"),c(y,"height","450")},m(s,t){a(document.head,v),n(s,he,t),n(s,$,t),a($,I),a(I,Xs),f(Z,Xs,null),a($,zt),a($,Js),a(Js,Et),n(s,ue,t),f(G,s,t),n(s,ge,t),n(s,P,t),a(P,It),a(P,ys),a(ys,Pt),a(P,Tt),n(s,fe,t),n(s,T,t),a(T,Lt),a(T,vs),a(vs,At),a(T,Dt),n(s,de,t),n(s,L,t),a(L,Ot),a(L,$s),a($s,Vt),a(L,Nt),n(s,be,t),n(s,qs,t),a(qs,Mt),n(s,je,t),n(s,ks,t),a(ks,St),n(s,xe,t),n(s,_,t),a(_,Ks),a(Ks,Wt),a(_,Ht),a(_,Qs),a(Qs,Ct),a(_,Ft),a(_,se),a(se,Bt),n(s,_e,t),n(s,zs,t),a(zs,Zt),n(s,we,t),f(Y,s,t),n(s,ye,t),n(s,q,t),a(q,A),a(A,ee),f(R,ee,null),a(q,Gt),a(q,te),a(te,Yt),n(s,ve,t),n(s,w,t),a(w,Rt),a(w,Es),a(Es,Ut),a(w,Xt),a(w,U),a(U,Jt),a(w,Kt),n(s,$e,t),f(X,s,t),n(s,qe,t),n(s,D,t),a(D,Qt),a(D,J),a(J,sa),a(D,ea),n(s,ke,t),f(K,s,t),n(s,ze,t),n(s,Q,t),a(Q,Is),n(s,Ee,t),n(s,Ps,t),a(Ps,ta),n(s,Ie,t),f(ss,s,t),n(s,Pe,t),n(s,Ts,t),a(Ts,aa),n(s,Te,t),f(es,s,t),n(s,Le,t),n(s,ts,t),a(ts,Ls),n(s,Ae,t),n(s,k,t),a(k,O),a(O,ae),f(as,ae,null),a(k,na),a(k,ne),a(ne,oa),n(s,De,t),n(s,As,t),a(As,la),n(s,Oe,t),n(s,V,t),a(V,ia),a(V,ns),a(ns,ra),a(V,pa),n(s,Ve,t),f(os,s,t),n(s,Ne,t),n(s,Ds,t),a(Ds,ca),n(s,Me,t),f(ls,s,t),n(s,Se,t),n(s,is,t),a(is,Os),n(s,We,t),n(s,N,t),a(N,ma),a(N,Vs),a(Vs,ha),a(N,ua),n(s,He,t),f(rs,s,t),n(s,Ce,t),n(s,M,t),a(M,ga),a(M,Ns),a(Ns,fa),a(M,da),n(s,Fe,t),f(ps,s,t),n(s,Be,t),n(s,cs,t),a(cs,Ms),n(s,Ze,t),n(s,z,t),a(z,S),a(S,oe),f(ms,oe,null),a(z,ba),a(z,le),a(le,ja),n(s,Ge,t),n(s,Ss,t),a(Ss,xa),n(s,Ye,t),f(hs,s,t),n(s,Re,t),n(s,W,t),a(W,_a),a(W,ie),a(ie,wa),a(W,ya),n(s,Ue,t),f(us,s,t),n(s,Xe,t),n(s,gs,t),a(gs,Ws),n(s,Je,t),n(s,E,t),a(E,H),a(H,re),f(fs,re,null),a(E,va),a(E,pe),a(pe,$a),n(s,Ke,t),n(s,Hs,t),a(Hs,qa),n(s,Qe,t),n(s,Cs,t),a(Cs,ka),n(s,st,t),f(ds,s,t),n(s,et,t),n(s,Fs,t),a(Fs,za),n(s,tt,t),f(bs,s,t),n(s,at,t),n(s,js,t),a(js,Bs),n(s,nt,t),n(s,C,t),a(C,Ea),a(C,ce),a(ce,Ia),a(C,Pa),n(s,ot,t),f(xs,s,t),n(s,lt,t),n(s,F,t),a(F,Ta),a(F,Zs),a(Zs,La),a(F,Aa),n(s,it,t),f(_s,s,t),n(s,rt,t),n(s,ws,t),a(ws,Gs),n(s,pt,t),n(s,Ys,t),a(Ys,Da),n(s,ct,t),n(s,y,t),mt=!0},p:Bn,i(s){mt||(d(Z.$$.fragment,s),d(G.$$.fragment,s),d(Y.$$.fragment,s),d(R.$$.fragment,s),d(X.$$.fragment,s),d(K.$$.fragment,s),d(ss.$$.fragment,s),d(es.$$.fragment,s),d(as.$$.fragment,s),d(os.$$.fragment,s),d(ls.$$.fragment,s),d(rs.$$.fragment,s),d(ps.$$.fragment,s),d(ms.$$.fragment,s),d(hs.$$.fragment,s),d(us.$$.fragment,s),d(fs.$$.fragment,s),d(ds.$$.fragment,s),d(bs.$$.fragment,s),d(xs.$$.fragment,s),d(_s.$$.fragment,s),mt=!0)},o(s){b(Z.$$.fragment,s),b(G.$$.fragment,s),b(Y.$$.fragment,s),b(R.$$.fragment,s),b(X.$$.fragment,s),b(K.$$.fragment,s),b(ss.$$.fragment,s),b(es.$$.fragment,s),b(as.$$.fragment,s),b(os.$$.fragment,s),b(ls.$$.fragment,s),b(rs.$$.fragment,s),b(ps.$$.fragment,s),b(ms.$$.fragment,s),b(hs.$$.fragment,s),b(us.$$.fragment,s),b(fs.$$.fragment,s),b(ds.$$.fragment,s),b(bs.$$.fragment,s),b(xs.$$.fragment,s),b(_s.$$.fragment,s),mt=!1},d(s){e(v),s&&e(he),s&&e($),j(Z),s&&e(ue),j(G,s),s&&e(ge),s&&e(P),s&&e(fe),s&&e(T),s&&e(de),s&&e(L),s&&e(be),s&&e(qs),s&&e(je),s&&e(ks),s&&e(xe),s&&e(_),s&&e(_e),s&&e(zs),s&&e(we),j(Y,s),s&&e(ye),s&&e(q),j(R),s&&e(ve),s&&e(w),s&&e($e),j(X,s),s&&e(qe),s&&e(D),s&&e(ke),j(K,s),s&&e(ze),s&&e(Q),s&&e(Ee),s&&e(Ps),s&&e(Ie),j(ss,s),s&&e(Pe),s&&e(Ts),s&&e(Te),j(es,s),s&&e(Le),s&&e(ts),s&&e(Ae),s&&e(k),j(as),s&&e(De),s&&e(As),s&&e(Oe),s&&e(V),s&&e(Ve),j(os,s),s&&e(Ne),s&&e(Ds),s&&e(Me),j(ls,s),s&&e(Se),s&&e(is),s&&e(We),s&&e(N),s&&e(He),j(rs,s),s&&e(Ce),s&&e(M),s&&e(Fe),j(ps,s),s&&e(Be),s&&e(cs),s&&e(Ze),s&&e(z),j(ms),s&&e(Ge),s&&e(Ss),s&&e(Ye),j(hs,s),s&&e(Re),s&&e(W),s&&e(Ue),j(us,s),s&&e(Xe),s&&e(gs),s&&e(Je),s&&e(E),j(fs),s&&e(Ke),s&&e(Hs),s&&e(Qe),s&&e(Cs),s&&e(st),j(ds,s),s&&e(et),s&&e(Fs),s&&e(tt),j(bs,s),s&&e(at),s&&e(js),s&&e(nt),s&&e(C),s&&e(ot),j(xs,s),s&&e(lt),s&&e(F),s&&e(it),j(_s,s),s&&e(rt),s&&e(ws),s&&e(pt),s&&e(Ys),s&&e(ct),s&&e(y)}}}const Rn={local:"zeroshot-object-detection",sections:[{local:"zeroshot-object-detection-pipeline",title:"Zero-shot object detection pipeline"},{local:"textprompted-zeroshot-object-detection-by-hand",title:"Text-prompted zero-shot object detection by hand"},{local:"batch-processing",title:"Batch processing"},{local:"imageguided-object-detection",title:"Image-guided object detection"}],title:"Zero-shot object detection"};function Un(Oa){return Zn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class so extends Wn{constructor(v){super();Hn(this,v,Un,Yn,Cn,{})}}export{so as default,Rn as metadata};
