import{s as Je,o as ve,n as Te}from"../chunks/scheduler.56725da7.js";import{S as _e,i as xe,e as m,s,c as p,h as Ne,a as c,d as o,b as l,f as ie,g as u,j as _,k as L,l as J,m as n,n as d,t as h,o as g,p as f}from"../chunks/index.18a26576.js";import{C as Ze}from"../chunks/CopyLLMTxtMenu.08cb1880.js";import{D as $e}from"../chunks/Docstring.4f5c8174.js";import{C as he}from"../chunks/CodeBlock.8cfad13f.js";import{E as We}from"../chunks/ExampleCodeBlock.0c069651.js";import{H as S}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.bfeb55ce.js";function Xe(G){let r,x="Example:",w,b,y;return b=new he({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEFmcm9tJTIwb3B0aW11bS5uZXVyb24lMjBpbXBvcnQlMjBOZXVyb25Zb2xvc0Zvck9iamVjdERldGVjdGlvbiUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvSW1hZ2VQcm9jZXNzb3IlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwJTNBJTJGJTJGaW1hZ2VzLmNvY29kYXRhc2V0Lm9yZyUyRnZhbDIwMTclMkYwMDAwMDAwMzk3NjkuanBnJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBJTBBcHJlcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJvcHRpbXVtJTJGeW9sb3MtdGlueS1uZXVyb254LWJzMSUyMiklMEFtb2RlbCUyMCUzRCUyME5ldXJvbllvbG9zRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMjJvcHRpbXVtJTJGeW9sb3MtdGlueS1uZXVyb254LWJzMSUyMiklMEElMEFpbnB1dHMlMjAlM0QlMjBwcmVwcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyklMEF0YXJnZXRfc2l6ZXMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCaW1hZ2Uuc2l6ZSU1QiUzQSUzQS0xJTVEJTVEKSUwQXJlc3VsdHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IucG9zdF9wcm9jZXNzX29iamVjdF9kZXRlY3Rpb24ob3V0cHV0cyUyQyUyMHRocmVzaG9sZCUzRDAuOSUyQyUyMHRhcmdldF9zaXplcyUzRHRhcmdldF9zaXplcyklNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<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">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronYolosForObjectDetection
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor

