0

0

DETR:基于transformer实现端到端目标检测

P粉084495128

P粉084495128

发布时间:2025-07-24 11:39:47

|

220人浏览过

|

来源于php中文网

原创

本文复现detr目标检测方案,基于transformer实现端到端检测,无需nms或anchor生成。模型含cnn(res50)+transformer+ffn结构,用二分图匹配与匈牙利算法处理预测框。适配paddle 2.0,修复bug并对齐精度,detr-dc5变体在coco2017验证集map达0.431。

☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

detr:基于transformer实现端到端目标检测 - php中文网

模型介绍

论文复现第三期DETR方案, 精确度MAP为0.431

End-to-End Object Detection with Transformers

参考代码: https://aistudio.baidu.com/aistudio/projectdetail/1327221

  • 在大佬的基础上进行修改,包括Paddle 2.0适配, BUG修复,以及精度对齐等工作

github pytorch代码: https://github.com/facebookresearch/detr

论文地址: https://arxiv.org/pdf/1706.03762.pdf

  • 基于transformer实现端到端目标检测, 两大主要组成,一者是预测的匹配损失函数,再者预测目标和他们的关系。
  • 不需要使用NMS或者anchor生成, 本文能将该任务的先验知识进行编码。DETR结合目标关联关系和上下文直接并行输出最终的预测集。
  • Bipartite Matching二分图最大匹配, 将节点集V分割为互不相割的子集。训练时将预测框和GT boxes进行匹配。若没有找到匹配的预测框作为"no object"。 最终计算匹配损失。
  • transformer的自注意力机制,专门对序列中成对交互的元素进行建模,所以也很好解决去除重复框
  • 推理出的box坐标是直接基于输入图片而不是基于anchor
  • 先预设固定数量的预测量,通常比图像的目标数量多。南调是对预测目标进行评分,使用最低成对匹配成本,用到匈牙利算法。线性组合IOU损失和L1损失。
  • 网络结构由cnn(res50)+transformer+FFN. 常用的backbone都可以用。cnn到transformer通过1x1卷积进行降维,空间维度压缩到一维, FFN由3层MLP+relu组成。
  • backbone和transformer分开训练,学习率设置不一样。具体是怎样的方式?
  • 关于transformer,
    • 其实就是全连接(或一维卷积)加上attention结合体,对于局部特征捕获能力稍欠缺。
    • 编解码结构较大的局限性是固定长度的语义向量, 编码器压缩成一个固长向量无法表示整个序列信息, 前期信息容易被后序信息覆盖,解码时输入每个单词权重不一致。
    • attention解决编解码结构的弊端,编码器时将正序和逆序的隐藏层状态结合起来, 解码时步骤,1.计算编码器隐藏层状态和解码器隐藏层状态间的相关程度并用softmax归一化得到权重值, 2. 计算语义编码向量的加权和,3. 根据加权和计算隐藏状态和解码器输出。不同编解码结构的是解码时选择性的从向量序列中挑选。
    • soft attention缺点是每次decode都会计算所有编码器隐藏层状态向量,计算复杂度较高。hard attention每次近选择一个source进行计算,缺点是不可微,无法反向传播。
    • global attetion也属于soft attention, 只是计算权重公式上有差别。实验表明general方式好一些。
    • local attention, 每次选择一部分source进行计算, 既减少计算量又能可微。思路是为decoder预测一个source位置,然后基于位置选择一个窗口用于计算编码向量。关键是怎么确定pt位置, monotoic或predictive。
    • self attention, 传统attention是基于target和source间的相似度,而self是发生在target内部或者source内部的相似关联。self更容易捕获长距依赖特征。query和key点积相当于给每个单词打分,决定了编码单词时重视句子其他部分的程度。softmax决定了其他单词对当前单词编码的贡献,self作为最大,其他单词也很有参考作用。
    • transformer和attention机制一样,只是更复杂,多个encoder和docoder堆叠一起, encoder包含self-attention(不仅仅当前词还有上下文)和神经网络层(可并行),decoder多了一层attention(当前需关注的重点内容)。encoder前要对输入数据进行embedding操作。
    • 位置编码, transformer缺少解释序列中单词顺序的方法,positional encoding在维度上和embedding一样,偶数位置正弦编码,奇数位置余弦编码,决定当前词的位置或不同词间距离,并且模型可学习到。
    • 多头注意力,主要扩展了模型专注不同位置的能力,给出了注意力层的多个表示子空间。8个头就有8套qkv矩阵,每个头的qkv矩阵权重独立,将这些矩阵拼接在一起并用附加权重矩阵相乘。
    • transformer还使用到了残差和layer norm。LN是在每一个样本上计算均值和方差,而不是BN那种在批方向计算均值和方差。还用到了mask,掩盖值,使其参数更新时不产生效果, padding mask在较短序列填充0,Sequence mask只依赖t之前的信息,将t之后信息掩盖起来。

