Transformers documentation

MM Grounding DINO

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

该模型于 2024-01-04 在 HF papers 上发布,并于 2025-08-01 贡献至 Hugging Face Transformers。

MM Grounding DINO

MM Grounding DINO 模型由 Xiangyu Zhao、Yicheng Chen、Shilin Xu、Xiangtai Li、Xinjiang Wang、Yining Li 和 Haian Huang 在 An Open and Comprehensive Pipeline for Unified Object Grounding and Detection 中提出。

MM Grounding DINO 通过改进对比类头并移除解码器中的参数共享,对 Grounding DINO 进行了改进,从而在 COCO(50.6(+2.2) AP)和 LVIS(31.9(+11.8) val AP 和 41.4(+12.6) minival AP)上均提升了零样本检测性能。

您可以在 MM Grounding DINO 集合中找到所有原始的 MM Grounding DINO 检查点。该模型还支持 LLMDet 推理。您可以在 LLMDet 集合中找到 LLMDet 检查点。

点击右侧边栏中的 MM Grounding DINO 模型,以查看更多将 MM Grounding DINO 应用于不同 MM Grounding DINO 任务的示例。

以下示例演示了如何使用 AutoModelForZeroShotObjectDetection 类基于图像生成文本。

AutoModel
import torch

from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
from transformers.image_utils import load_image


# Prepare processor and model
model_id = "openmmlab-community/mm_grounding_dino_tiny_o365v1_goldg_v3det"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id, device_map="auto")

# Prepare inputs
image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = load_image(image_url)
text_labels = [["a cat", "a remote control"]]
inputs = processor(images=image, text=text_labels, return_tensors="pt").to(model.device)

# Run inference
with torch.no_grad():
    outputs = model(**inputs)

# Postprocess outputs
results = processor.post_process_grounded_object_detection(
    outputs,
    threshold=0.4,
    target_sizes=[(image.height, image.width)]
)

# Retrieve the first image result
result = results[0]
for box, score, labels in zip(result["boxes"], result["scores"], result["labels"]):
    box = [round(x, 2) for x in box.tolist()]
    print(f"Detected {labels} with confidence {round(score.item(), 3)} at location {box}")

备注

MMGroundingDinoConfig

class transformers.MMGroundingDinoConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0id2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Noneis_encoder_decoder: bool = Truebackbone_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonetext_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonenum_queries: int = 900encoder_layers: int = 6encoder_ffn_dim: int = 2048encoder_attention_heads: int = 8decoder_layers: int = 6decoder_ffn_dim: int = 2048decoder_attention_heads: int = 8activation_function: str = 'relu'd_model: int = 256dropout: float | int = 0.1attention_dropout: float | int = 0.0activation_dropout: float | int = 0.0auxiliary_loss: bool = Falseposition_embedding_type: str = 'sine'num_feature_levels: int = 4encoder_n_points: int = 4decoder_n_points: int = 4two_stage: bool = Trueclass_cost: float = 1.0bbox_cost: float = 5.0giou_cost: float = 2.0bbox_loss_coefficient: float = 5.0giou_loss_coefficient: float = 2.0focal_alpha: float = 0.25disable_custom_kernels: bool = Falsemax_text_len: int = 256text_enhancer_dropout: float | int = 0.0fusion_droppath: float | int = 0.1fusion_dropout: float | int = 0.0embedding_init_target: bool = Truequery_dim: int = 4positional_embedding_temperature: int = 20decoder_bbox_embed_share: bool = Truedecoder_cls_embed_share: bool = Trueinit_std: float = 0.02layer_norm_eps: float = 1e-05tie_word_embeddings: bool = True )

