fastbev mmdetection3D 角度和方向损失

角度/方向损失

sin(a−b)=sinacosb−cosasinb

config参数

dir_offset=0.7854, # pi/4

dir_limit_offset=0,

box编解码

# Copyright (c) OpenMMLab. All rights reserved.
import torchfrom mmdet.core.bbox import BaseBBoxCoder
from mmdet.core.bbox.builder import BBOX_CODERSimport ipdb@BBOX_CODERS.register_module()
class DeltaXYZWLHRBBoxCoder(BaseBBoxCoder):"""Bbox Coder for 3D boxes.Args:code_size (int): The dimension of boxes to be encoded."""def __init__(self, code_size=7):super(DeltaXYZWLHRBBoxCoder, self).__init__()self.code_size = code_size@staticmethoddef encode(src_boxes, dst_boxes):"""Get box regression transformation deltas (dx, dy, dz, dw, dh, dl,dr, dv*) that can be used to transform the `src_boxes` into the`target_boxes`.Args:src_boxes (torch.Tensor): source boxes, e.g., object proposals.dst_boxes (torch.Tensor): target of the transformation, e.g.,ground-truth boxes.Returns:torch.Tensor: Box transformation deltas."""box_ndim = src_boxes.shape[-1]cas, cgs, cts = [], [], []if box_ndim > 7:xa, ya, za, wa, la, ha, ra, *cas = torch.split(src_boxes, 1, dim=-1)xg, yg, zg, wg, lg, hg, rg, *cgs = torch.split(dst_boxes, 1, dim=-1)cts = [g - a for g, a in zip(cgs, cas)]else:xa, ya, za, wa, la, ha, ra = torch.split(src_boxes, 1, dim=-1)xg, yg, zg, wg, lg, hg, rg = torch.split(dst_boxes, 1, dim=-1)za = za + ha / 2zg = zg + hg / 2diagonal = torch.sqrt(la**2 + wa**2)xt = (xg - xa) / diagonalyt = (yg - ya) / diagonalzt = (zg - za) / halt = torch.log(lg / la)wt = torch.log(wg / wa)ht = torch.log(hg / ha)rt = rg - rareturn torch.cat([xt, yt, zt, wt, lt, ht, rt, *cts], dim=-1)@staticmethoddef decode(anchors, deltas):"""Apply transformation `deltas` (dx, dy, dz, dw, dh, dl, dr, dv*) to`boxes`.Args:anchors (torch.Tensor): Parameters of anchors with shape (N, 7).deltas (torch.Tensor): Encoded boxes with shape(N, 7+n) [x, y, z, w, l, h, r, velo*].Returns:torch.Tensor: Decoded boxes."""cas, cts = [], []box_ndim = anchors.shape[-1]if box_ndim > 7:xa, ya, za, wa, la, ha, ra, *cas = torch.split(anchors, 1, dim=-1)xt, yt, zt, wt, lt, ht, rt, *cts = torch.split(deltas, 1, dim=-1)else:xa, ya, za, wa, la, ha, ra = torch.split(anchors, 1, dim=-1)xt, yt, zt, wt, lt, ht, rt = torch.split(deltas, 1, dim=-1)za = za + ha / 2diagonal = torch.sqrt(la**2 + wa**2)xg = xt * diagonal + xayg = yt * diagonal + yazg = zt * ha + zalg = torch.exp(lt) * lawg = torch.exp(wt) * wahg = torch.exp(ht) * harg = rt + razg = zg - hg / 2cgs = [t + a for t, a in zip(cts, cas)]return torch.cat([xg, yg, zg, wg, lg, hg, rg, *cgs], dim=-1)

训练-方向分类

mmdet3d/models/dense_heads/free_anchor3d_head.py

2个方向 0,1

self.dir_offset = 0.7854 = pi/4