关于数据集COCO2017

COCO的全称是Common Objects in Context,是微软团队提供的一个可以用来进行图像识别的数据集。MS COCO数据集中的图像分为训练、验证和测试集。其行业地位就不再多少了,本文主要梳理一下该数据集包含的内容。下图是官网给出的可下载的数据集(更新时间2020年01月09日),从这里可看出其数据集主要包括有标注的和无标注的数据。

DETR:基于transformer实现端到端目标检测 - php中文网        

In [ ]
#解压数据集%cd /home/aistudio/data/data7122/ 
!unzip train2017.zip!unzip val2017.zip !unzip annotations_trainval2017.zip
   
In [ ]
#加载数据集%cd ~/my_detr
!python coco_dataset.py
   

模型结构搭建

  1. Backbone在resnet50基础上修改,支持DC5变体
  2. 搭建transformer结构
  3. 搭建后处理包括匈牙利匹配算法
  4. 损失函数
  5. 后处理

核心代码主要有:

  • model.py
  • resnet.py
  • backbone.py
  • transformer.py

DETR:基于transformer实现端到端目标检测 - php中文网        

In [ ]
<br/>
   

精度对齐

因为loss函数以及后处理较为复杂,所以这里特定还用了loss精度对齐

紫东太初
紫东太初

中科院和武汉AI研究院推出的新一代大模型

下载

输出结果结果精度对齐

模拟tensor输入: image = [paddle.ones(shape=[3, 800, 1199])] samples.tensors = torch.ones(1, 3, 800, 1199) 因为resize对图像输入有一定差距,所以使用ones的张量, 比如使用样例数据, 0.348(torch) vs 0.31(paddle)

pytorch结果:

DETR:基于transformer实现端到端目标检测 - php中文网        

paddle结果:

DETR:基于transformer实现端到端目标检测 - php中文网        

LOSS 精度对齐

相差小数点2位

Pytorch的结果:

DETR:基于transformer实现端到端目标检测 - php中文网        

PaddlePaddle的结果:

DETR:基于transformer实现端到端目标检测 - php中文网        

训练DETR

In [ ]
#开始训练%cd ~/my_detr
!python train_val.py train
       
/home/aistudio/my_detr
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  def convert_to_list(value, n, name, dtype=np.int):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sized
---->
{'hidden_dim': 256, 'lr_backbone': -1, 'masks': False, 'dilation': False, 'backbone': 'resnet50', 'num_classes': 91, 'dropout': 0.1, 'nheads': 8, 'dim_feedforward': 2048, 'enc_layers': 6, 'dec_layers': 6, 'pre_norm': False, 'num_queries': 100, 'aux_loss': True, 'set_cost_class': 1, 'set_cost_bbox': 5, 'set_cost_giou': 2, 'bbox_loss_coef': 5, 'giou_loss_coef': 2, 'eos_coef': 0.1, 'coco_path': '/home/aistudio/data/data7122', 'lr': 1e-06, 'clip_max_norm': 0.1, 'batch_size': 8, 'epochs': 2}
{'num_classes': 91, 'norm_layer': <class 'backbone.FrozenBatchNorm2d'>}
block <class 'resnet.BottleneckBlock'>
[False, False, False]
W0514 19:16:37.620630 26619 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0514 19:16:37.627422 26619 device_context.cc:372] device: 0, cuDNN Version: 7.6.
debug: 1 1
debug: 2 1
debug: 2 1
debug: 2 1
Epoch 0: StepDecay set learning rate to 1e-06.
loading annotations into memory...
Done (t=0.56s)
creating index...
index created!
loading annotations into memory...
Done (t=0.69s)
creating index...
index created!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py:687: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  elif dtype == np.bool:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:143: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.FP32, but right dtype is VarType.INT64, the right dtype will convert to VarType.FP32
  format(lhs_dtype, rhs_dtype, lhs_dtype))
