Buckets:

download
raw
69.3 kB
import"../chunks/DsnmJJEf.js";import{i as E,h as B,C as X,H as s,a as u,D as r,E as H,s as Y}from"../chunks/CN3cOuQA.js";import{p as A,o as L,s as e,f as g,a,b as O,c as i,d as l,n as N,r as c}from"../chunks/DdiSzEty.js";import{T as q}from"../chunks/Biyddybe.js";import{E as W}from"../chunks/BpTh2jDR.js";const P='{"title":"D-FINE","local":"d-fine","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage tips","local":"usage-tips","sections":[],"depth":2},{"title":"DFineConfig","local":"transformers.DFineConfig","sections":[],"depth":2},{"title":"DFineModel","local":"transformers.DFineModel","sections":[],"depth":2},{"title":"DFineForObjectDetection","local":"transformers.DFineForObjectDetection","sections":[],"depth":2}],"depth":1}';var K=l('<meta name="hf:doc:metadata"/>'),I=l(`<p>Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code> instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.</p>`),$=l("<p>Examples:</p> <!>",1),ee=l("<p>Example:</p> <!>",1),oe=l(`<p></p> <p><em>This model was published in HF papers on 2024-10-17 and contributed to Hugging Face Transformers on 2025-04-29.</em></p> <!> <!> <!> <p>The D-FINE model was proposed in <a href="https://huggingface.co/papers/2410.13842" rel="nofollow">D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement</a> by
Yansong Peng, Hebei Li, Peixi Wu, Yueyi Zhang, Xiaoyan Sun, Feng Wu</p> <p>The abstract from the paper is the following:</p> <p><em>We introduce D-FINE, a powerful real-time object detector that achieves outstanding localization precision by redefining the bounding box regression task in DETR models. D-FINE comprises two key components: Fine-grained Distribution Refinement (FDR) and Global Optimal Localization Self-Distillation (GO-LSD).
FDR transforms the regression process from predicting fixed coordinates to iteratively refining probability distributions, providing a fine-grained intermediate representation that significantly enhances localization accuracy. GO-LSD is a bidirectional optimization strategy that transfers localization knowledge from refined distributions to shallower layers through self-distillation, while also simplifying the residual prediction tasks for deeper layers. Additionally, D-FINE incorporates lightweight optimizations in computationally intensive modules and operations, achieving a better balance between speed and accuracy. Specifically, D-FINE-L / X achieves 54.0% / 55.8% AP on the COCO dataset at 124 / 78 FPS on an NVIDIA T4 GPU. When pretrained on Objects365, D-FINE-L / X attains 57.1% / 59.3% AP, surpassing all existing real-time detectors. Furthermore, our method significantly enhances the performance of a wide range of DETR models by up to 5.3% AP with negligible extra parameters and training costs. Our code and pretrained models: this https URL.</em></p> <p>This model was contributed by <a href="https://github.com/VladOS95-cyber" rel="nofollow">VladOS95-cyber</a>.
The original code can be found <a href="https://github.com/Peterande/D-FINE" rel="nofollow">here</a>.</p> <!> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DFineModel. It is used to instantiate a D Fine
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the <a href="https://huggingface.co/ustc-community/dfine-xlarge-coco" rel="nofollow">ustc-community/dfine-xlarge-coco</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>RT-DETR Model (consisting of a backbone and encoder-decoder) outputting raw hidden states without any head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/d_fine#transformers.DFineModel">DFineModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the decoder of the model.</p></li> <li><p><strong>intermediate_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, hidden_size)</code>) — Stacked intermediate hidden states (output of each layer of the decoder).</p></li> <li><p><strong>intermediate_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, sequence_length, config.num_labels)</code>) — Stacked intermediate logits (logits of each layer of the decoder).</p></li> <li><p><strong>intermediate_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, 4)</code>) — Stacked intermediate reference points (reference points of each layer of the decoder).</p></li> <li><p><strong>intermediate_predicted_corners</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, 4)</code>) — Stacked intermediate predicted corners (predicted corners of each layer of the decoder).</p></li> <li><p><strong>initial_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, 4)</code>) — Initial reference points used for the first decoder layer.</p></li> <li><p><strong>decoder_hidden_states</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p></li> <li><p><strong>decoder_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p></li> <li><p><strong>cross_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the decoder’s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p></li> <li><p><strong>encoder_last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — Sequence of hidden-states at the output of the last layer of the encoder of the model.</p></li> <li><p><strong>encoder_hidden_states</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p></li> <li><p><strong>encoder_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p></li> <li><p><strong>init_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, 4)</code>) — Initial reference points sent through the Transformer decoder.</p></li> <li><p><strong>enc_topk_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, config.num_labels)</code>) — Predicted bounding boxes scores where the top <code>config.two_stage_num_proposals</code> scoring bounding boxes are
picked as region proposals in the encoder stage. Output of bounding box binary classification (i.e.
foreground and background).</p></li> <li><p><strong>enc_topk_bboxes</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, 4)</code>) — Logits of predicted bounding boxes coordinates in the encoder stage.</p></li> <li><p><strong>enc_outputs_class</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, config.num_labels)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Predicted bounding boxes scores where the top <code>config.two_stage_num_proposals</code> scoring bounding boxes are
picked as region proposals in the first stage. Output of bounding box binary classification (i.e.
foreground and background).</p></li> <li><p><strong>enc_outputs_coord_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, 4)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Logits of predicted bounding boxes coordinates in the first stage.</p></li> <li><p><strong>denoising_meta_values</strong> (<code>dict</code>, <em>optional</em>) — Extra dictionary for the denoising related values.</p></li></ul> <!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>RT-DETR Model (consisting of a backbone and encoder-decoder) outputting bounding boxes and logits to be further
decoded into scores and classes.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/d_fine#transformers.DFineForObjectDetection">DFineForObjectDetection</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>loss</strong> (<code>torch.Tensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> are provided)) — Total loss as a linear combination of a negative log-likelihood (cross-entropy) for class prediction and a
bounding box loss. The latter is defined as a linear combination of the L1 loss and the generalized
scale-invariant IoU loss.</p></li> <li><p><strong>loss_dict</strong> (<code>Dict</code>, <em>optional</em>) — A dictionary containing the individual losses. Useful for logging.</p></li> <li><p><strong>logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, num_classes + 1)</code>) — Classification logits (including no-object) for all queries.</p></li> <li><p><strong>pred_boxes</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, 4)</code>) — Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). These
values are normalized in [0, 1], relative to the size of each individual image in the batch (disregarding
possible padding). You can use <code>~DFineImageProcessor.post_process_object_detection</code> to retrieve the
unnormalized (absolute) bounding boxes.</p></li> <li><p><strong>auxiliary_outputs</strong> (<code>list[Dict]</code>, <em>optional</em>) — Optional, only returned when auxiliary losses are activated (i.e. <code>config.auxiliary_loss</code> is set to <code>True</code>)
and labels are provided. It is a list of dictionaries containing the two above keys (<code>logits</code> and <code>pred_boxes</code>) for each decoder layer.</p></li> <li><p><strong>last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the decoder of the model.</p></li> <li><p><strong>intermediate_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, hidden_size)</code>) — Stacked intermediate hidden states (output of each layer of the decoder).</p></li> <li><p><strong>intermediate_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, config.num_labels)</code>) — Stacked intermediate logits (logits of each layer of the decoder).</p></li> <li><p><strong>intermediate_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, 4)</code>) — Stacked intermediate reference points (reference points of each layer of the decoder).</p></li> <li><p><strong>intermediate_predicted_corners</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, 4)</code>) — Stacked intermediate predicted corners (predicted corners of each layer of the decoder).</p></li> <li><p><strong>initial_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.decoder_layers, num_queries, 4)</code>) — Stacked initial reference points (initial reference points of each layer of the decoder).</p></li> <li><p><strong>decoder_hidden_states</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p></li> <li><p><strong>decoder_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p></li> <li><p><strong>cross_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the decoder’s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p></li> <li><p><strong>encoder_last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — Sequence of hidden-states at the output of the last layer of the encoder of the model.</p></li> <li><p><strong>encoder_hidden_states</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p></li> <li><p><strong>encoder_attentions</strong> (<code>tuple[torch.Tensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p></li> <li><p><strong>init_reference_points</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_queries, 4)</code>) — Initial reference points sent through the Transformer decoder.</p></li> <li><p><strong>enc_topk_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, config.num_labels)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Logits of predicted bounding boxes coordinates in the encoder.</p></li> <li><p><strong>enc_topk_bboxes</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, 4)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Logits of predicted bounding boxes coordinates in the encoder.</p></li> <li><p><strong>enc_outputs_class</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, config.num_labels)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Predicted bounding boxes scores where the top <code>config.two_stage_num_proposals</code> scoring bounding boxes are
picked as region proposals in the first stage. Output of bounding box binary classification (i.e.
foreground and background).</p></li> <li><p><strong>enc_outputs_coord_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, 4)</code>, <em>optional</em>, returned when <code>config.with_box_refine=True</code> and <code>config.two_stage=True</code>) — Logits of predicted bounding boxes coordinates in the first stage.</p></li> <li><p><strong>denoising_meta_values</strong> (<code>dict</code>, <em>optional</em>) — Extra dictionary for the denoising related values</p></li></ul> <!></div></div> <!> <p></p>`,1);function ie(Z,R){A(R,!1),L(()=>{new URLSearchParams(window.location.search).get("fw")}),E();var f=oe();B("1ut1o71",o=>{var t=K();Y(t,"content",P),a(o,t)});var _=e(g(f),4);X(_,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var b=e(_,2);s(b,{title:"D-FINE",local:"d-fine",headingTag:"h1"});var y=e(b,2);s(y,{title:"Overview",local:"overview",headingTag:"h2"});var w=e(y,10);s(w,{title:"Usage tips",local:"usage-tips",headingTag:"h2"});var M=e(w,2);u(M,{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b0ltYWdlUHJvY2Vzc29yJTJDJTIwREZpbmVGb3JPYmplY3REZXRlY3Rpb24lMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmltYWdlX3V0aWxzJTIwaW1wb3J0JTIwbG9hZF9pbWFnZSUwQSUwQSUwQXVybCUyMCUzRCUyMCdodHRwJTNBJTJGJTJGaW1hZ2VzLmNvY29kYXRhc2V0Lm9yZyUyRnZhbDIwMTclMkYwMDAwMDAwMzk3NjkuanBnJyUwQWltYWdlJTIwJTNEJTIwbG9hZF9pbWFnZSh1cmwpJTBBJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJ1c3RjLWNvbW11bml0eSUyRmRmaW5lX3hfY29jbyUyMiklMEFtb2RlbCUyMCUzRCUyMERGaW5lRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMjJ1c3RjLWNvbW11bml0eSUyRmRmaW5lX3hfY29jbyUyMiUyQyUyMGRldmljZV9tYXAlM0QlMjJhdXRvJTIyKSUwQSUwQWlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlM0RpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKG1vZGVsLmRldmljZSklMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQXJlc3VsdHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IucG9zdF9wcm9jZXNzX29iamVjdF9kZXRlY3Rpb24ob3V0cHV0cyUyQyUyMHRhcmdldF9zaXplcyUzRCU1QihpbWFnZS5oZWlnaHQlMkMlMjBpbWFnZS53aWR0aCklNUQlMkMlMjB0aHJlc2hvbGQlM0QwLjUpJTBBJTBBZm9yJTIwcmVzdWx0JTIwaW4lMjByZXN1bHRzJTNBJTBBJTIwJTIwJTIwJTIwZm9yJTIwc2NvcmUlMkMlMjBsYWJlbF9pZCUyQyUyMGJveCUyMGluJTIwemlwKHJlc3VsdCU1QiUyMnNjb3JlcyUyMiU1RCUyQyUyMHJlc3VsdCU1QiUyMmxhYmVscyUyMiU1RCUyQyUyMHJlc3VsdCU1QiUyMmJveGVzJTIyJTVEKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNjb3JlJTJDJTIwbGFiZWwlMjAlM0QlMjBzY29yZS5pdGVtKCklMkMlMjBsYWJlbF9pZC5pdGVtKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBib3glMjAlM0QlMjAlNUJyb3VuZChpJTJDJTIwMiklMjBmb3IlMjBpJTIwaW4lMjBib3gudG9saXN0KCklNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChmJTIyJTdCbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCbGFiZWwlNUQlN0QlM0ElMjAlN0JzY29yZSUzQS4yZiU3RCUyMCU3QmJveCU3RCUyMiklMEFjYXQlM0ElMjAwLjk2JTIwJTVCMzQ0LjQ5JTJDJTIwMjMuNCUyQyUyMDYzOS44NCUyQyUyMDM3NC4yNyU1RCUwQWNhdCUzQSUyMDAuOTYlMjAlNUIxMS43MSUyQyUyMDUzLjUyJTJDJTIwMzE2LjY0JTJDJTIwNDcyLjMzJTVEJTBBcmVtb3RlJTNBJTIwMC45NSUyMCU1QjQwLjQ2JTJDJTIwNzMuNyUyQyUyMDE3NS42MiUyQyUyMDExNy41NyU1RCUwQXNvZmElM0ElMjAwLjkyJTIwJTVCMC41OSUyQyUyMDEuODglMkMlMjA2NDAuMjUlMkMlMjA0NzQuNzQlNUQlMEFyZW1vdGUlM0ElMjAwLjg5JTIwJTVCMzMzLjQ4JTJDJTIwNzcuMDQlMkMlMjAzNzAuNzclMkMlMjAxODcuMyU1RA==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, DFineForObjectDetection
<span class="hljs-keyword">from</span> transformers.image_utils <span class="hljs-keyword">import</span> load_image
url = <span class="hljs-string">&#x27;http://images.cocodataset.org/val2017/000000039769.jpg&#x27;</span>
image = load_image(url)
image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;ustc-community/dfine_x_coco&quot;</span>)
model = DFineForObjectDetection.from_pretrained(<span class="hljs-string">&quot;ustc-community/dfine_x_coco&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
inputs = image_processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device)
<span class="hljs-keyword">with</span> torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_object_detection(outputs, target_sizes=[(image.height, image.width)], threshold=<span class="hljs-number">0.5</span>)
<span class="hljs-keyword">for</span> result <span class="hljs-keyword">in</span> results:
<span class="hljs-keyword">for</span> score, label_id, box <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(result[<span class="hljs-string">&quot;scores&quot;</span>], result[<span class="hljs-string">&quot;labels&quot;</span>], result[<span class="hljs-string">&quot;boxes&quot;</span>]):
score, label = score.item(), label_id.item()
box = [<span class="hljs-built_in">round</span>(i, <span class="hljs-number">2</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> box.tolist()]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">{model.config.id2label[label]}</span>: <span class="hljs-subst">{score:<span class="hljs-number">.2</span>f}</span> <span class="hljs-subst">{box}</span>&quot;</span>)
cat: <span class="hljs-number">0.96</span> [<span class="hljs-number">344.49</span>, <span class="hljs-number">23.4</span>, <span class="hljs-number">639.84</span>, <span class="hljs-number">374.27</span>]
cat: <span class="hljs-number">0.96</span> [<span class="hljs-number">11.71</span>, <span class="hljs-number">53.52</span>, <span class="hljs-number">316.64</span>, <span class="hljs-number">472.33</span>]
remote: <span class="hljs-number">0.95</span> [<span class="hljs-number">40.46</span>, <span class="hljs-number">73.7</span>, <span class="hljs-number">175.62</span>, <span class="hljs-number">117.57</span>]
sofa: <span class="hljs-number">0.92</span> [<span class="hljs-number">0.59</span>, <span class="hljs-number">1.88</span>, <span class="hljs-number">640.25</span>, <span class="hljs-number">474.74</span>]
remote: <span class="hljs-number">0.89</span> [<span class="hljs-number">333.48</span>, <span class="hljs-number">77.04</span>, <span class="hljs-number">370.77</span>, <span class="hljs-number">187.3</span>]`,lang:"python",wrap:!1});var T=e(M,2);s(T,{title:"DFineConfig",local:"transformers.DFineConfig",headingTag:"h2"});var d=e(T,2),Q=i(d);r(Q,{name:"class transformers.DFineConfig",anchor:"transformers.DFineConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/d_fine/configuration_d_fine.py#L31",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"is_encoder_decoder",val:": bool = True"},{name:"initializer_range",val:": float = 0.01"},{name:"initializer_bias_prior_prob",val:": float | None = None"},{name:"layer_norm_eps",val:": float = 1e-05"},{name:"batch_norm_eps",val:": float = 1e-05"},{name:"backbone_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"freeze_backbone_batch_norms",val:": bool = True"},{name:"encoder_hidden_dim",val:": int = 256"},{name:"encoder_in_channels",val:": list[int] | tuple[int, ...] = (512, 1024, 2048)"},{name:"feat_strides",val:": list[int] | tuple[int, ...] = (8, 16, 32)"},{name:"encoder_layers",val:": int = 1"},{name:"encoder_ffn_dim",val:": int = 1024"},{name:"encoder_attention_heads",val:": int = 8"},{name:"dropout",val:": float | int = 0.0"},{name:"activation_dropout",val:": float | int = 0.0"},{name:"encode_proj_layers",val:": list[int] | tuple[int, ...] = (2,)"},{name:"positional_encoding_temperature",val:": int = 10000"},{name:"encoder_activation_function",val:": str = 'gelu'"},{name:"activation_function",val:": str = 'silu'"},{name:"eval_size",val:": int | None = None"},{name:"normalize_before",val:": bool = False"},{name:"hidden_expansion",val:": float = 1.0"},{name:"d_model",val:": int = 256"},{name:"num_queries",val:": int = 300"},{name:"decoder_in_channels",val:": list[int] | tuple[int, ...] = (256, 256, 256)"},{name:"decoder_ffn_dim",val:": int = 1024"},{name:"num_feature_levels",val:": int = 3"},{name:"decoder_n_points",val:": int | list[int] = 4"},{name:"decoder_layers",val:": int = 6"},{name:"decoder_attention_heads",val:": int = 8"},{name:"decoder_activation_function",val:": str = 'relu'"},{name:"attention_dropout",val:": float | int = 0.0"},{name:"num_denoising",val:": int = 100"},{name:"label_noise_ratio",val:": float = 0.5"},{name:"box_noise_scale",val:": float = 1.0"},{name:"learn_initial_query",val:": bool = False"},{name:"anchor_image_size",val:": int | list[int] | None = None"},{name:"with_box_refine",val:": bool = True"},{name:"matcher_alpha",val:": float = 0.25"},{name:"matcher_gamma",val:": float = 2.0"},{name:"matcher_class_cost",val:": float = 2.0"},{name:"matcher_bbox_cost",val:": float = 5.0"},{name:"matcher_giou_cost",val:": float = 2.0"},{name:"use_focal_loss",val:": bool = True"},{name:"auxiliary_loss",val:": bool = True"},{name:"focal_loss_alpha",val:": float = 0.75"},{name:"focal_loss_gamma",val:": float = 2.0"},{name:"weight_loss_vfl",val:": float = 1.0"},{name:"weight_loss_bbox",val:": float = 5.0"},{name:"weight_loss_giou",val:": float = 2.0"},{name:"weight_loss_fgl",val:": float = 0.15"},{name:"weight_loss_ddf",val:": float = 1.5"},{name:"eos_coefficient",val:": float = 0.0001"},{name:"eval_idx",val:": int = -1"},{name:"layer_scale",val:": int | float = 1.0"},{name:"max_num_bins",val:": int = 32"},{name:"reg_scale",val:": float = 4.0"},{name:"depth_mult",val:": float = 1.0"},{name:"top_prob_values",val:": int = 4"},{name:"lqe_hidden_dim",val:": int = 64"},{name:"lqe_layers",val:": int = 2"},{name:"decoder_offset_scale",val:": float = 0.5"},{name:"decoder_method",val:": str = 'default'"},{name:"up",val:": float = 0.5"},{name:"tie_word_embeddings",val:": bool = True"}],parametersDescription:[{anchor:"transformers.DFineConfig.is_encoder_decoder",description:`<strong>is_encoder_decoder</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether the model is used as an encoder/decoder or not.`,name:"is_encoder_decoder"},{anchor:"transformers.DFineConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.01</code>) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DFineConfig.initializer_bias_prior_prob",description:`<strong>initializer_bias_prior_prob</strong> (<code>float</code>, <em>optional</em>) &#x2014;
The prior probability used by the bias initializer to initialize biases for <code>enc_score_head</code> and <code>class_embed</code>.
If <code>None</code>, <code>prior_prob</code> computed as <code>prior_prob = 1 / (num_labels + 1)</code> while initializing model weights.`,name:"initializer_bias_prior_prob"},{anchor:"transformers.DFineConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-05</code>) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.DFineConfig.batch_norm_eps",description:`<strong>batch_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-05</code>) &#x2014;
The epsilon used by the batch normalization layers.`,name:"batch_norm_eps"},{anchor:"transformers.DFineConfig.backbone_config",description:`<strong>backbone_config</strong> (<code>Union[dict, ~configuration_utils.PreTrainedConfig]</code>, <em>optional</em>) &#x2014;
The configuration of the backbone model.`,name:"backbone_config"},{anchor:"transformers.DFineConfig.freeze_backbone_batch_norms",description:`<strong>freeze_backbone_batch_norms</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to freeze the batch normalization layers in the backbone.`,name:"freeze_backbone_batch_norms"},{anchor:"transformers.DFineConfig.encoder_hidden_dim",description:`<strong>encoder_hidden_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>256</code>) &#x2014;
Dimension of the hidden representations.`,name:"encoder_hidden_dim"},{anchor:"transformers.DFineConfig.encoder_in_channels",description:`<strong>encoder_in_channels</strong> (<code>list</code>, <em>optional</em>, defaults to <code>[512, 1024, 2048]</code>) &#x2014;
Multi level features input for encoder.`,name:"encoder_in_channels"},{anchor:"transformers.DFineConfig.feat_strides",description:`<strong>feat_strides</strong> (<code>list[int]</code>, <em>optional</em>, defaults to <code>[8, 16, 32]</code>) &#x2014;
Strides used in each feature map.`,name:"feat_strides"},{anchor:"transformers.DFineConfig.encoder_layers",description:`<strong>encoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) &#x2014;
Number of hidden layers in the Transformer encoder. Will use the same value as <code>num_layers</code> if not set.`,name:"encoder_layers"},{anchor:"transformers.DFineConfig.encoder_ffn_dim",description:`<strong>encoder_ffn_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1024</code>) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (often named feed-forward) layer in encoder.`,name:"encoder_ffn_dim"},{anchor:"transformers.DFineConfig.encoder_attention_heads",description:`<strong>encoder_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>8</code>) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"encoder_attention_heads"},{anchor:"transformers.DFineConfig.dropout",description:`<strong>dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) &#x2014;
The ratio for all dropout layers.`,name:"dropout"},{anchor:"transformers.DFineConfig.activation_dropout",description:`<strong>activation_dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) &#x2014;
The dropout ratio for activations inside the fully connected layer.`,name:"activation_dropout"},{anchor:"transformers.DFineConfig.encode_proj_layers",description:`<strong>encode_proj_layers</strong> (<code>list[int]</code>, <em>optional</em>, defaults to <code>[2]</code>) &#x2014;
Indexes of the projected layers to be used in the encoder.`,name:"encode_proj_layers"},{anchor:"transformers.DFineConfig.positional_encoding_temperature",description:`<strong>positional_encoding_temperature</strong> (<code>int</code>, <em>optional</em>, defaults to 10000) &#x2014;
The temperature parameter used to create the positional encodings.`,name:"positional_encoding_temperature"},{anchor:"transformers.DFineConfig.encoder_activation_function",description:`<strong>encoder_activation_function</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the encoder and pooler. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"encoder_activation_function"},{anchor:"transformers.DFineConfig.activation_function",description:`<strong>activation_function</strong> (<code>str</code>, <em>optional</em>, defaults to <code>silu</code>) &#x2014;
The non-linear activation function (function or string) in the decoder. For example, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code>, etc.`,name:"activation_function"},{anchor:"transformers.DFineConfig.eval_size",description:`<strong>eval_size</strong> (<code>tuple[int, int]</code>, <em>optional</em>) &#x2014;
Height and width used to computes the effective height and width of the position embeddings after taking
into account the stride.`,name:"eval_size"},{anchor:"transformers.DFineConfig.normalize_before",description:`<strong>normalize_before</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Determine whether to apply layer normalization in the transformer encoder layer before self-attention and
feed-forward modules.`,name:"normalize_before"},{anchor:"transformers.DFineConfig.hidden_expansion",description:`<strong>hidden_expansion</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Expansion ratio to enlarge the dimension size of RepVGGBlock and CSPRepLayer.`,name:"hidden_expansion"},{anchor:"transformers.DFineConfig.d_model",description:`<strong>d_model</strong> (<code>int</code>, <em>optional</em>, defaults to <code>256</code>) &#x2014;
Size of the encoder layers and the pooler layer.`,name:"d_model"},{anchor:"transformers.DFineConfig.num_queries",description:`<strong>num_queries</strong> (<code>int</code>, <em>optional</em>, defaults to 300) &#x2014;
Number of object queries.`,name:"num_queries"},{anchor:"transformers.DFineConfig.decoder_in_channels",description:`<strong>decoder_in_channels</strong> (<code>list</code>, <em>optional</em>, defaults to <code>[256, 256, 256]</code>) &#x2014;
Multi level features dimension for decoder`,name:"decoder_in_channels"},{anchor:"transformers.DFineConfig.decoder_ffn_dim",description:`<strong>decoder_ffn_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1024</code>) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (often named feed-forward) layer in decoder.`,name:"decoder_ffn_dim"},{anchor:"transformers.DFineConfig.num_feature_levels",description:`<strong>num_feature_levels</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The number of input feature levels.`,name:"num_feature_levels"},{anchor:"transformers.DFineConfig.decoder_n_points",description:`<strong>decoder_n_points</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
The number of sampled keys in each feature level for each attention head in the decoder.`,name:"decoder_n_points"},{anchor:"transformers.DFineConfig.decoder_layers",description:`<strong>decoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>6</code>) &#x2014;
Number of hidden layers in the Transformer decoder. Will use the same value as <code>num_layers</code> if not set.`,name:"decoder_layers"},{anchor:"transformers.DFineConfig.decoder_attention_heads",description:`<strong>decoder_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>8</code>) &#x2014;
Number of attention heads for each attention layer in the Transformer decoder.`,name:"decoder_attention_heads"},{anchor:"transformers.DFineConfig.decoder_activation_function",description:`<strong>decoder_activation_function</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;relu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the decoder. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"decoder_activation_function"},{anchor:"transformers.DFineConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.DFineConfig.num_denoising",description:`<strong>num_denoising</strong> (<code>int</code>, <em>optional</em>, defaults to 100) &#x2014;
The total number of denoising tasks or queries to be used for contrastive denoising.`,name:"num_denoising"},{anchor:"transformers.DFineConfig.label_noise_ratio",description:`<strong>label_noise_ratio</strong> (<code>float</code>, <em>optional</em>, defaults to 0.5) &#x2014;
The fraction of denoising labels to which random noise should be added.`,name:"label_noise_ratio"},{anchor:"transformers.DFineConfig.box_noise_scale",description:`<strong>box_noise_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Scale or magnitude of noise to be added to the bounding boxes.`,name:"box_noise_scale"},{anchor:"transformers.DFineConfig.learn_initial_query",description:`<strong>learn_initial_query</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Indicates whether the initial query embeddings for the decoder should be learned during training`,name:"learn_initial_query"},{anchor:"transformers.DFineConfig.anchor_image_size",description:`<strong>anchor_image_size</strong> (<code>tuple[int, int]</code>, <em>optional</em>) &#x2014;
Height and width of the input image used during evaluation to generate the bounding box anchors. If None, automatic generate anchor is applied.`,name:"anchor_image_size"},{anchor:"transformers.DFineConfig.with_box_refine",description:`<strong>with_box_refine</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to apply iterative bounding box refinement, where each decoder layer refines the bounding boxes
based on the predictions from the previous layer.`,name:"with_box_refine"},{anchor:"transformers.DFineConfig.matcher_alpha",description:`<strong>matcher_alpha</strong> (<code>float</code>, <em>optional</em>, defaults to 0.25) &#x2014;
Parameter alpha used by the Hungarian Matcher.`,name:"matcher_alpha"},{anchor:"transformers.DFineConfig.matcher_gamma",description:`<strong>matcher_gamma</strong> (<code>float</code>, <em>optional</em>, defaults to 2.0) &#x2014;
Parameter gamma used by the Hungarian Matcher.`,name:"matcher_gamma"},{anchor:"transformers.DFineConfig.matcher_class_cost",description:`<strong>matcher_class_cost</strong> (<code>float</code>, <em>optional</em>, defaults to 2.0) &#x2014;
The relative weight of the class loss used by the Hungarian Matcher.`,name:"matcher_class_cost"},{anchor:"transformers.DFineConfig.matcher_bbox_cost",description:`<strong>matcher_bbox_cost</strong> (<code>float</code>, <em>optional</em>, defaults to 5.0) &#x2014;
The relative weight of the bounding box loss used by the Hungarian Matcher.`,name:"matcher_bbox_cost"},{anchor:"transformers.DFineConfig.matcher_giou_cost",description:`<strong>matcher_giou_cost</strong> (<code>float</code>, <em>optional</em>, defaults to 2.0) &#x2014;
The relative weight of the giou loss used by the Hungarian Matcher.`,name:"matcher_giou_cost"},{anchor:"transformers.DFineConfig.use_focal_loss",description:`<strong>use_focal_loss</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Parameter informing if focal loss should be used.`,name:"use_focal_loss"},{anchor:"transformers.DFineConfig.auxiliary_loss",description:`<strong>auxiliary_loss</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether auxiliary decoding losses (losses at each decoder layer) are to be used.`,name:"auxiliary_loss"},{anchor:"transformers.DFineConfig.focal_loss_alpha",description:`<strong>focal_loss_alpha</strong> (<code>float</code>, <em>optional</em>, defaults to 0.75) &#x2014;
Parameter alpha used to compute the focal loss.`,name:"focal_loss_alpha"},{anchor:"transformers.DFineConfig.focal_loss_gamma",description:`<strong>focal_loss_gamma</strong> (<code>float</code>, <em>optional</em>, defaults to 2.0) &#x2014;
Parameter gamma used to compute the focal loss.`,name:"focal_loss_gamma"},{anchor:"transformers.DFineConfig.weight_loss_vfl",description:`<strong>weight_loss_vfl</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Relative weight of the varifocal loss in the object detection loss.`,name:"weight_loss_vfl"},{anchor:"transformers.DFineConfig.weight_loss_bbox",description:`<strong>weight_loss_bbox</strong> (<code>float</code>, <em>optional</em>, defaults to 5.0) &#x2014;
Relative weight of the L1 bounding box loss in the object detection loss.`,name:"weight_loss_bbox"},{anchor:"transformers.DFineConfig.weight_loss_giou",description:`<strong>weight_loss_giou</strong> (<code>float</code>, <em>optional</em>, defaults to 2.0) &#x2014;
Relative weight of the generalized IoU loss in the object detection loss.`,name:"weight_loss_giou"},{anchor:"transformers.DFineConfig.weight_loss_fgl",description:`<strong>weight_loss_fgl</strong> (<code>float</code>, <em>optional</em>, defaults to 0.15) &#x2014;
Relative weight of the fine-grained localization loss in the object detection loss.`,name:"weight_loss_fgl"},{anchor:"transformers.DFineConfig.weight_loss_ddf",description:`<strong>weight_loss_ddf</strong> (<code>float</code>, <em>optional</em>, defaults to 1.5) &#x2014;
Relative weight of the decoupled distillation focal loss in the object detection loss.`,name:"weight_loss_ddf"},{anchor:"transformers.DFineConfig.eos_coefficient",description:`<strong>eos_coefficient</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.0001</code>) &#x2014;
Relative classification weight of the &#x2018;no-object&#x2019; class in the object detection loss.`,name:"eos_coefficient"},{anchor:"transformers.DFineConfig.eval_idx",description:`<strong>eval_idx</strong> (<code>int</code>, <em>optional</em>, defaults to -1) &#x2014;
Index of the decoder layer to use for evaluation. If negative, counts from the end
(e.g., -1 means use the last layer). This allows for early prediction in the decoder
stack while still training later layers.`,name:"eval_idx"},{anchor:"transformers.DFineConfig.layer_scale",description:`<strong>layer_scale</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1.0</code>) &#x2014;
Scaling factor for the hidden dimension in later decoder layers. Used to adjust the
model capacity after the evaluation layer.`,name:"layer_scale"},{anchor:"transformers.DFineConfig.max_num_bins",description:`<strong>max_num_bins</strong> (<code>int</code>, <em>optional</em>, defaults to 32) &#x2014;
Maximum number of bins for the distribution-guided bounding box refinement.
Higher values allow for more fine-grained localization but increase computation.`,name:"max_num_bins"},{anchor:"transformers.DFineConfig.reg_scale",description:`<strong>reg_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 4.0) &#x2014;
Scale factor for the regression distribution. Controls the range and granularity
of the bounding box refinement process.`,name:"reg_scale"},{anchor:"transformers.DFineConfig.depth_mult",description:`<strong>depth_mult</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Multiplier for the number of blocks in RepNCSPELAN4 layers. Used to scale the model&#x2019;s
depth while maintaining its architecture.`,name:"depth_mult"},{anchor:"transformers.DFineConfig.top_prob_values",description:`<strong>top_prob_values</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Number of top probability values to consider from each corner&#x2019;s distribution.`,name:"top_prob_values"},{anchor:"transformers.DFineConfig.lqe_hidden_dim",description:`<strong>lqe_hidden_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Hidden dimension size for the Location Quality Estimator (LQE) network.`,name:"lqe_hidden_dim"},{anchor:"transformers.DFineConfig.lqe_layers",description:`<strong>lqe_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
Number of layers in the Location Quality Estimator MLP.`,name:"lqe_layers"},{anchor:"transformers.DFineConfig.decoder_offset_scale",description:`<strong>decoder_offset_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 0.5) &#x2014;
Offset scale used in deformable attention.`,name:"decoder_offset_scale"},{anchor:"transformers.DFineConfig.decoder_method",description:`<strong>decoder_method</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;default&quot;</code>) &#x2014;
The method to use for the decoder: <code>&quot;default&quot;</code> or <code>&quot;discrete&quot;</code>.`,name:"decoder_method"},{anchor:"transformers.DFineConfig.up",description:`<strong>up</strong> (<code>float</code>, <em>optional</em>, defaults to 0.5) &#x2014;
Controls the upper bounds of the Weighting Function.`,name:"up"},{anchor:"transformers.DFineConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to tie weight embeddings according to model&#x2019;s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"}]}),N(4),c(d);var j=e(d,2);s(j,{title:"DFineModel",local:"transformers.DFineModel",headingTag:"h2"});var p=e(j,2),v=i(p);r(v,{name:"class transformers.DFineModel",anchor:"transformers.DFineModel",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/d_fine/modeling_d_fine.py#L1539",parameters:[{name:"config",val:": DFineConfig"}],parametersDescription:[{anchor:"transformers.DFineModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/d_fine#transformers.DFineConfig">DFineConfig</a>) &#x2014;
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
<a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var U=e(v,8),x=i(U);r(x,{name:"forward",anchor:"transformers.DFineModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/d_fine/modeling_d_fine.py#L1665",parameters:[{name:"pixel_values",val:": Tensor"},{name:"pixel_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"encoder_outputs",val:": typing.Optional[torch.Tensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",val:": list[dict] | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DFineModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<code>image_processor_class</code>. See <code>image_processor_class.__call__</code> for details (<code>processor_class</code> uses
<code>image_processor_class</code> for processing images).`,name:"pixel_values"},{anchor:"transformers.DFineModel.forward.pixel_mask",description:`<strong>pixel_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, height, width)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding pixel values. Mask values selected in <code>[0, 1]</code>:
<ul>
<li>1 for pixels that are real (i.e. <strong>not masked</strong>),</li>
<li>0 for pixels that are padding (i.e. <strong>masked</strong>).</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a></p>`,name:"pixel_mask"},{anchor:"transformers.DFineModel.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>last_hidden_state</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) is a sequence of
hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.`,name:"encoder_outputs"},{anchor:"transformers.DFineModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing the flattened feature map (output of the backbone + projection layer), you
can choose to directly pass a flattened representation of an image.`,name:"inputs_embeds"},{anchor:"transformers.DFineModel.forward.labels",description:`<strong>labels</strong> (<code>list[Dict]</code> of len <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the bipartite matching loss. List of dicts, each dictionary containing at least the
following 2 keys: &#x2018;class_labels&#x2019; and &#x2018;boxes&#x2019; (the class labels and bounding boxes of an image in the batch
respectively). The class labels themselves should be a <code>torch.LongTensor</code> of len <code>(number of bounding boxes in the image,)</code> and the boxes a <code>torch.Tensor</code> of shape <code>(number of bounding boxes in the image, 4)</code>.`,name:"labels"}],returnDescription:`
<p>A <code>DFineModelOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<code>None</code>) and inputs.</p>
`,returnType:`
<p><code>DFineModelOutput</code> or <code>tuple(torch.Tensor)</code></p>
`});var J=e(x,4);q(J,{children:(o,t)=>{var n=I();a(o,n)},$$slots:{default:!0}});var S=e(J,4);W(S,{anchor:"transformers.DFineModel.forward.example",children:(o,t)=>{var n=$(),m=e(g(n),2);u(m,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMERGaW5lTW9kZWwlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEFmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViLnV0aWxzJTIwaW1wb3J0JTIwaHR0cHglMEFmcm9tJTIwaW8lMjBpbXBvcnQlMjBCeXRlc0lPJTBBJTBBdXJsJTIwJTNEJTIwJTIyaHR0cCUzQSUyRiUyRmltYWdlcy5jb2NvZGF0YXNldC5vcmclMkZ2YWwyMDE3JTJGMDAwMDAwMDM5NzY5LmpwZyUyMiUwQXdpdGglMjBodHRweC5zdHJlYW0oJTIyR0VUJTIyJTJDJTIwdXJsKSUyMGFzJTIwcmVzcG9uc2UlM0ElMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4oQnl0ZXNJTyhyZXNwb25zZS5yZWFkKCkpKSUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyUGVraW5nVSUyRkRGaW5lX3I1MHZkJTIyKSUwQW1vZGVsJTIwJTNEJTIwREZpbmVNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyUGVraW5nVSUyRkRGaW5lX3I1MHZkJTIyKSUwQSUwQWlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlM0RpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQWxhc3RfaGlkZGVuX3N0YXRlcyUyMCUzRCUyMG91dHB1dHMubGFzdF9oaWRkZW5fc3RhdGUlMEFsaXN0KGxhc3RfaGlkZGVuX3N0YXRlcy5zaGFwZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, DFineModel
<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> huggingface_hub.utils <span class="hljs-keyword">import</span> httpx
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<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><span class="hljs-keyword">with</span> httpx.stream(<span class="hljs-string">&quot;GET&quot;</span>, url) <span class="hljs-keyword">as</span> response:
<span class="hljs-meta">... </span> image = Image.<span class="hljs-built_in">open</span>(BytesIO(response.read()))
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;PekingU/DFine_r50vd&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = DFineModel.from_pretrained(<span class="hljs-string">&quot;PekingU/DFine_r50vd&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(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>last_hidden_states = outputs.last_hidden_state
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(last_hidden_states.shape)
[<span class="hljs-number">1</span>, <span class="hljs-number">300</span>, <span class="hljs-number">256</span>]`,lang:"python",wrap:!1}),a(o,n)},$$slots:{default:!0}}),c(U),c(p);var C=e(p,2);s(C,{title:"DFineForObjectDetection",local:"transformers.DFineForObjectDetection",headingTag:"h2"});var h=e(C,2),F=i(h);r(F,{name:"class transformers.DFineForObjectDetection",anchor:"transformers.DFineForObjectDetection",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/d_fine/modeling_d_fine.py#L1949",parameters:[{name:"config",val:": DFineConfig"}],parametersDescription:[{anchor:"transformers.DFineForObjectDetection.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/d_fine#transformers.DFineConfig">DFineConfig</a>) &#x2014;
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
<a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var D=e(F,8),z=i(D);r(z,{name:"forward",anchor:"transformers.DFineForObjectDetection.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/d_fine/modeling_d_fine.py#L1988",parameters:[{name:"pixel_values",val:": Tensor"},{name:"pixel_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"encoder_outputs",val:": typing.Optional[torch.Tensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",val:": list[dict] | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DFineForObjectDetection.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<code>image_processor_class</code>. See <code>image_processor_class.__call__</code> for details (<code>processor_class</code> uses
<code>image_processor_class</code> for processing images).`,name:"pixel_values"},{anchor:"transformers.DFineForObjectDetection.forward.pixel_mask",description:`<strong>pixel_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, height, width)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding pixel values. Mask values selected in <code>[0, 1]</code>:
<ul>
<li>1 for pixels that are real (i.e. <strong>not masked</strong>),</li>
<li>0 for pixels that are padding (i.e. <strong>masked</strong>).</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a></p>`,name:"pixel_mask"},{anchor:"transformers.DFineForObjectDetection.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>last_hidden_state</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) is a sequence of
hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.`,name:"encoder_outputs"},{anchor:"transformers.DFineForObjectDetection.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.DFineForObjectDetection.forward.labels",description:`<strong>labels</strong> (<code>list[Dict]</code> of len <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the bipartite matching loss. List of dicts, each dictionary containing at least the
following 2 keys: &#x2018;class_labels&#x2019; and &#x2018;boxes&#x2019; (the class labels and bounding boxes of an image in the batch
respectively). The class labels themselves should be a <code>torch.LongTensor</code> of len <code>(number of bounding boxes in the image,)</code> and the boxes a <code>torch.Tensor</code> of shape <code>(number of bounding boxes in the image, 4)</code>.`,name:"labels"}],returnDescription:`
<p>A <code>DFineObjectDetectionOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<code>None</code>) and inputs.</p>
`,returnType:`
<p><code>DFineObjectDetectionOutput</code> or <code>tuple(torch.Tensor)</code></p>
`});var k=e(z,4);q(k,{children:(o,t)=>{var n=I();a(o,n)},$$slots:{default:!0}});var V=e(k,4);W(V,{anchor:"transformers.DFineForObjectDetection.forward.example",children:(o,t)=>{var n=ee(),m=e(g(n),2);u(m,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmltYWdlX3V0aWxzJTIwaW1wb3J0JTIwbG9hZF9pbWFnZSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvSW1hZ2VQcm9jZXNzb3IlMkMlMjBERmluZUZvck9iamVjdERldGVjdGlvbiUwQSUwQXVybCUyMCUzRCUyMCUyMmh0dHAlM0ElMkYlMkZpbWFnZXMuY29jb2RhdGFzZXQub3JnJTJGdmFsMjAxNyUyRjAwMDAwMDAzOTc2OS5qcGclMjIlMEFpbWFnZSUyMCUzRCUyMGxvYWRfaW1hZ2UodXJsKSUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIydXN0Yy1jb21tdW5pdHklMkZkZmluZS14bGFyZ2UtY29jbyUyMiklMEFtb2RlbCUyMCUzRCUyMERGaW5lRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMjJ1c3RjLWNvbW11bml0eSUyRmRmaW5lLXhsYXJnZS1jb2NvJTIyKSUwQSUwQSUyMyUyMHByZXBhcmUlMjBpbWFnZSUyMGZvciUyMHRoZSUyMG1vZGVsJTBBaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEElMjMlMjBmb3J3YXJkJTIwcGFzcyUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyklMEElMEFsb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmxvZ2l0cyUwQWxpc3QobG9naXRzLnNoYXBlKSUwQSUwQWJveGVzJTIwJTNEJTIwb3V0cHV0cy5wcmVkX2JveGVzJTBBbGlzdChib3hlcy5zaGFwZSklMEElMEElMjMlMjBjb252ZXJ0JTIwb3V0cHV0cyUyMChib3VuZGluZyUyMGJveGVzJTIwYW5kJTIwY2xhc3MlMjBsb2dpdHMpJTIwdG8lMjBQYXNjYWwlMjBWT0MlMjBmb3JtYXQlMjAoeG1pbiUyQyUyMHltaW4lMkMlMjB4bWF4JTJDJTIweW1heCklMEF0YXJnZXRfc2l6ZXMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCaW1hZ2Uuc2l6ZSU1QiUzQSUzQS0xJTVEJTVEKSUwQXJlc3VsdHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IucG9zdF9wcm9jZXNzX29iamVjdF9kZXRlY3Rpb24ob3V0cHV0cyUyQyUyMHRocmVzaG9sZCUzRDAuOSUyQyUyMHRhcmdldF9zaXplcyUzRHRhcmdldF9zaXplcyklMEFyZXN1bHQlMjAlM0QlMjByZXN1bHRzJTVCMCU1RCUyMCUyMCUyMyUyMGZpcnN0JTIwaW1hZ2UlMjBpbiUyMGJhdGNoJTBBJTBBZm9yJTIwc2NvcmUlMkMlMjBsYWJlbCUyQyUyMGJveCUyMGluJTIwemlwKHJlc3VsdCU1QiUyMnNjb3JlcyUyMiU1RCUyQyUyMHJlc3VsdCU1QiUyMmxhYmVscyUyMiU1RCUyQyUyMHJlc3VsdCU1QiUyMmJveGVzJTIyJTVEKSUzQSUwQSUyMCUyMCUyMCUyMGJveCUyMCUzRCUyMCU1QnJvdW5kKGklMkMlMjAyKSUyMGZvciUyMGklMjBpbiUyMGJveC50b2xpc3QoKSU1RCUwQSUyMCUyMCUyMCUyMHByaW50KCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGYlMjJEZXRlY3RlZCUyMCU3Qm1vZGVsLmNvbmZpZy5pZDJsYWJlbCU1QmxhYmVsLml0ZW0oKSU1RCU3RCUyMHdpdGglMjBjb25maWRlbmNlJTIwJTIyJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZiUyMiU3QnJvdW5kKHNjb3JlLml0ZW0oKSUyQyUyMDMpJTdEJTIwYXQlMjBsb2NhdGlvbiUyMCU3QmJveCU3RCUyMiUwQSUyMCUyMCUyMCUyMCk=",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">from</span> transformers.image_utils <span class="hljs-keyword">import</span> load_image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, DFineForObjectDetection
<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 = load_image(url)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;ustc-community/dfine-xlarge-coco&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = DFineForObjectDetection.from_pretrained(<span class="hljs-string">&quot;ustc-community/dfine-xlarge-coco&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># prepare image for the model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># forward pass</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(logits.shape)
[<span class="hljs-number">1</span>, <span class="hljs-number">300</span>, <span class="hljs-number">80</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes = outputs.pred_boxes
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(boxes.shape)
[<span class="hljs-number">1</span>, <span class="hljs-number">300</span>, <span class="hljs-number">4</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># convert outputs (bounding boxes and class logits) to Pascal VOC format (xmin, ymin, xmax, ymax)</span>
<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-meta">&gt;&gt;&gt; </span>result = results[<span class="hljs-number">0</span>] <span class="hljs-comment"># first image in batch</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> score, label, box <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(result[<span class="hljs-string">&quot;scores&quot;</span>], result[<span class="hljs-string">&quot;labels&quot;</span>], result[<span class="hljs-string">&quot;boxes&quot;</span>]):
<span class="hljs-meta">... </span> box = [<span class="hljs-built_in">round</span>(i, <span class="hljs-number">2</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> box.tolist()]
<span class="hljs-meta">... </span> <span class="hljs-built_in">print</span>(
<span class="hljs-meta">... </span> <span class="hljs-string">f&quot;Detected <span class="hljs-subst">{model.config.id2label[label.item()]}</span> with confidence &quot;</span>
<span class="hljs-meta">... </span> <span class="hljs-string">f&quot;<span class="hljs-subst">{<span class="hljs-built_in">round</span>(score.item(), <span class="hljs-number">3</span>)}</span> at location <span class="hljs-subst">{box}</span>&quot;</span>
<span class="hljs-meta">... </span> )
Detected cat <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.958</span> at location [<span class="hljs-number">344.49</span>, <span class="hljs-number">23.4</span>, <span class="hljs-number">639.84</span>, <span class="hljs-number">374.27</span>]
Detected cat <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.956</span> at location [<span class="hljs-number">11.71</span>, <span class="hljs-number">53.52</span>, <span class="hljs-number">316.64</span>, <span class="hljs-number">472.33</span>]
Detected remote <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.947</span> at location [<span class="hljs-number">40.46</span>, <span class="hljs-number">73.7</span>, <span class="hljs-number">175.62</span>, <span class="hljs-number">117.57</span>]
Detected sofa <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.918</span> at location [<span class="hljs-number">0.59</span>, <span class="hljs-number">1.88</span>, <span class="hljs-number">640.25</span>, <span class="hljs-number">474.74</span>]`,lang:"python",wrap:!1}),a(o,n)},$$slots:{default:!0}}),c(D),c(h);var G=e(h,2);H(G,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/d_fine.md"}),N(2),a(Z,f),O()}export{ie as component};

Xet Storage Details

Size:
69.3 kB
·
Xet hash:
42a3f625d741b57a054708552b0855e059c10e73799643d8a322e81be9e120b7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.