matched_object_targets是编码后的

            matched_anchors = anchors_[matched] # [38,25,9]matched_object_targets = self.bbox_coder.encode( # [38,25,9]matched_anchors,gt_bboxes_.unsqueeze(dim=1).expand_as(matched_anchors))if self.use_direction_classifier:# also calculate direction prob: P_{ij}^{dir}matched_dir_targets = get_direction_target( # [38,25] dir=0,1  0~2*PImatched_anchors,matched_object_targets,self.dir_offset,one_hot=False)loss_dir = self.loss_dir(                      # [38,25]dir_cls_preds_[matched].transpose(-2, -1), # [38,2,25] F.cross_entropymatched_dir_targets,                       # [38,25]reduction_override='none')
def get_direction_target(anchors,reg_targets,dir_offset=0,num_bins=2,one_hot=True):"""Encode direction to 0 ~ num_bins-1.Args:anchors (torch.Tensor): Concatenated multi-level anchor.reg_targets (torch.Tensor): Bbox regression targets.dir_offset (int): Direction offset.num_bins (int): Number of bins to divide 2*PI.one_hot (bool): Whether to encode as one hot.Returns:torch.Tensor: Encoded direction targets."""rot_gt = reg_targets[..., 6] + anchors[..., 6]offset_rot = limit_period(rot_gt - dir_offset, 0, 2 * np.pi)dir_cls_targets = torch.floor(offset_rot / (2 * np.pi / num_bins)).long()dir_cls_targets = torch.clamp(dir_cls_targets, min=0, max=num_bins - 1)if one_hot:dir_targets = torch.zeros(*list(dir_cls_targets.shape),num_bins,dtype=anchors.dtype,device=dir_cls_targets.device)dir_targets.scatter_(dir_cls_targets.unsqueeze(dim=-1).long(), 1.0)dir_cls_targets = dir_targetsreturn dir_cls_targets
def limit_period(val, offset=0.5, period=np.pi):"""Limit the value into a period for periodic function.Args:val (torch.Tensor): The value to be converted.offset (float, optional): Offset to set the value range. \Defaults to 0.5.period ([type], optional): Period of the value. Defaults to np.pi.Returns:torch.Tensor: Value in the range of \[-offset * period, (1-offset) * period]"""return val - torch.floor(val / period + offset) * period

训练-角度

mmdet3d/models/dense_heads/free_anchor3d_head.py

gt和pre都是编码后的偏移

sin(a−b)=sinacosb−cosasinb

if self.diff_rad_by_sin:bbox_preds_[matched], matched_object_targets = \self.add_sin_difference(bbox_preds_[matched], matched_object_targets)
    def add_sin_difference(boxes1, boxes2):"""Convert the rotation difference to difference in sine function.Args:boxes1 (torch.Tensor): Original Boxes in shape (NxC), where C>=7and the 7th dimension is rotation dimension.boxes2 (torch.Tensor): Target boxes in shape (NxC), where C>=7 andthe 7th dimension is rotation dimension.Returns:tuple[torch.Tensor]: ``boxes1`` and ``boxes2`` whose 7th \dimensions are changed."""rad_pred_encoding = torch.sin(boxes1[..., 6:7]) * torch.cos(boxes2[..., 6:7])rad_tg_encoding = torch.cos(boxes1[..., 6:7]) * torch.sin(boxes2[...,6:7])boxes1 = torch.cat([boxes1[..., :6], rad_pred_encoding, boxes1[..., 7:]], dim=-1)boxes2 = torch.cat([boxes2[..., :6], rad_tg_encoding, boxes2[..., 7:]],dim=-1)return boxes1, boxes2

test

mmdet3d/models/dense_heads/anchor3d_head.py   get_bboxes

self.dir_limit_offset = 0

self.dir_offset = 0.7854   = PI/4

            bboxes = self.bbox_coder.decode(anchors, bbox_pred)dir_rot = limit_period(bboxes[..., 6] - self.dir_offset,self.dir_limit_offset, np.pi)bboxes[..., 6] = (dir_rot + self.dir_offset +np.pi * dir_scores.to(bboxes.dtype))
def limit_period(val, offset=0.5, period=np.pi):"""Limit the value into a period for periodic function.Args:val (torch.Tensor): The value to be converted.offset (float, optional): Offset to set the value range. \Defaults to 0.5.period ([type], optional): Period of the value. Defaults to np.pi.Returns:torch.Tensor: Value in the range of \[-offset * period, (1-offset) * period]"""return val - torch.floor(val / period + offset) * period