epoch: 0, batch_id: 0, loss: 10.05978012084961
epoch: 0, batch_id: 100, loss: 6.360683917999268
epoch: 0, batch_id: 200, loss: 6.134881973266602
epoch: 0, batch_id: 300, loss: 7.114040851593018
epoch: 0, batch_id: 400, loss: 6.500746250152588
epoch: 0, batch_id: 500, loss: 6.7673797607421875
epoch: 0, batch_id: 600, loss: 5.745387554168701
epoch: 1, batch_id: 0, loss: 7.610352993011475
epoch: 1, batch_id: 100, loss: 5.726753234863281
epoch: 1, batch_id: 200, loss: 5.837918758392334
epoch: 1, batch_id: 300, loss: 6.997137069702148
epoch: 1, batch_id: 400, loss: 6.292409420013428
epoch: 1, batch_id: 500, loss: 6.677578926086426
epoch: 1, batch_id: 600, loss: 5.692938327789307
       

验证DETR

In [14]
%cd ~/my_detr
!python train_val.py eval
       
/home/aistudio/my_detr
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  def convert_to_list(value, n, name, dtype=np.int):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sized
---->
{'hidden_dim': 256, 'lr_backbone': -1, 'masks': False, 'dilation': False, 'backbone': 'resnet50', 'num_classes': 91, 'dropout': 0.1, 'nheads': 8, 'dim_feedforward': 2048, 'enc_layers': 6, 'dec_layers': 6, 'pre_norm': False, 'num_queries': 100, 'aux_loss': True, 'set_cost_class': 1, 'set_cost_bbox': 5, 'set_cost_giou': 2, 'bbox_loss_coef': 5, 'giou_loss_coef': 2, 'eos_coef': 0.1, 'coco_path': '/home/aistudio/data/data7122', 'lr': 1e-06, 'clip_max_norm': 0.1, 'batch_size': 8, 'epochs': 2}
{'num_classes': 91, 'norm_layer': <class 'backbone.FrozenBatchNorm2d'>}
block <class 'resnet.BottleneckBlock'>
[False, False, False]
W0514 21:08:15.278102  7932 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0514 21:08:15.283421  7932 device_context.cc:372] device: 0, cuDNN Version: 7.6.
debug: 1 1
debug: 2 1
debug: 2 1
debug: 2 1
Epoch 0: StepDecay set learning rate to 1e-06.
loading annotations into memory...
Done (t=0.55s)
creating index...
index created!
loading annotations into memory...
Done (t=0.68s)
creating index...
index created!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py:687: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  elif dtype == np.bool:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.FP32, but right dtype is VarType.INT64, the right dtype will convert to VarType.FP32
  format(lhs_dtype, rhs_dtype, lhs_dtype))
Accumulating evaluation results...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:378: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:379: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
DONE (t=11.61s).
IoU metric: bbox
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.420
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.624
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.442
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.213
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.460
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.611
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.334
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.533
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.575
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.325
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.631
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.809
       

训练DETR-DC5

这个模型非常耗显存, 很难训练

In [ ]
#开始训练DC5%cd ~/my_detr
!python train_val_dc5.py train
       