参数

  • is_encoder_decoder (bool,可选,默认为 True) — 指示该模型是否用作编码器/解码器。
  • backbone_config (Union[dict, ~configuration_utils.PreTrainedConfig],可选) — 主干模型的配置。
  • text_config (Union[dict, ~configuration_utils.PreTrainedConfig],可选) — 文本骨干网络的配置对象或字典。
  • num_queries (int,可选,默认值为 900) — 对象查询的数量,即检测槽位。这是 MMGroundingDinoModel 在单张图像中可检测到的最大对象数量。
  • encoder_layers (int,可选,默认为 6) — Transformer 编码器中的隐藏层数量。如果未设置,将使用与 num_layers 相同的值。
  • encoder_ffn_dim (int,可选,默认为 2048) — 编码器中“中间”(通常称为前馈)层的维度。
  • encoder_attention_heads (int,可选,默认为 8) — Transformer 编码器中每个注意力层的注意力头数量。
  • decoder_layers (int, 可选,默认为 6) — Transformer 解码器中的隐藏层数量。如果未设置,将使用与 num_layers 相同的值。
  • decoder_ffn_dim (int,可选,默认为 2048) — 解码器中“中间”(通常称为前馈)层的维度。
  • decoder_attention_heads (int,可选,默认为 8) — Transformer 解码器中每个注意力层的注意力头数量。
  • activation_function (str,可选,默认为 relu) — 解码器中的非线性激活函数(函数或字符串)。例如,"gelu"、"relu"、"silu" 等。
  • d_model (int,可选,默认为 256) — 编码器层和池化层的维度大小。
  • dropout (Union[float, int],可选,默认为 0.1) — 所有 dropout 层的比率。
  • attention_dropout (Union[float, int],可选,默认为 0.0) — 注意力概率的 dropout 比率。
  • activation_dropout (Union[float, int],可选,默认为 0.0) — 全连接层中激活值的 dropout 比率。
  • auxiliary_loss (bool,可选,默认为 False) — 是否使用辅助解码损失(即每个解码器层的损失)。
  • position_embedding_type (str,可选,默认为 "sine") — 用于叠加在图像特征之上的位置嵌入类型。取值为 "sine" 或 "learned" 之一。
  • num_feature_levels (int,可选,默认为 4) — 输入特征层级的数量。
  • encoder_n_points (int,可选,默认为 4) — 编码器中每个注意力头在每个特征层级中采样的键数量。
  • decoder_n_points (int,可选,默认为 4) — 解码器中每个注意力头在每个特征层级上采样的键数量。
  • two_stage (bool,可选,默认为 True) — 是否应用两阶段可变形 DETR,其中区域建议也由 Grounding DINO 的变体生成,并进一步输入解码器以进行迭代边界框细化。
  • class_cost (float,可选,默认为 1.0) — 匈牙利匹配代价中分类误差的相对权重。
  • bbox_cost (float,可选,默认为 5.0) — 匈牙利匹配代价中 L1 边界框误差的相对权重。
  • giou_cost (float,可选,默认为 2.0) — 匈牙利匹配代价中广义 IoU 损失的相对权重。
  • bbox_loss_coefficient (float,可选,默认为 5.0) — 全景分割损失中 L1 边界框损失的相对权重。
  • giou_loss_coefficient (float,可选,默认为 2.0) — 全景分割损失中广义 IoU 损失的相对权重。
  • focal_alpha (float,可选,默认为 0.25) — Focal loss 中的 Alpha 参数。
  • disable_custom_kernels (bool,可选,默认为 False) — 禁用自定义 CUDA 和 CPU 内核。此选项对于 ONNX 导出是必需的,因为 PyTorch ONNX 导出不支持自定义内核。
  • max_text_len (int,可选,默认为 256) — 文本输入的最大长度。
  • text_enhancer_dropout (float,可选,默认值为 0.0) — 文本增强器的 dropout 比率。
  • fusion_droppath (float, 可选,默认为 0.1) — 融合模块的 droppath 比率。
  • fusion_dropout (float, 可选,默认为 0.0) — 融合模块的 dropout 比率。
  • embedding_init_target (bool,可选,默认为 True) — 是否使用 Embedding 权重来初始化 target。
  • query_dim (int,可选,默认为 4) — 查询向量的维度。
  • positional_embedding_temperature (float,可选,默认为 20) — 与视觉骨干网络一起使用的正弦位置嵌入的温度。
  • decoder_bbox_embed_share (bool,可选,默认为 True) — 是否在所有解码器层之间共享 bbox 回归头。
  • decoder_cls_embed_share (bool,可选,默认为 True) — 是否在所有解码器层之间共享类别嵌入头。
  • init_std (float,可选,默认为 0.02) — 用于初始化所有权重矩阵的 truncated_normal_initializer 的标准差。
  • layer_norm_eps (float,可选,默认为 1e-05) — 层归一化层所使用的 epsilon 值。
  • tie_word_embeddings (bool,可选,默认为 True) — 是否根据模型的 tied_weights_keys 映射来绑定权重嵌入。

这是用于存储 Mm Grounding Dino 模型配置的类。它根据指定的参数实例化 Mm Grounding Dino 模型,并定义模型架构。使用默认值实例化配置,将得到与 openmmlab-community/mm_grounding_dino_tiny_o365v1_goldg_v3det 类似的配置。