gt_bboxes_3d

limit rad to [-pi, pi]

参考

PointPillars论文解析和OpenPCDet代码解析_pointpillars代码解析-CSDN博客

https://github.com/open-mmlab/OpenPCDet/issues/80

MMDetection3D:数据加载简析 - 龙雪 - 博客园

https://zhuanlan.zhihu.com/p/270314921

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/78154.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

极狐GitLab 如何 cherry-pick 变更?

极狐GitLab 是 GitLab 在中国的发行版,关于中文参考文档和资料有: 极狐GitLab 中文文档极狐GitLab 中文论坛极狐GitLab 官网 拣选(cherry-pick)更改 (BASIC ALL) 在 Git 中,cherry-pick 是从一个分支获取一个提交并将其添加为另一个分支的…

java多线程(7.0)

目录 ​编辑 定时器 定时器的使用 三.定时器的实现 MyTimer 3.1 分析思路 1. 创建执行任务的类。 2. 管理任务 3. 执行任务 3.2 线程安全问题 定时器 定时器是软件开发中的一个重要组件. 类似于一个 "闹钟". 达到一个设定的时间之后, 就执行某个指定好的…

优化非线性复杂系统的参数

非线性项组合的系统 对于系统中的每一个复杂拟合,即每一个残差函数,都能表示为非线性方程的趋势,例如较为复杂的系统函数组, from optimtool.base import sp, np x sp.symbols("x1:5") res1 0.5*x[0] 0.2*x[1] 1.…

清华LeapLab开源Cooragent框架:一句话构建本地智能体服务群,让AGI真正触手可及

引言:智能体革命,从复杂到简单 在人工智能发展的浪潮中,Agent(智能体) 技术被视为实现通用人工智能(AGI)的关键路径。然而,传统智能体的开发与协作始终面临两大痛点:依赖…

云原生--核心组件-容器篇-1-Docker和云原生关系(Docker是云原生的基石)

1、基本概念 (1)、云原生(Cloud Native) 是一种构建和运行应用程序的方法论,旨在充分利用云计算环境(公有云、私有云、混合云)的特性,通过容器化、微服务、服务网格、声明式API等技…

问答页面支持拖拽和复制粘贴文件,MaxKB企业级AI助手v1.10.6 LTS版本发布

2025年4月24日,MaxKB开源企业级AI助手正式发布v1.10.6 LTS版本。这一版本主要进行了一些功能优化和问题修复。 功能优化 ■ 应用:文件上传支持上传其他自定义的文件类型,该类型文件需要自行写入函数解析; ■ 问答页面&#xff…

用户案例--慧眼科技

作者:算力魔方创始人/英特尔创新大使刘力 每个行业都有其独特的需求,算力魔方推出了全面的定制化服务,从概念到产品化,满足各行各业,用户可以根据具体应用需求定制更多接口或更强图形处理的需求,且算力魔方…

apple 个人开发者转公司经验

1、在apple开发者官网申请 2、收到邮件后,回复准备了开始迁移 3、收到填写迁移资料的邮件 4、开始填写资料 Sign In - Applehttps://developer.apple.com/enroll/type/edit To complete this change, you will need: 要完成此更改,您需要: L…

【ESP32-IDF笔记】20-配置以太网网络(W5500)

环境配置 Visual Studio Code :版本1.98.2 ESP32:ESP32-S3 ESP-IDF:V5.4 模块:W5500,SPI通讯协议 组件支持:esp_eth 官方的ethernet 以太网组件 W5500介绍 介绍 W5500 是一款全硬件 TCP/IP 嵌入式以太网…

卫星通信的基本概念

1 频段 频段 频率范围 技术特点 典型应用 优势 局限性 最新进展 L 频段 1-2 GHz 波长较长&#xff0c;穿透能力强&#xff0c;受天气影响小&#xff0c;带宽较窄&#xff08;<100 MHz&#xff09;。 卫星导航&#xff08;北斗 / GPS&#xff09;、海事通信&#x…

