import{S as ia,i as oa,s as na,e as i,k as r,w as f,t as c,M as ra,c as o,d as e,m as p,a as n,x as g,h,b as m,N as la,G as l,g as t,y as u,L as pa,q as d,o as b,B as y,v as ca}from"../../chunks/vendor-hf-doc-builder.js";import{I as Ue}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as $}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as ha}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function ma(Te){let w,ds,M,x,rs,Z,Ls,ps,Ks,bs,E,ys,X,Os,js,V,se,ws,A,ee,Ms,P,ae,vs,D,te,Js,k,cs,le,ie,hs,oe,xs,L,ne,ks,z,Us,v,U,ms,I,re,fs,pe,Ts,j,ce,K,he,me,R,fe,ge,_s,G,$s,O,ue,Zs,W,Es,N,ss,_e,zs,es,de,Is,B,Rs,J,T,gs,C,be,us,ye,Gs,as,je,Ws,_,we,Y,Me,ve,Ns,H,Bs,ts,Je,Cs,q,Ys,S,ls,$e,Hs,is,xe,qs,F,Ss,os,ke,Fs,Q,Qs;return Z=new Ue({}),E=new ha({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_image_classification.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/zero_shot_image_classification.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/zero_shot_image_classification.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/zero_shot_image_classification.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/zero_shot_image_classification.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/zero_shot_image_classification.ipynb"}]}}),z=new $({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwdHJhbnNmb3JtZXJz",highlighted:"pip install -q transformers"}}),I=new Ue({}),G=new $({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBY2hlY2twb2ludCUyMCUzRCUyMCUyMm9wZW5haSUyRmNsaXAtdml0LWxhcmdlLXBhdGNoMTQlMjIlMEFkZXRlY3RvciUyMCUzRCUyMHBpcGVsaW5lKG1vZGVsJTNEY2hlY2twb2ludCUyQyUyMHRhc2slM0QlMjJ6ZXJvLXNob3QtaW1hZ2UtY2xhc3NpZmljYXRpb24lMjIp",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;openai/clip-vit-large-patch14&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>detector = pipeline(model=checkpoint, task=<span class="hljs-string">&quot;zero-shot-image-classification&quot;</span>)`}}),W=new $({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRnVuc3BsYXNoLmNvbSUyRnBob3RvcyUyRmc4b1M4LTgyRHhJJTJGZG93bmxvYWQlM0ZpeGlkJTNETW53eE1qQTNmREI4TVh4MGIzQnBZM3g4U25Cbk5rdHBaR3d0U0d0OGZIeDhmREo4ZkRFMk56Z3hNRFl3T0RjJTI2Zm9yY2UlM0R0cnVlJTI2dyUzRDY0MCUyMiUwQWltYWdlJTIwJTNEJTIwSW1hZ2Uub3BlbihyZXF1ZXN0cy5nZXQodXJsJTJDJTIwc3RyZWFtJTNEVHJ1ZSkucmF3KSUwQSUwQWltYWdl",highlighted:`<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><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/g8oS8-82DxI/download?ixid=MnwxMjA3fDB8MXx0b3BpY3x8SnBnNktpZGwtSGt8fHx8fDJ8fDE2NzgxMDYwODc&amp;force=true&amp;w=640&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = 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>image`}}),B=new $({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjBjbGFzc2lmaWVyKGltYWdlJTJDJTIwY2FuZGlkYXRlX2xhYmVscyUzRCU1QiUyMmZveCUyMiUyQyUyMCUyMmJlYXIlMjIlMkMlMjAlMjJzZWFndWxsJTIyJTJDJTIwJTIyb3dsJTIyJTVEKSUwQXByZWRpY3Rpb25z",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predictions = classifier(image, candidate_labels=[<span class="hljs-string">&quot;fox&quot;</span>, <span class="hljs-string">&quot;bear&quot;</span>, <span class="hljs-string">&quot;seagull&quot;</span>, <span class="hljs-string">&quot;owl&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>predictions
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9996670484542847</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;owl&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.000199399160919711</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;seagull&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">7.392891711788252e-05</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;fox&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">5.96074532950297e-05</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;bear&#x27;</span>}]`}}),C=new Ue({}),H=new $({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBBdXRvTW9kZWxGb3JaZXJvU2hvdEltYWdlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclplcm9TaG90SW1hZ2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, AutoModelForZeroShotImageClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForZeroShotImageClassification.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(checkpoint)`}}),q=new $({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRnVuc3BsYXNoLmNvbSUyRnBob3RvcyUyRnhCUlFmUjJicU5JJTJGZG93bmxvYWQlM0ZpeGlkJTNETW53eE1qQTNmREI4TVh4aGJHeDhmSHg4Zkh4OGZId3hOamM0TXpnNE9ERXglMjZmb3JjZSUzRHRydWUlMjZ3JTNENjQwJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBJTBBaW1hZ2U=",highlighted:`<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><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/xBRQfR2bqNI/download?ixid=MnwxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNjc4Mzg4ODEx&amp;force=true&amp;w=640&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = 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>image`}}),F=new $({props:{code:"Y2FuZGlkYXRlX2xhYmVscyUyMCUzRCUyMCU1QiUyMnRyZWUlMjIlMkMlMjAlMjJjYXIlMjIlMkMlMjAlMjJiaWtlJTIyJTJDJTIwJTIyY2F0JTIyJTVEJTBBaW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlJTJDJTIwdGV4dCUzRGNhbmRpZGF0ZV9sYWJlbHMlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyJTJDJTIwcGFkZGluZyUzRFRydWUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>candidate_labels = [<span class="hljs-string">&quot;tree&quot;</span>, <span class="hljs-string">&quot;car&quot;</span>, <span class="hljs-string">&quot;bike&quot;</span>, <span class="hljs-string">&quot;cat&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(images=image, text=candidate_labels, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>, padding=<span class="hljs-literal">True</span>)`}}),Q=new $({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQWxvZ2l0cyUyMCUzRCUyMG91dHB1dHMubG9naXRzX3Blcl9pbWFnZSU1QjAlNUQlMEFwcm9icyUyMCUzRCUyMGxvZ2l0cy5zb2Z0bWF4KGRpbSUzRC0xKS5udW1weSgpJTBBc2NvcmVzJTIwJTNEJTIwcHJvYnMudG9saXN0KCklMEElMEFyZXN1bHQlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMjJzY29yZSUyMiUzQSUyMHNjb3JlJTJDJTIwJTIybGFiZWwlMjIlM0ElMjBjYW5kaWRhdGVfbGFiZWwlN0QlMEElMjAlMjAlMjAlMjBmb3IlMjBzY29yZSUyQyUyMGNhbmRpZGF0ZV9sYWJlbCUyMGluJTIwc29ydGVkKHppcChwcm9icyUyQyUyMGNhbmRpZGF0ZV9sYWJlbHMpJTJDJTIwa2V5JTNEbGFtYmRhJTIweCUzQSUyMC14JTVCMCU1RCklMEElNUQlMEElMEFyZXN1bHQ=",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">&gt;&gt;&gt; </span>logits = outputs.logits_per_image[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>probs = logits.softmax(dim=-<span class="hljs-number">1</span>).numpy()
<span class="hljs-meta">&gt;&gt;&gt; </span>scores = probs.tolist()

<span class="hljs-meta">&gt;&gt;&gt; </span>result = [
<span class="hljs-meta">... </span>    {<span class="hljs-string">&quot;score&quot;</span>: score, <span class="hljs-string">&quot;label&quot;</span>: candidate_label}
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> score, candidate_label <span class="hljs-keyword">in</span> <span class="hljs-built_in">sorted</span>(<span class="hljs-built_in">zip</span>(probs, candidate_labels), key=<span class="hljs-keyword">lambda</span> x: -x[<span class="hljs-number">0</span>])
<span class="hljs-meta">... </span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>result
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.998572</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;car&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0010570387</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;bike&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0003393686</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;tree&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">3.1572064e-05</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;cat&#x27;</span>}]`}}),{c(){w=i("meta"),ds=r(),M=i("h1"),x=i("a"),rs=i("span"),f(Z.$$.fragment),Ls=r(),ps=i("span"),Ks=c("Zero-shot image classification"),bs=r(),f(E.$$.fragment),ys=r(),X=i("p"),Os=c(`Zero-shot image classification is a task that involves classifying images into different categories using a model that was
not explicitly trained on data containing labeled examples from those specific categories.`),js=r(),V=i("p"),se=c(`Traditionally, image classification requires training a model on a specific set of labeled images, and this model learns to
\u201Cmap\u201D certain image features to labels. When there\u2019s a need to use such model for a classification task that introduces a
new set of labels, fine-tuning is required to \u201Crecalibrate\u201D the model.`),ws=r(),A=i("p"),ee=c(`In contrast, zero-shot or open vocabulary image classification models are typically multi-modal models that have been trained on a large
dataset of images and associated descriptions. These models learn aligned vision-language representations that can be used for many downstream tasks including zero-shot image classification.`),Ms=r(),P=i("p"),ae=c(`This is a more flexible approach to image classification that allows models to generalize to new and unseen categories
without the need for additional training data and enables users to query images with free-form text descriptions of their target objects .`),vs=r(),D=i("p"),te=c("In this guide you\u2019ll learn how to:"),Js=r(),k=i("ul"),cs=i("li"),le=c("create a zero-shot image classification pipeline"),ie=r(),hs=i("li"),oe=c("run zero-shot image classification inference by hand"),xs=r(),L=i("p"),ne=c("Before you begin, make sure you have all the necessary libraries installed:"),ks=r(),f(z.$$.fragment),Us=r(),v=i("h2"),U=i("a"),ms=i("span"),f(I.$$.fragment),re=r(),fs=i("span"),pe=c("Zero-shot image classification pipeline"),Ts=r(),j=i("p"),ce=c("The simplest way to try out inference with a model supporting zero-shot image classification is to use the corresponding "),K=i("a"),he=c("pipeline()"),me=c(`.
Instantiate a pipeline from a `),R=i("a"),fe=c("checkpoint on the Hugging Face Hub"),ge=c(":"),_s=r(),f(G.$$.fragment),$s=r(),O=i("p"),ue=c("Next, choose an image you\u2019d like to classify."),Zs=r(),f(W.$$.fragment),Es=r(),N=i("div"),ss=i("img"),zs=r(),es=i("p"),de=c(`Pass the image and the candidate object labels to the pipeline. Here we pass the image directly; other suitable options
include a local path to an image or an image url.
The candidate labels can be simple words like in this example, or more descriptive.`),Is=r(),f(B.$$.fragment),Rs=r(),J=i("h2"),T=i("a"),gs=i("span"),f(C.$$.fragment),be=r(),us=i("span"),ye=c("Zero-shot image classification by hand"),Gs=r(),as=i("p"),je=c(`Now that you\u2019ve seen how to use the zero-shot image classification pipeline, let\u2019s take a look how you can run zero-shot
image classification manually.`),Ws=r(),_=i("p"),we=c("Start by loading the model and associated processor from a "),Y=i("a"),Me=c("checkpoint on the Hugging Face Hub"),ve=c(`.
Here we\u2019ll use the same checkpoint as before:`),Ns=r(),f(H.$$.fragment),Bs=r(),ts=i("p"),Je=c("Let\u2019s take a different image to switch things up."),Cs=r(),f(q.$$.fragment),Ys=r(),S=i("div"),ls=i("img"),Hs=r(),is=i("p"),xe=c(`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 tokenizer that takes care of the text inputs.`),qs=r(),f(F.$$.fragment),Ss=r(),os=i("p"),ke=c("Pass the inputs through the model, and post-process the results:"),Fs=r(),f(Q.$$.fragment),this.h()},l(s){const a=ra('[data-svelte="svelte-1phssyn"]',document.head);w=o(a,"META",{name:!0,content:!0}),a.forEach(e),ds=p(s),M=o(s,"H1",{class:!0});var Xs=n(M);x=o(Xs,"A",{id:!0,class:!0,href:!0});var Ze=n(x);rs=o(Ze,"SPAN",{});var Ee=n(rs);g(Z.$$.fragment,Ee),Ee.forEach(e),Ze.forEach(e),Ls=p(Xs),ps=o(Xs,"SPAN",{});var ze=n(ps);Ks=h(ze,"Zero-shot image classification"),ze.forEach(e),Xs.forEach(e),bs=p(s),g(E.$$.fragment,s),ys=p(s),X=o(s,"P",{});var Ie=n(X);Os=h(Ie,`Zero-shot image classification is a task that involves classifying images into different categories using a model that was
not explicitly trained on data containing labeled examples from those specific categories.`),Ie.forEach(e),js=p(s),V=o(s,"P",{});var Re=n(V);se=h(Re,`Traditionally, image classification requires training a model on a specific set of labeled images, and this model learns to
\u201Cmap\u201D certain image features to labels. When there\u2019s a need to use such model for a classification task that introduces a
new set of labels, fine-tuning is required to \u201Crecalibrate\u201D the model.`),Re.forEach(e),ws=p(s),A=o(s,"P",{});var Ge=n(A);ee=h(Ge,`In contrast, zero-shot or open vocabulary image classification models are typically multi-modal models that have been trained on a large
dataset of images and associated descriptions. These models learn aligned vision-language representations that can be used for many downstream tasks including zero-shot image classification.`),Ge.forEach(e),Ms=p(s),P=o(s,"P",{});var We=n(P);ae=h(We,`This is a more flexible approach to image classification that allows models to generalize to new and unseen categories
without the need for additional training data and enables users to query images with free-form text descriptions of their target objects .`),We.forEach(e),vs=p(s),D=o(s,"P",{});var Ne=n(D);te=h(Ne,"In this guide you\u2019ll learn how to:"),Ne.forEach(e),Js=p(s),k=o(s,"UL",{});var Vs=n(k);cs=o(Vs,"LI",{});var Be=n(cs);le=h(Be,"create a zero-shot image classification pipeline"),Be.forEach(e),ie=p(Vs),hs=o(Vs,"LI",{});var Ce=n(hs);oe=h(Ce,"run zero-shot image classification inference by hand"),Ce.forEach(e),Vs.forEach(e),xs=p(s),L=o(s,"P",{});var Ye=n(L);ne=h(Ye,"Before you begin, make sure you have all the necessary libraries installed:"),Ye.forEach(e),ks=p(s),g(z.$$.fragment,s),Us=p(s),v=o(s,"H2",{class:!0});var As=n(v);U=o(As,"A",{id:!0,class:!0,href:!0});var He=n(U);ms=o(He,"SPAN",{});var qe=n(ms);g(I.$$.fragment,qe),qe.forEach(e),He.forEach(e),re=p(As),fs=o(As,"SPAN",{});var Se=n(fs);pe=h(Se,"Zero-shot image classification pipeline"),Se.forEach(e),As.forEach(e),Ts=p(s),j=o(s,"P",{});var ns=n(j);ce=h(ns,"The simplest way to try out inference with a model supporting zero-shot image classification is to use the corresponding "),K=o(ns,"A",{href:!0});var Fe=n(K);he=h(Fe,"pipeline()"),Fe.forEach(e),me=h(ns,`.
Instantiate a pipeline from a `),R=o(ns,"A",{href:!0,rel:!0});var Qe=n(R);fe=h(Qe,"checkpoint on the Hugging Face Hub"),Qe.forEach(e),ge=h(ns,":"),ns.forEach(e),_s=p(s),g(G.$$.fragment,s),$s=p(s),O=o(s,"P",{});var Xe=n(O);ue=h(Xe,"Next, choose an image you\u2019d like to classify."),Xe.forEach(e),Zs=p(s),g(W.$$.fragment,s),Es=p(s),N=o(s,"DIV",{class:!0});var Ve=n(N);ss=o(Ve,"IMG",{src:!0,alt:!0}),Ve.forEach(e),zs=p(s),es=o(s,"P",{});var Ae=n(es);de=h(Ae,`Pass the image and the candidate object labels to the pipeline. Here we pass the image directly; other suitable options
include a local path to an image or an image url.
The candidate labels can be simple words like in this example, or more descriptive.`),Ae.forEach(e),Is=p(s),g(B.$$.fragment,s),Rs=p(s),J=o(s,"H2",{class:!0});var Ps=n(J);T=o(Ps,"A",{id:!0,class:!0,href:!0});var Pe=n(T);gs=o(Pe,"SPAN",{});var De=n(gs);g(C.$$.fragment,De),De.forEach(e),Pe.forEach(e),be=p(Ps),us=o(Ps,"SPAN",{});var Le=n(us);ye=h(Le,"Zero-shot image classification by hand"),Le.forEach(e),Ps.forEach(e),Gs=p(s),as=o(s,"P",{});var Ke=n(as);je=h(Ke,`Now that you\u2019ve seen how to use the zero-shot image classification pipeline, let\u2019s take a look how you can run zero-shot
image classification manually.`),Ke.forEach(e),Ws=p(s),_=o(s,"P",{});var Ds=n(_);we=h(Ds,"Start by loading the model and associated processor from a "),Y=o(Ds,"A",{href:!0,rel:!0});var Oe=n(Y);Me=h(Oe,"checkpoint on the Hugging Face Hub"),Oe.forEach(e),ve=h(Ds,`.
Here we\u2019ll use the same checkpoint as before:`),Ds.forEach(e),Ns=p(s),g(H.$$.fragment,s),Bs=p(s),ts=o(s,"P",{});var sa=n(ts);Je=h(sa,"Let\u2019s take a different image to switch things up."),sa.forEach(e),Cs=p(s),g(q.$$.fragment,s),Ys=p(s),S=o(s,"DIV",{class:!0});var ea=n(S);ls=o(ea,"IMG",{src:!0,alt:!0}),ea.forEach(e),Hs=p(s),is=o(s,"P",{});var aa=n(is);xe=h(aa,`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 tokenizer that takes care of the text inputs.`),aa.forEach(e),qs=p(s),g(F.$$.fragment,s),Ss=p(s),os=o(s,"P",{});var ta=n(os);ke=h(ta,"Pass the inputs through the model, and post-process the results:"),ta.forEach(e),Fs=p(s),g(Q.$$.fragment,s),this.h()},h(){m(w,"name","hf:doc:metadata"),m(w,"content",JSON.stringify(fa)),m(x,"id","zeroshot-image-classification"),m(x,"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"),m(x,"href","#zeroshot-image-classification"),m(M,"class","relative group"),m(U,"id","zeroshot-image-classification-pipeline"),m(U,"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"),m(U,"href","#zeroshot-image-classification-pipeline"),m(v,"class","relative group"),m(K,"href","/docs/transformers/v4.33.0/en/main_classes/pipelines#transformers.pipeline"),m(R,"href","https://huggingface.co/models?pipeline_tag=zero-shot-image-classification&sort=downloads"),m(R,"rel","nofollow"),la(ss.src,_e="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/owl.jpg")||m(ss,"src",_e),m(ss,"alt","Photo of an owl"),m(N,"class","flex justify-center"),m(T,"id","zeroshot-image-classification-by-hand"),m(T,"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"),m(T,"href","#zeroshot-image-classification-by-hand"),m(J,"class","relative group"),m(Y,"href","https://huggingface.co/models?pipeline_tag=zero-shot-image-classification&sort=downloads"),m(Y,"rel","nofollow"),la(ls.src,$e="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg")||m(ls,"src",$e),m(ls,"alt","Photo of a car"),m(S,"class","flex justify-center")},m(s,a){l(document.head,w),t(s,ds,a),t(s,M,a),l(M,x),l(x,rs),u(Z,rs,null),l(M,Ls),l(M,ps),l(ps,Ks),t(s,bs,a),u(E,s,a),t(s,ys,a),t(s,X,a),l(X,Os),t(s,js,a),t(s,V,a),l(V,se),t(s,ws,a),t(s,A,a),l(A,ee),t(s,Ms,a),t(s,P,a),l(P,ae),t(s,vs,a),t(s,D,a),l(D,te),t(s,Js,a),t(s,k,a),l(k,cs),l(cs,le),l(k,ie),l(k,hs),l(hs,oe),t(s,xs,a),t(s,L,a),l(L,ne),t(s,ks,a),u(z,s,a),t(s,Us,a),t(s,v,a),l(v,U),l(U,ms),u(I,ms,null),l(v,re),l(v,fs),l(fs,pe),t(s,Ts,a),t(s,j,a),l(j,ce),l(j,K),l(K,he),l(j,me),l(j,R),l(R,fe),l(j,ge),t(s,_s,a),u(G,s,a),t(s,$s,a),t(s,O,a),l(O,ue),t(s,Zs,a),u(W,s,a),t(s,Es,a),t(s,N,a),l(N,ss),t(s,zs,a),t(s,es,a),l(es,de),t(s,Is,a),u(B,s,a),t(s,Rs,a),t(s,J,a),l(J,T),l(T,gs),u(C,gs,null),l(J,be),l(J,us),l(us,ye),t(s,Gs,a),t(s,as,a),l(as,je),t(s,Ws,a),t(s,_,a),l(_,we),l(_,Y),l(Y,Me),l(_,ve),t(s,Ns,a),u(H,s,a),t(s,Bs,a),t(s,ts,a),l(ts,Je),t(s,Cs,a),u(q,s,a),t(s,Ys,a),t(s,S,a),l(S,ls),t(s,Hs,a),t(s,is,a),l(is,xe),t(s,qs,a),u(F,s,a),t(s,Ss,a),t(s,os,a),l(os,ke),t(s,Fs,a),u(Q,s,a),Qs=!0},p:pa,i(s){Qs||(d(Z.$$.fragment,s),d(E.$$.fragment,s),d(z.$$.fragment,s),d(I.$$.fragment,s),d(G.$$.fragment,s),d(W.$$.fragment,s),d(B.$$.fragment,s),d(C.$$.fragment,s),d(H.$$.fragment,s),d(q.$$.fragment,s),d(F.$$.fragment,s),d(Q.$$.fragment,s),Qs=!0)},o(s){b(Z.$$.fragment,s),b(E.$$.fragment,s),b(z.$$.fragment,s),b(I.$$.fragment,s),b(G.$$.fragment,s),b(W.$$.fragment,s),b(B.$$.fragment,s),b(C.$$.fragment,s),b(H.$$.fragment,s),b(q.$$.fragment,s),b(F.$$.fragment,s),b(Q.$$.fragment,s),Qs=!1},d(s){e(w),s&&e(ds),s&&e(M),y(Z),s&&e(bs),y(E,s),s&&e(ys),s&&e(X),s&&e(js),s&&e(V),s&&e(ws),s&&e(A),s&&e(Ms),s&&e(P),s&&e(vs),s&&e(D),s&&e(Js),s&&e(k),s&&e(xs),s&&e(L),s&&e(ks),y(z,s),s&&e(Us),s&&e(v),y(I),s&&e(Ts),s&&e(j),s&&e(_s),y(G,s),s&&e($s),s&&e(O),s&&e(Zs),y(W,s),s&&e(Es),s&&e(N),s&&e(zs),s&&e(es),s&&e(Is),y(B,s),s&&e(Rs),s&&e(J),y(C),s&&e(Gs),s&&e(as),s&&e(Ws),s&&e(_),s&&e(Ns),y(H,s),s&&e(Bs),s&&e(ts),s&&e(Cs),y(q,s),s&&e(Ys),s&&e(S),s&&e(Hs),s&&e(is),s&&e(qs),y(F,s),s&&e(Ss),s&&e(os),s&&e(Fs),y(Q,s)}}}const fa={local:"zeroshot-image-classification",sections:[{local:"zeroshot-image-classification-pipeline",title:"Zero-shot image classification pipeline"},{local:"zeroshot-image-classification-by-hand",title:"Zero-shot image classification by hand"}],title:"Zero-shot image classification"};function ga(Te){return ca(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ja extends ia{constructor(w){super();oa(this,w,ga,ma,na,{})}}export{ja as default,fa as metadata};