<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 = 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>preprocessor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;optimum/yolos-tiny-neuronx-bs1&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = NeuronYolosForObjectDetection.from_pretrained(<span class="hljs-string">&quot;optimum/yolos-tiny-neuronx-bs1&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = preprocessor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>target_sizes = torch.tensor([image.size[::-<span class="hljs-number">1</span>]])
<span class="hljs-meta">&gt;&gt;&gt; </span>results = image_processor.post_process_object_detection(outputs, threshold=<span class="hljs-number">0.9</span>, target_sizes=target_sizes)[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){r=m("p"),r.textContent=x,w=s(),p(b.$$.fragment)},l(a){r=c(a,"P",{"data-svelte-h":!0}),_(r)!=="svelte-11lpom8"&&(r.textContent=x),w=l(a),u(b.$$.fragment,a)},m(a,j){n(a,r,j),n(a,w,j),d(b,a,j),y=!0},p:Te,i(a){y||(h(b.$$.fragment,a),y=!0)},o(a){g(b.$$.fragment,a),y=!1},d(a){a&&(o(r),o(w)),f(b,a)}}}function Ve(G){let r,x,w,b,y,a,j,P,N,D,Z,ge=`The YOLOS model was proposed in <a href="https://arxiv.org/abs/2106.00666" rel="nofollow">You Only Look at One Sequence: Rethinking Transformer in Vision through Object Detection</a> by Yuxin Fang, Bencheng Liao, Xinggang Wang, Jiemin Fang, Jiyang Qi, Rui Wu, Jianwei Niu, Wenyu Liu.
YOLOS proposes to just leverage the plain <a href="vit">Vision Transformer (ViT)</a> for object detection, inspired by DETR. It turns out that a base-sized encoder-only Transformer can also achieve 42 AP on COCO, similar to DETR and much more complex frameworks such as Faster R-CNN.`,Q,W,A,X,fe='To deploy 🤗 <a href="https://huggingface.co/docs/transformers/index" rel="nofollow">Transformers</a> models on Neuron devices, you first need to compile the models and export them to a serialized format for inference. Below are two approaches to compile the model, you can choose the one that best suits your needs. Here we take the <code>feature-extraction</code> as an example:',q,V,K,C,be="You can export the model using the Optimum command-line interface as follows:",ee,k,te,v,ye="<p>Execute <code>optimum-cli export neuron --help</code> to display all command line options and their description.</p>",oe,H,ne,I,se,U,le,i,B,me,z,je="Neuron Model with object detection heads on top, for tasks such as COCO detection.",pe,Y,Me=`This model inherits from <code>~neuron.modeling.NeuronTracedModel</code>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving)`,ce,$,R,ue,E,we="The <code>NeuronYolosForObjectDetection</code> forward method, overrides the <code>__call__</code> special method. Accepts only the inputs traced during the compilation step. Any additional inputs provided during inference will be ignored. To include extra inputs, recompile the model with those inputs specified.",de,T,ae,F,re;return y=new Ze({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),j=new S({props:{title:"YOLOS",local:"yolos",headingTag:"h1"}}),N=new S({props:{title:"Overview",local:"overview",headingTag:"h2"}}),W=new S({props:{title:"Export to Neuron",local:"export-to-neuron",headingTag:"h2"}}),V=new S({props:{title:"Option 1: CLI",local:"option-1-cli",headingTag:"h3"}}),k=new he({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBuZXVyb24lMjAtLW1vZGVsJTIwaHVzdHZsJTJGeW9sb3MtdGlueSUyMC0tdGFzayUyMG9iamVjdC1kZXRlY3Rpb24lMjAtLWJhdGNoX3NpemUlMjAxJTIweW9sb3Nfb2JqZWN0X2RldGVjdGlvbl9uZXVyb254JTJG",highlighted:'optimum-cli <span class="hljs-built_in">export</span> neuron --model hustvl/yolos-tiny --task object-detection --batch_size 1 yolos_object_detection_neuronx/',wrap:!1}}),H=new S({props:{title:"Option 2: Python API",local:"option-2-python-api",headingTag:"h3"}}),I=new he({props:{code:"ZnJvbSUyMG9wdGltdW0ubmV1cm9uJTIwaW1wb3J0JTIwTmV1cm9uTW9kZWxGb3JPYmplY3REZXRlY3Rpb24lMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b0ltYWdlUHJvY2Vzc29yJTBBJTBBJTBBcHJlcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJodXN0dmwlMkZ5b2xvcy10aW55JTIyKSUwQW5ldXJvbl9tb2RlbCUyMCUzRCUyME5ldXJvbk1vZGVsRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMjJodXN0dmwlMkZ5b2xvcy10aW55JTIyJTJDJTIwZXhwb3J0JTNEVHJ1ZSUyQyUyMGJhdGNoX3NpemUlM0QxKSUwQSUwQW5ldXJvbl9tb2RlbC5zYXZlX3ByZXRyYWluZWQoJTIyeW9sb3Nfb2JqZWN0X2RldGVjdGlvbl9uZXVyb254JTIyKSUwQW5ldXJvbl9tb2RlbC5wdXNoX3RvX2h1YiglMEElMjAlMjAlMjAlMjAlMjJ5b2xvc19vYmplY3RfZGV0ZWN0aW9uX25ldXJvbnglMjIlMkMlMjByZXBvc2l0b3J5X2lkJTNEJTIyb3B0aW11bSUyRnlvbG9zLXRpbnktbmV1cm9ueC1iczElMjIlMjAlMjAlMjMlMjBSZXBsYWNlJTIwd2l0aCUyMHlvdXIlMjBIRiUyMEh1YiUyMHJlcG8lMjBpZCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronModelForObjectDetection
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor


preprocessor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;hustvl/yolos-tiny&quot;</span>)
neuron_model = NeuronModelForObjectDetection.from_pretrained(<span class="hljs-string">&quot;hustvl/yolos-tiny&quot;</span>, export=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">1</span>)

neuron_model.save_pretrained(<span class="hljs-string">&quot;yolos_object_detection_neuronx&quot;</span>)
neuron_model.push_to_hub(
    <span class="hljs-string">&quot;yolos_object_detection_neuronx&quot;</span>, repository_id=<span class="hljs-string">&quot;optimum/yolos-tiny-neuronx-bs1&quot;</span>  <span class="hljs-comment"># Replace with your HF Hub repo id</span>
)`,wrap:!1}}),U=new S({props:{title:"NeuronYolosForObjectDetection",local:"optimum.neuron.NeuronYolosForObjectDetection",headingTag:"h2"}}),B=new $e({props:{name:"class optimum.neuron.NeuronYolosForObjectDetection",anchor:"optimum.neuron.NeuronYolosForObjectDetection",parameters:[{name:"model",val:": ScriptModule"},{name:"config",val:": PretrainedConfig"},{name:"model_save_dir",val:": str | pathlib.Path | tempfile.TemporaryDirectory | None = None"},{name:"model_file_name",val:": str | None = None"},{name:"preprocessors",val:": list | None = None"},{name:"neuron_config",val:": NeuronDefaultConfig | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"optimum.neuron.NeuronYolosForObjectDetection.config",description:`<strong>config</strong> (<code>transformers.PretrainedConfig</code>) &#x2014; <a href="https://huggingface.co/docs/transformers/main_classes/configuration#transformers.PretrainedConfig" rel="nofollow">PretrainedConfig</a> is the Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <code>optimum.neuron.modeling.NeuronTracedModel.from_pretrained</code> method to load the model weights.`,name:"config"},{anchor:"optimum.neuron.NeuronYolosForObjectDetection.model",description:'<strong>model</strong> (<code>torch.jit._script.ScriptModule</code>) &#x2014; <a href="https://pytorch.org/docs/stable/generated/torch.jit.ScriptModule.html" rel="nofollow">torch.jit._script.ScriptModule</a> is the TorchScript module with embedded NEFF(Neuron Executable File Format) compiled by neuron(x) compiler.',name:"model"}],source:"https://github.com/huggingface/optimum-neuron/blob/vr_1011/optimum/neuron/models/inference/yolos/modeling_yolos.py#L43"}}),R=new $e({props:{name:"forward",anchor:"optimum.neuron.NeuronYolosForObjectDetection.forward",parameters:[{name:"pixel_values",val:": Tensor"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"optimum.neuron.NeuronYolosForObjectDetection.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor | None</code> of shape <code>(batch_size, num_channels, height, width)</code>, defaults to <code>None</code>) &#x2014;
Pixel values corresponding to the images in the current batch.
Pixel values can be obtained from encoded images using <a href="https://huggingface.co/docs/transformers/en/model_doc/auto#transformers.AutoImageProcessor" rel="nofollow"><code>AutoImageProcessor</code></a>.`,name:"pixel_values"}],source:"https://github.com/huggingface/optimum-neuron/blob/vr_1011/optimum/neuron/models/inference/yolos/modeling_yolos.py#L53"}}),T=new We({props:{anchor:"optimum.neuron.NeuronYolosForObjectDetection.forward.example",$$slots:{default:[Xe]},$$scope:{ctx:G}}}),{c(){r=m("meta"),x=s(),w=m("p"),b=s(),p(y.$$.fragment),a=s(),p(j.$$.fragment),P=s(),p(N.$$.fragment),D=s(),Z=m("p"),Z.innerHTML=ge,Q=s(),p(W.$$.fragment),A=s(),X=m("p"),X.innerHTML=fe,q=s(),p(V.$$.fragment),K=s(),C=m("p"),C.textContent=be,ee=s(),p(k.$$.fragment),te=s(),v=m("blockquote"),v.innerHTML=ye,oe=s(),p(H.$$.fragment),ne=s(),p(I.$$.fragment),se=s(),p(U.$$.fragment),le=s(),i=m("div"),p(B.$$.fragment),me=s(),z=m("p"),z.textContent=je,pe=s(),Y=m("p"),Y.innerHTML=Me,ce=s(),$=m("div"),p(R.$$.fragment),ue=s(),E=m("p"),E.innerHTML=we,de=s(),p(T.$$.fragment),ae=s(),F=m("p"),this.h()},l(e){const t=Ne("svelte-u9bgzb",document.head);r=c(t,"META",{name:!0,content:!0}),t.forEach(o),x=l(e),w=c(e,"P",{}),ie(w).forEach(o),b=l(e),u(y.$$.fragment,e),a=l(e),u(j.$$.fragment,e),P=l(e),u(N.$$.fragment,e),D=l(e),Z=c(e,"P",{"data-svelte-h":!0}),_(Z)!=="svelte-98a8ak"&&(Z.innerHTML=ge),Q=l(e),u(W.$$.fragment,e),A=l(e),X=c(e,"P",{"data-svelte-h":!0}),_(X)!=="svelte-huz3tp"&&(X.innerHTML=fe),q=l(e),u(V.$$.fragment,e),K=l(e),C=c(e,"P",{"data-svelte-h":!0}),_(C)!=="svelte-87nkn2"&&(C.textContent=be),ee=l(e),u(k.$$.fragment,e),te=l(e),v=c(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),_(v)!=="svelte-13x1ycp"&&(v.innerHTML=ye),oe=l(e),u(H.$$.fragment,e),ne=l(e),u(I.$$.fragment,e),se=l(e),u(U.$$.fragment,e),le=l(e),i=c(e,"DIV",{class:!0});var M=ie(i);u(B.$$.fragment,M),me=l(M),z=c(M,"P",{"data-svelte-h":!0}),_(z)!=="svelte-1jokdk4"&&(z.textContent=je),pe=l(M),Y=c(M,"P",{"data-svelte-h":!0}),_(Y)!=="svelte-t21i2g"&&(Y.innerHTML=Me),ce=l(M),$=c(M,"DIV",{class:!0});var O=ie($);u(R.$$.fragment,O),ue=l(O),E=c(O,"P",{"data-svelte-h":!0}),_(E)!=="svelte-1xamqu"&&(E.innerHTML=we),de=l(O),u(T.$$.fragment,O),O.forEach(o),M.forEach(o),ae=l(e),F=c(e,"P",{}),ie(F).forEach(o),this.h()},h(){L(r,"name","hf:doc:metadata"),L(r,"content",Ce),L(v,"class","tip"),L($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),L(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){J(document.head,r),n(e,x,t),n(e,w,t),n(e,b,t),d(y,e,t),n(e,a,t),d(j,e,t),n(e,P,t),d(N,e,t),n(e,D,t),n(e,Z,t),n(e,Q,t),d(W,e,t),n(e,A,t),n(e,X,t),n(e,q,t),d(V,e,t),n(e,K,t),n(e,C,t),n(e,ee,t),d(k,e,t),n(e,te,t),n(e,v,t),n(e,oe,t),d(H,e,t),n(e,ne,t),d(I,e,t),n(e,se,t),d(U,e,t),n(e,le,t),n(e,i,t),d(B,i,null),J(i,me),J(i,z),J(i,pe),J(i,Y),J(i,ce),J(i,$),d(R,$,null),J($,ue),J($,E),J($,de),d(T,$,null),n(e,ae,t),n(e,F,t),re=!0},p(e,[t]){const M={};t&2&&(M.$$scope={dirty:t,ctx:e}),T.$set(M)},i(e){re||(h(y.$$.fragment,e),h(j.$$.fragment,e),h(N.$$.fragment,e),h(W.$$.fragment,e),h(V.$$.fragment,e),h(k.$$.fragment,e),h(H.$$.fragment,e),h(I.$$.fragment,e),h(U.$$.fragment,e),h(B.$$.fragment,e),h(R.$$.fragment,e),h(T.$$.fragment,e),re=!0)},o(e){g(y.$$.fragment,e),g(j.$$.fragment,e),g(N.$$.fragment,e),g(W.$$.fragment,e),g(V.$$.fragment,e),g(k.$$.fragment,e),g(H.$$.fragment,e),g(I.$$.fragment,e),g(U.$$.fragment,e),g(B.$$.fragment,e),g(R.$$.fragment,e),g(T.$$.fragment,e),re=!1},d(e){e&&(o(x),o(w),o(b),o(a),o(P),o(D),o(Z),o(Q),o(A),o(X),o(q),o(K),o(C),o(ee),o(te),o(v),o(oe),o(ne),o(se),o(le),o(i),o(ae),o(F)),o(r),f(y,e),f(j,e),f(N,e),f(W,e),f(V,e),f(k,e),f(H,e),f(I,e),f(U,e),f(B),f(R),f(T)}}}const Ce='{"title":"YOLOS","local":"yolos","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Export to Neuron","local":"export-to-neuron","sections":[{"title":"Option 1: CLI","local":"option-1-cli","sections":[],"depth":3},{"title":"Option 2: Python API","local":"option-2-python-api","sections":[],"depth":3}],"depth":2},{"title":"NeuronYolosForObjectDetection","local":"optimum.neuron.NeuronYolosForObjectDetection","sections":[],"depth":2}],"depth":1}';function ke(G){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ee extends _e{constructor(r){super(),xe(this,r,ke,Ve,Je,{})}}export{Ee as component};