/home/aistudio/my_detr
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  def convert_to_list(value, n, name, dtype=np.int):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sized
---->
{'hidden_dim': 256, 'lr_backbone': -1, 'masks': False, 'dilation': True, 'backbone': 'resnet50', 'num_classes': 91, 'dropout': 0.1, 'nheads': 8, 'dim_feedforward': 2048, 'enc_layers': 6, 'dec_layers': 6, 'pre_norm': False, 'num_queries': 100, 'aux_loss': True, 'set_cost_class': 1, 'set_cost_bbox': 5, 'set_cost_giou': 2, 'bbox_loss_coef': 5, 'giou_loss_coef': 2, 'eos_coef': 0.1, 'coco_path': '/home/aistudio/data/data7122', 'lr': 1e-06, 'clip_max_norm': 0.1, 'batch_size': 1, 'epochs': 1}
{'num_classes': 91, 'replace_stride_with_dilation': [False, False, True], 'norm_layer': <class 'backbone.FrozenBatchNorm2d'>}
block <class 'resnet.BottleneckBlock'>
[False, False, True]
W0514 17:11:00.507395 24269 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0514 17:11:00.512784 24269 device_context.cc:372] device: 0, cuDNN Version: 7.6.
debug: 1 1
debug: 2 1
debug: 2 1
debug: 1 2
530
Epoch 0: StepDecay set learning rate to 1e-06.
loading annotations into memory...
Done (t=0.57s)
creating index...
index created!
loading annotations into memory...
Done (t=0.70s)
creating index...
index created!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py:687: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  elif dtype == np.bool:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:143: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.FP32, but right dtype is VarType.INT64, the right dtype will convert to VarType.FP32
  format(lhs_dtype, rhs_dtype, lhs_dtype))
epoch: 0, batch_id: 0, loss: 5.015964031219482
epoch: 0, batch_id: 100, loss: 14.247769355773926
epoch: 0, batch_id: 200, loss: 7.298154830932617
epoch: 0, batch_id: 300, loss: 1.0471426248550415
epoch: 0, batch_id: 400, loss: 7.584997653961182
epoch: 0, batch_id: 500, loss: 3.577380895614624
epoch: 0, batch_id: 600, loss: 4.61794900894165
epoch: 0, batch_id: 700, loss: 5.049403667449951
epoch: 0, batch_id: 800, loss: 5.122508525848389
epoch: 0, batch_id: 900, loss: 3.216052770614624
epoch: 0, batch_id: 1000, loss: 3.3042514324188232
epoch: 0, batch_id: 1100, loss: 4.413068771362305
epoch: 0, batch_id: 1200, loss: 7.288424015045166
epoch: 0, batch_id: 1300, loss: 6.1409735679626465
epoch: 0, batch_id: 1400, loss: 10.504143714904785
epoch: 0, batch_id: 1500, loss: 3.685210704803467
epoch: 0, batch_id: 1600, loss: 2.6168665885925293
epoch: 0, batch_id: 1700, loss: 22.14373016357422
epoch: 0, batch_id: 1800, loss: 8.267280578613281
epoch: 0, batch_id: 1900, loss: 1.4486600160598755
epoch: 0, batch_id: 2000, loss: 4.107017993927002
epoch: 0, batch_id: 2100, loss: 9.582965850830078
epoch: 0, batch_id: 2200, loss: 6.967478275299072
epoch: 0, batch_id: 2300, loss: 15.338693618774414
epoch: 0, batch_id: 2400, loss: 13.399685859680176
epoch: 0, batch_id: 2500, loss: 1.4326478242874146
epoch: 0, batch_id: 2600, loss: 6.990074157714844
epoch: 0, batch_id: 2700, loss: 8.32422161102295
epoch: 0, batch_id: 2800, loss: 5.453993797302246
epoch: 0, batch_id: 2900, loss: 7.272365093231201
epoch: 0, batch_id: 3000, loss: 8.217702865600586
epoch: 0, batch_id: 3100, loss: 2.2091081142425537
epoch: 0, batch_id: 3200, loss: 0.9168111085891724
epoch: 0, batch_id: 3300, loss: 1.9928405284881592
epoch: 0, batch_id: 3400, loss: 6.245678424835205
epoch: 0, batch_id: 3500, loss: 8.91486930847168
epoch: 0, batch_id: 3600, loss: 6.916267395019531
epoch: 0, batch_id: 3700, loss: 4.461080551147461
epoch: 0, batch_id: 3800, loss: 8.265044212341309
epoch: 0, batch_id: 3900, loss: 8.603659629821777
epoch: 0, batch_id: 4000, loss: 4.085428714752197
epoch: 0, batch_id: 4100, loss: 10.250466346740723
epoch: 0, batch_id: 4200, loss: 2.327882766723633
epoch: 0, batch_id: 4300, loss: 3.273315906524658
epoch: 0, batch_id: 4400, loss: 6.719542026519775
epoch: 0, batch_id: 4500, loss: 3.232994794845581
epoch: 0, batch_id: 4600, loss: 4.106349945068359
epoch: 0, batch_id: 4700, loss: 1.6361501216888428
epoch: 0, batch_id: 4800, loss: 4.615266799926758
epoch: 0, batch_id: 4900, loss: 8.394232749938965
start evaluating....
Accumulating evaluation results...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:378: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:379: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
DONE (t=9.37s).
IoU metric: bbox
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.432
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.634
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.458
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.223
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.471
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.612
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.340
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.551
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.591
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.334
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.642
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.815
save weights with map:  0.43226377363430357
       