配置对象继承自 PreTrainedConfig,可用于控制模型输出。有关更多信息,请参阅 PreTrainedConfig 的文档。

示例:

>>> from transformers import MMGroundingDinoConfig, MMGroundingDinoModel

>>> # Initializing a MM Grounding DINO configuration
>>> configuration = MMGroundingDinoConfig()

>>> # Initializing a model (with random weights) from the configuration
>>> model = MMGroundingDinoModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

MMGroundingDinoModel

class transformers.MMGroundingDinoModel

< >

( config: MMGroundingDinoConfig )

参数

  • config (MMGroundingDinoConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

原始的 Grounding DINO 模型(由骨干网络和编码器-解码器 Transformer 组成),其顶部没有添加任何特定的头,直接输出原始的隐藏状态。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensorinput_ids: Tensortoken_type_ids: typing.Optional[torch.Tensor] = Noneattention_mask: typing.Optional[torch.Tensor] = Nonepixel_mask: typing.Optional[torch.Tensor] = Noneencoder_outputs = Noneoutput_attentions = Noneoutput_hidden_states = Nonereturn_dict = None**kwargs ) → MMGroundingDinoModelOutput or tuple(torch.Tensor)

参数

  • pixel_values (torch.Tensor,形状为 (batch_size, num_channels, image_size, image_size)) — 对应输入图像的张量。可以使用 GroundingDinoImageProcessor 获取像素值。有关详细信息,请参阅 GroundingDinoImageProcessor.call()(GroundingDinoProcessor 使用 GroundingDinoImageProcessor 来处理图像)。
  • input_ids (torch.LongTensor 形状为 (batch_size, text_sequence_length)) — 输入序列中各 token 在词汇表中的索引。如果您提供了填充,默认情况下将被忽略。

    可以使用 AutoTokenizer 获取索引。有关详细信息,请参阅 BertTokenizer.call()。

  • token_type_ids (torch.LongTensor 形状为 (batch_size, text_sequence_length), ,可选) — 。用于指示输入中第一和第二部分的段标记索引。索引取自 [0, 1]: 0 ,对应 sentence A 标记,1 对应 sentence B 标记。

    什么是 token type ID?

  • attention_mask (torch.Tensor 形状为 (batch_size, sequence_length), ,可选) — 用于避免对填充 token 索引执行注意力机制的掩码。掩码值取自 [0, 1]:
    • 1 表示未被屏蔽的 token,
    • 对于被掩码的 token,值为 0。

    什么是注意力掩码?

  • pixel_mask (torch.Tensor 形状为 (batch_size, height, width), 可选) — 用于避免对填充像素值执行注意力的掩码。掩码值取自 [0, 1]:
    • 对于真实的像素(即未被掩码的像素),值为 1,
    • 对于填充像素(即 被屏蔽 的像素),值为 0。

    什么是注意力掩码?

  • encoder_outputs (`) -- Tuple consists of (last_hidden_state, *optional*: hidden_states, *optional*: attentions) last_hidden_stateof shape(batch_size, sequence_length, hidden_size)`, optional) is a sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
  • output_attentions (`) -- Whether or not to return the attentions tensors of all attention layers. See attentions` under returned tensors for more detail.
  • output_hidden_states (`) -- Whether or not to return the hidden states of all layers. See hidden_states` under returned tensors for more detail.
  • return_dict(“) — 是否返回 ModelOutput 而不是普通元组。

返回值

MMGroundingDinoModelOutput 或 tuple(torch.Tensor)

MMGroundingDinoModelOutput 或 torch.Tensor 元组(当传入 return_dict=False 或 config.return_dict=False 时),其包含的元素取决于配置(MMGroundingDinoConfig)和输入。

MMGroundingDinoModel 的 forward 方法会重写 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • last_hidden_state(形状为 (batch_size, num_queries, hidden_size) 的 torch.Tensor)— 模型解码器最后一层输出的隐藏状态序列。

  • init_reference_points(形状为 (batch_size, num_queries, 4) 的 torch.Tensor)— 通过 Transformer 解码器传输的初始参考点。

  • intermediate_hidden_states(形状为 (batch_size, config.decoder_layers, num_queries, hidden_size) 的 torch.Tensor)— 堆叠的中间隐藏状态(解码器每一层的输出)。

  • intermediate_reference_points(形状为 (batch_size, config.decoder_layers, num_queries, 4) 的 torch.Tensor)— 堆叠的中间参考点(解码器每一层的参考点)。

  • decoder_hidden_states (tuple[torch.Tensor],可选,在传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(如果模型具有嵌入层,则包含嵌入层输出的一个张量,以及每个层输出的一个张量),形状为 (batch_size, sequence_length, hidden_size)。

    解码器在每一层输出处的隐藏状态,以及初始嵌入输出。

  • decoder_attentions(tuple[tuple[torch.Tensor]],可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回)—— 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)。

    解码器在注意力 softmax 之后的注意力权重,用于在自注意力头中计算加权平均值。

  • encoder_last_hidden_state_vision(形状为 (batch_size, sequence_length, hidden_size) 的 torch.Tensor,可选)— 模型编码器最后一层输出的隐藏状态序列。

  • encoder_last_hidden_state_text(形状为 (batch_size, sequence_length, hidden_size) 的 torch.Tensor,可选)— 模型编码器最后一层输出的隐藏状态序列。

  • encoder_vision_hidden_states (tuple(torch.Tensor),可选,在传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(包含视觉嵌入的输出以及每一层的输出),形状为 (batch_size, sequence_length, hidden_size)。视觉编码器在每一层输出处的隐藏状态,以及初始嵌入输出。

  • encoder_text_hidden_states (tuple(torch.Tensor),可选,在传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — torch.Tensor 的元组(包含文本嵌入的输出以及每一层的输出,各一个), 形状为 (batch_size, sequence_length, hidden_size)。文本编码器在每一层输出处的隐藏状态,以及初始嵌入的输出。

  • encoder_attentions (tuple(tuple(torch.Tensor)),可选,在传入 output_attentions=True 或 config.output_attentions=True 时返回) — 由 torch.Tensor 元组的元组组成(每层注意力对应一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)。注意力 softmax 之后的注意力权重,用于计算文本-视觉注意力、视觉-文本注意力、文本增强器(自注意力)以及多尺度可变形注意力头中的加权平均值。注意力 softmax,用于计算双向注意力头中的加权平均值。

  • enc_outputs_class (torch.Tensor,形状为 (batch_size, sequence_length, config.num_labels),可选,当 config.two_stage=True 时返回) — 预测的边界框分数,其中得分最高的 config.num_queries 个边界框将在第一阶段被选为区域建议。边界框二分类(即前景和背景)的输出。

  • enc_outputs_coord_logits (torch.Tensor,形状为 (batch_size, sequence_length, 4),可选,当 config.two_stage=True 时返回) — 第一阶段中预测的边界框坐标的 logits。

  • encoder_logits(形状为 (batch_size, sequence_length, config.num_labels) 的 torch.Tensor,可选,当 config.two_stage=True 时返回) — 第一阶段中得分最高的 config.num_queries 个边界框的 logits。

  • encoder_pred_boxes(形状为 (batch_size, sequence_length, 4) 的 torch.Tensor,可选,当 config.two_stage=True 时返回) — 第一阶段中得分最高的 config.num_queries 个边界框的坐标。

示例:

>>> from transformers import AutoProcessor, AutoModel
>>> from PIL import Image
>>> from huggingface_hub.utils import httpx
>>> from io import BytesIO

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> text = "a cat."

>>> processor = AutoProcessor.from_pretrained("IDEA-Research/grounding-dino-tiny")
>>> model = AutoModel.from_pretrained("IDEA-Research/grounding-dino-tiny")

>>> inputs = processor(images=image, text=text, return_tensors="pt")
>>> outputs = model(**inputs)

>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
[1, 900, 256]

MMGroundingDinoForObjectDetection

class transformers.MMGroundingDinoForObjectDetection

< >

( config: MMGroundingDinoConfig )

参数

  • config (MMGroundingDinoConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

Grounding DINO 模型(由骨干网络和编码器-解码器 Transformer 组成),顶部带有目标检测头, 用于 COCO 检测等任务。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensorinput_ids: LongTensortoken_type_ids: typing.Optional[torch.LongTensor] = Noneattention_mask: typing.Optional[torch.LongTensor] = Nonepixel_mask: typing.Optional[torch.BoolTensor] = Noneencoder_outputs: transformers.models.mm_grounding_dino.modeling_mm_grounding_dino.MMGroundingDinoEncoderOutput | tuple | None = Noneoutput_attentions: bool | None = Noneoutput_hidden_states: bool | None = Nonereturn_dict: bool | None = Nonelabels: list[dict[str, typing.Union[torch.LongTensor, torch.Tensor]]] | None = None**kwargs )

参数

  • pixel_values (torch.Tensor,形状为 (batch_size, num_channels, image_size, image_size)) — 对应输入图像的张量。可以使用 GroundingDinoImageProcessor 获取像素值。有关详细信息,请参阅 GroundingDinoImageProcessor.call()(GroundingDinoProcessor 使用 GroundingDinoImageProcessor 来处理图像)。
  • input_ids (torch.LongTensor 形状为 (batch_size, text_sequence_length)) — 输入序列中各 token 在词汇表中的索引。如果您提供了填充,默认情况下将被忽略。

    可以使用 AutoTokenizer 获取索引。有关详细信息,请参阅 BertTokenizer.call()。

  • token_type_ids (torch.LongTensor 形状为 (batch_size, text_sequence_length), ,可选) — 。用于指示输入中第一和第二部分的段标记索引。索引取自 [0, 1]: 0 ,对应 sentence A 标记,1 对应 sentence B 标记。

    什么是 token type ID?

  • attention_mask (torch.LongTensor 形状为 (batch_size, sequence_length), ,可选) — 用于避免对填充(padding)标记索引执行注意力机制的掩码。掩码值取自 [0, 1]:1 表示未屏蔽的标记,0 表示被屏蔽的标记。什么是注意力掩码? [0, 1]:
    • 1 表示未被屏蔽的 token,
    • 对于被掩码的 token,值为 0。

    什么是注意力掩码?

  • pixel_mask (torch.BoolTensor 形状为 (batch_size, height, width), ,可选) — 用于避免对填充像素值执行注意力机制的掩码。掩码值取自 [0, 1]:
    • 对于真实的像素(即未被掩码的像素),值为 1,
    • 对于填充像素(即 被屏蔽 的像素),值为 0。

    什么是注意力掩码?

  • encoder_outputs (Union[~models.mm_grounding_dino.modeling_mm_grounding_dino.MMGroundingDinoEncoderOutput, tuple], 可选) — 元组由 (last_hidden_state, 可选: hidden_states, 可选: attentions) last_hidden_state 的形状为 (batch_size, sequence_length, hidden_size), 可选) 是编码器最后一层输出的隐藏状态序列。用于解码器的交叉注意力。
  • output_attentions (bool, 可选) — 是否返回所有注意力层的注意力张量。有关详细信息,请参阅返回张量中的 attentions。
  • output_hidden_states (bool,可选) — 是否返回所有层的隐藏状态。有关更多详细信息,请参阅返回张量中的 hidden_states。
  • return_dict (bool, 可选) — 是否返回 ModelOutput 而不是普通元组。
  • labels (list[Dict],长度为 (batch_size,),可选) — 用于计算二部图匹配损失的标签。一个字典列表,每个字典至少包含以下 2 个键:‘class_labels’ 和 ‘boxes’(分别表示批次中某张图像的分类标签和边界框)。分类标签本身应是一个长度为 (number of bounding boxes in the image,) 的 torch.LongTensor,边界框应是一个形状为 (number of bounding boxes in the image, 4) 的 torch.Tensor。

MMGroundingDinoForObjectDetection 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

示例:

>>> from huggingface_hub.utils import httpx
>>> from io import BytesIO

>>> import torch
>>> from PIL import Image
>>> from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection

>>> model_id = "IDEA-Research/grounding-dino-tiny"
>>> device = "cuda"

>>> processor = AutoProcessor.from_pretrained(model_id)
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> # Check for cats and remote controls
>>> text_labels = [["a cat", "a remote control"]]

>>> inputs = processor(images=image, text=text_labels, return_tensors="pt").to(device)
>>> with torch.no_grad():
...     outputs = model(**inputs)

>>> results = processor.post_process_grounded_object_detection(
...     outputs,
...     threshold=0.4,
...     text_threshold=0.3,
...     target_sizes=[(image.height, image.width)]
... )
>>> # Retrieve the first image result
>>> result = results[0]
>>> for box, score, text_label in zip(result["boxes"], result["scores"], result["text_labels"]):
...     box = [round(x, 2) for x in box.tolist()]
...     print(f"Detected {text_label} with confidence {round(score.item(), 3)} at location {box}")
Detected a cat with confidence 0.479 at location [344.7, 23.11, 637.18, 374.28]
Detected a cat with confidence 0.438 at location [12.27, 51.91, 316.86, 472.44]
Detected a remote control with confidence 0.478 at location [38.57, 70.0, 176.78, 118.18]
Update on GitHub