数据结构------C语言经典题目(7)

1.系统栈和数据结构中的栈有什么区别&#xff1f; 1.本质&#xff1a; 系统栈&#xff1a;由程序运行时由操作系统自动分配的一块连续内存区域&#xff0c;用于存储函数调用过程中的临时数据&#xff08;参数、局部变量、返回地址&#xff09;&#xff0c;是程序运行的底层机制…

【Redis】一、redis的下载与安装

目录 一、redis下载 二、启动服务 三、测试服务 四、可视化界面 五、设置reids密码 今天起准备对redis进行学习&#xff0c;目标是掌握实际开发项目中如何应用redis等操作。首先在这里讲将如何下载redis&#xff0c;方便以后查阅。 一、redis下载 可以去官网&#xff08…

vue3中nextTick的作用及示例

在Vue 3中&#xff0c;nextTick是一个用于处理DOM异步更新的工具函数&#xff0c;确保在数据变化后操作最新的DOM。以下是其作用的详细解析&#xff1a; 核心作用 延迟回调到DOM更新后&#xff1a;Vue的响应式系统会将数据变更批量处理&#xff0c;异步更新DOM。nextTick允许你…

拆解大模型“越狱”攻击:对抗样本如何撕开AI安全护栏?

该文章首发于奇安信攻防社区:https://forum.butian.net/share/4254 引言 随着大规模语言模型(LLMs)在内容生成、智能交互等领域的广泛应用,其安全性和可控性成为学界和产业界关注的焦点。尽管主流模型通过道德对齐机制建立了安全护栏,但研究者发现,通过精心设计的"…

Ubuntu主机上通过WiFi转有线为其他设备提供网络连接

以下是在Ubuntu主机上通过WiFi转有线为Jetson设备提供网络连接的步骤&#xff1a; ​​1. 确认网络接口名称​​ 在Ubuntu主机上执行以下命令&#xff0c;查看WiFi和有线接口名称&#xff1a; ip a WiFi接口通常类似 wlp2s0 或 wlan0有线接口通常类似 enp0s25 或 eth0 记下…

通讯录完善版本(详细讲解+源码)

目录 前言 一、使通讯可以动态更新内存 1、contact.h 2、contact.c 存信息&#xff1a; 删除联系人&#xff0c;并试一个不存在的人的信息&#xff0c;看看会不会把其他人删了 ​编辑 修改&#xff1a; ​编辑 排序&#xff1a; ​编辑 销毁&#xff1a; ​编辑 ​…

Linux操作系统复习

Linux操作系统复习 一. Linux的权限和shell原理1. Linux从广义上讲是什么 从狭义上讲是什么&#xff1f;2. shell是什么&#xff1f;3. 为什么要设置一个shell外壳而不是直接和linux 内核沟通4. shell的原理是什么5. Linux中权限的概念6. 如何提升当前操作的权限7. 文件访问者的…

Spring AI 快速入门:从环境搭建到核心组件集成

Spring AI 快速入门&#xff1a;从环境搭建到核心组件集成 一、前言&#xff1a;Java开发者的AI开发捷径 对于Java生态的开发者来说&#xff0c;将人工智能技术融入企业级应用往往面临技术栈割裂、依赖管理复杂、多模型适配困难等挑战。Spring AI的出现彻底改变了这一局面——…

C++11介绍

目录 一、C11的两个小点 1.1、decltype 1.2、nullptr 二、列表初始化 2.1、C98传统的{} 2.2、C11中的{} 2.3、C11中的std::initializer_list 三、右值引用和移动语义 3.1、左值和右值 3.2、左值引用和右值引用 3.3、引用延长生命周期 3.4、左值和右值的参数匹配 3…

基于机器学习的网络钓鱼邮件智能检测与防护系统

phishingDP 介绍 phishingDP 是一个基于机器学习的网络钓鱼邮件智能检测与防护系统&#xff0c;旨在通过深度学习技术识别潜在的钓鱼邮件&#xff0c;保护用户免受网络诈骗威胁。该系统集成了数据预处理、模型训练、实时预测和结果可视化功能&#xff0c;提供用户友好的Web界…