验证DETR-DC5

In [15]
#验证DETR-DC5%cd ~/my_detr
!python train_val_dc5.py eval
       
/home/aistudio/my_detr
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  def convert_to_list(value, n, name, dtype=np.int):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sized
---->
{'hidden_dim': 256, 'lr_backbone': -1, 'masks': False, 'dilation': True, 'backbone': 'resnet50', 'num_classes': 91, 'dropout': 0.1, 'nheads': 8, 'dim_feedforward': 2048, 'enc_layers': 6, 'dec_layers': 6, 'pre_norm': False, 'num_queries': 100, 'aux_loss': True, 'set_cost_class': 1, 'set_cost_bbox': 5, 'set_cost_giou': 2, 'bbox_loss_coef': 5, 'giou_loss_coef': 2, 'eos_coef': 0.1, 'coco_path': '/home/aistudio/data/data7122', 'lr': 1e-06, 'clip_max_norm': 0.1, 'batch_size': 1, 'epochs': 1}
{'num_classes': 91, 'replace_stride_with_dilation': [False, False, True], 'norm_layer': <class 'backbone.FrozenBatchNorm2d'>}
block <class 'resnet.BottleneckBlock'>
[False, False, True]
W0514 21:21:04.015319  9341 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0514 21:21:04.020784  9341 device_context.cc:372] device: 0, cuDNN Version: 7.6.
debug: 1 1
debug: 2 1
debug: 2 1
debug: 1 2
Epoch 0: StepDecay set learning rate to 1e-06.
loading annotations into memory...
Done (t=0.56s)
creating index...
index created!
loading annotations into memory...
Done (t=0.69s)
creating index...
index created!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py:687: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  elif dtype == np.bool:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.FP32, but right dtype is VarType.INT64, the right dtype will convert to VarType.FP32
  format(lhs_dtype, rhs_dtype, lhs_dtype))
Accumulating evaluation results...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:378: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:379: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
DONE (t=9.90s).
IoU metric: bbox
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.431
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.630
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.458
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.223
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.470
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.609
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.340
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.549
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.593
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.339
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.645
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.812
       

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
C# ASP.NET Core微服务架构与API网关实践
C# ASP.NET Core微服务架构与API网关实践

本专题围绕 C# 在现代后端架构中的微服务实践展开,系统讲解基于 ASP.NET Core 构建可扩展服务体系的核心方法。内容涵盖服务拆分策略、RESTful API 设计、服务间通信、API 网关统一入口管理以及服务治理机制。通过真实项目案例,帮助开发者掌握构建高可用微服务系统的关键技术,提高系统的可扩展性与维护效率。

74

2026.03.11

Go高并发任务调度与Goroutine池化实践
Go高并发任务调度与Goroutine池化实践

本专题围绕 Go 语言在高并发任务处理场景中的实践展开,系统讲解 Goroutine 调度模型、Channel 通信机制以及并发控制策略。内容包括任务队列设计、Goroutine 池化管理、资源限制控制以及并发任务的性能优化方法。通过实际案例演示,帮助开发者构建稳定高效的 Go 并发任务处理系统,提高系统在高负载环境下的处理能力与稳定性。

38

2026.03.10

Kotlin Android模块化架构与组件化开发实践
Kotlin Android模块化架构与组件化开发实践

本专题围绕 Kotlin 在 Android 应用开发中的架构实践展开,重点讲解模块化设计与组件化开发的实现思路。内容包括项目模块拆分策略、公共组件封装、依赖管理优化、路由通信机制以及大型项目的工程化管理方法。通过真实项目案例分析,帮助开发者构建结构清晰、易扩展且维护成本低的 Android 应用架构体系,提升团队协作效率与项目迭代速度。

83

2026.03.09

JavaScript浏览器渲染机制与前端性能优化实践
JavaScript浏览器渲染机制与前端性能优化实践

本专题围绕 JavaScript 在浏览器中的执行与渲染机制展开,系统讲解 DOM 构建、CSSOM 解析、重排与重绘原理,以及关键渲染路径优化方法。内容涵盖事件循环机制、异步任务调度、资源加载优化、代码拆分与懒加载等性能优化策略。通过真实前端项目案例,帮助开发者理解浏览器底层工作原理,并掌握提升网页加载速度与交互体验的实用技巧。

97

2026.03.06

Rust内存安全机制与所有权模型深度实践
Rust内存安全机制与所有权模型深度实践

本专题围绕 Rust 语言核心特性展开,深入讲解所有权机制、借用规则、生命周期管理以及智能指针等关键概念。通过系统级开发案例,分析内存安全保障原理与零成本抽象优势,并结合并发场景讲解 Send 与 Sync 特性实现机制。帮助开发者真正理解 Rust 的设计哲学,掌握在高性能与安全性并重场景中的工程实践能力。

223

2026.03.05

PHP高性能API设计与Laravel服务架构实践
PHP高性能API设计与Laravel服务架构实践

本专题围绕 PHP 在现代 Web 后端开发中的高性能实践展开,重点讲解基于 Laravel 框架构建可扩展 API 服务的核心方法。内容涵盖路由与中间件机制、服务容器与依赖注入、接口版本管理、缓存策略设计以及队列异步处理方案。同时结合高并发场景,深入分析性能瓶颈定位与优化思路,帮助开发者构建稳定、高效、易维护的 PHP 后端服务体系。

458

2026.03.04

AI安装教程大全
AI安装教程大全

2026最全AI工具安装教程专题:包含各版本AI绘图、AI视频、智能办公软件的本地化部署手册。全篇零基础友好,附带最新模型下载地址、一键安装脚本及常见报错修复方案。每日更新,收藏这一篇就够了,让AI安装不再报错!

169

2026.03.04

Swift iOS架构设计与MVVM模式实战
Swift iOS架构设计与MVVM模式实战

本专题聚焦 Swift 在 iOS 应用架构设计中的实践,系统讲解 MVVM 模式的核心思想、数据绑定机制、模块拆分策略以及组件化开发方法。内容涵盖网络层封装、状态管理、依赖注入与性能优化技巧。通过完整项目案例,帮助开发者构建结构清晰、可维护性强的 iOS 应用架构体系。

246

2026.03.03

C++高性能网络编程与Reactor模型实践
C++高性能网络编程与Reactor模型实践

本专题围绕 C++ 在高性能网络服务开发中的应用展开,深入讲解 Socket 编程、多路复用机制、Reactor 模型设计原理以及线程池协作策略。内容涵盖 epoll 实现机制、内存管理优化、连接管理策略与高并发场景下的性能调优方法。通过构建高并发网络服务器实战案例,帮助开发者掌握 C++ 在底层系统与网络通信领域的核心技术。

34

2026.03.03

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
最新Python教程 从入门到精通
最新Python教程 从入门到精通

共4课时 | 22.5万人学习

Django 教程
Django 教程

共28课时 | 4.9万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号