当前位置: 首页 > article >正文

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

相关文章:

fastbev mmdetection3D 角度和方向损失

角度/方向损失 sin(a−b)sinacosb−cosasinb config参数 dir_offset0.7854, # pi/4 dir_limit_offset0, box编解码 # Copyright (c) OpenMMLab. All rights reserved. import torchfrom mmdet.core.bbox import BaseBBoxCoder from mmdet.core.bbox.builder import BBOX_COD…...

力扣-hot100(滑动窗口最大值)

239. 滑动窗口最大值 困难 给你一个整数数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。 返回 滑动窗口中的最大值 。 示例 1: 输入:nums […...

一种专用车辆智能配电模块的设计解析:技术革新与未来展望

关键词:智能配电模块、STM32、CAN总线、电子开关、新能源汽车 引言:传统配电系统的痛点与智能化转型 传统配电系统依赖继电器和保险丝,存在体积大、寿命短、智能化低等缺陷(如图1)。而新能源汽车和无人驾驶技术对配电…...

《深入浅出ProtoBuf:从环境搭建到高效数据序列化》​

ProtoBuf详解 1、初识ProtoBuf2、安装ProtoBuf2.1、ProtoBuf在Windows下的安装2.2、ProtoBuf在Linux下的安装 3、快速上手——通讯录V1.03.1、步骤1:创建.proto文件3.2、步骤2:编译contacts.proto文件,生成C文件3.3、步骤3:序列化…...

Java实现加密(七)国密SM2算法的签名和验签(附商用密码检测相关国家标准/国密标准下载)

目录 一、国密标准中,关于SM2签名验签的定义二、SM2签名和验签的实现原理1. 前置知识2. 签名生成过程3. 验签过程4. 数学正确性证明5. 安全性与注意事项 三、带userId、不带userId的区别1. 核心区别2.算法区别(1) 哈希计算过程(2) 签名验签流程 四、Java代码实现1. …...

【华为HCIP | 华为数通工程师】821—多选解析—第十七页

多选835、IS-IS协议所使用的NSAP地址主要由哪几个部分构成? A、AREA ID B、SEL C、DSCp D、SYSTEM ID 解析:NSAP地址:网络服务访问点(Network Service Access Point)是 OSI 协议中用于定位资源的地址。NSAP 的地址结构如图所示,它由 IDP(Initial Domain …...

函数的定义与使用(python)

lst[:]是传入lst的拷贝。改变它对原始lst没有任何影响。 *list一个*的元素在函数体内会被当成一个元组。 以下是对图中 Python 代码的详细解释: 代码总体功能 这段代码定义了一个生成器函数 getItem ,用于依次返回多个列表中的元素。然后通过循环遍历…...

List findIntersection getUnion

List findIntersection & getUnion 求两个列表的交集和并集 package zwf;import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List;/*** 列表工具类* * author ZengWenFeng* date 2025.04.22* mobile 13805029595* email 117791303qq.com*/ p…...

乒乓操作(Ping-Pong)

乒乓操作 “ 乒乓操作” 是一个常常应用于数据流控制的设计思想, 典型的乒乓操作方法如下图 所示: ​ T1周期,输入数据流1缓存到数据缓冲模块1中,如上图棕色;T2周期,输入数据流2缓存到数据缓冲模块2中&…...

微信小程序文章管理系统开发实现

概述 在内容为王的互联网时代,高效的文章管理系统成为各类平台的刚需。幽络源平台今日分享一款基于SSM框架开发的微信小程序文章管理系统完整解决方案,该系统实现了多角色内容管理、智能分类、互动交流等功能。 主要内容 一、用户端功能模块 ​​多角…...

GrassRouter 小草MULE多5G多链路聚合通信路由设备在应急场景的聚合效率测试报告及解决方案

在应急通信场景中,快速、稳定、高效的通信链路是保障救援工作顺利开展的关键。MULE(Multi-Link Unified Link Enhancement)多链路聚合路由通信设备作为一种新型的通信技术解决方案,通过聚合多条通信链路(如4G/5G、卫星…...

筑牢数字防线:商城系统安全的多维守护策略

一、构建网络安全防护屏障​ 网络安全是商城系统安全的第一道防线。企业应采用先进的防火墙技术,实时监控和过滤进出网络的流量,阻止非法访问和恶意攻击。入侵检测与防御系统(IDS/IPS)也是不可或缺的安全组件,它能够及…...

Linux阻塞与非阻塞I/O:从原理到实践详解

Linux阻塞与非阻塞I/O:从原理到实践详解 1. 阻塞与非阻塞I/O基础概念 1.1 阻塞与非阻塞简介 在Linux系统编程中,I/O操作可以分为两种基本模式:阻塞I/O和非阻塞I/O。这两种模式决定了当设备或资源不可用时,程序的行为方式。 阻…...

【MySQL】MySQL索引与事务

目录 前言 1. 索引 (index) 1.1 概念 1.2 作用 1.3 使用场景 1.4 索引的相关操作 查看索引 创建索引 删除索引 2. 索引背后的数据结构 2.1 B树 2.2 B+树的特点 2.3 B+树的优势 3. 事务 3.1 为什么使用事务 3.2 事…...

华为网路设备学习-19 IGP路由专题-路由策略

一、 二、 注意: 当该节点匹配模式为permit下时,参考if else 当该节点匹配模式为deny下时: 1、该节点中的apply子语句不会执行。 2、如果满足所有判断(if-match)条件时,拒绝该节点并跳出(即不…...

力扣-234.回文链表

题目描述 给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false 。 class Solution { public:bool isPalindrome(ListNode* head) {//快慢指针找到中间结点p1(偶数个结点…...

Spring Boot 整合 Lock4j + Redisson 实现分布式锁实战

本文基于 Spring Boot 2.7.x MyBatis Plus 3.5.9&#xff0c;演示如何通过 Lock4j 与 Redisson 实现高可靠的分布式锁方案&#xff0c;解决高并发场景下的资源竞争问题。 一、依赖配置关键点 1.1 Maven 依赖&#xff08;pom.xml&#xff09; <dependency><groupId&g…...

基于DrissionPage的表情包爬虫实现与解析(含源码)

目录 ​编辑 一、环境配置与技术选型 1.1 环境要求 1.2 DrissionPage优势 二、爬虫实现代码 三、代码解析 3.1 类结构设计 3.2 目录创建方法 3.3 图片链接获取 3.4 图片下载方法 四、技术升级对比 4.1 代码复杂度对比 4.2 性能测试数据 五、扩展优化建议 5.1 并…...

无限debugger实现原理

1. 直接调用 debugger 关键字 代码示例&#xff1a; debugger; // 手动触发调试器中断特点&#xff1a; 最简单的方式&#xff0c;直接插入 debugger 语句。若未在浏览器开发者工具中禁用断点&#xff0c;每次执行到此代码都会暂停。反制手段&#xff1a;可通过浏览器开发者…...

区间和数量统计 之 前缀和+哈希表

文章目录 1512.好数对的数目2845.统计趣味子数组的数目1371.每个元音包含偶数次的最长子字符串 区间和的数量统计是一类十分典型的问题&#xff1a;记录左边&#xff0c;枚举右边策略前置题目&#xff1a;统计nums[j]nums[i]的对数进阶版本&#xff1a;统计子数组和%modulo k的…...

全能 Sui 技术栈,构建 Web3 的未来

本文翻译自&#xff1a;FourPillarsFP&#xff0c;文章仅代表作者观点。 2025 年&#xff0c;SuiNetwork正在以一套全栈区块链策略强势出击&#xff0c;彻底打破加密行业的传统范式。正如 Mysten Labs 联合创始人 Adeniyi Abiodun 所说&#xff1a;“Sui 不只是一条区块链&…...

什么是爬虫?——从技术原理到现实应用的全面解析 V

什么是爬虫?——从技术原理到现实应用的全面解析 V 二十一、云原生爬虫架构设计 21.1 无服务器爬虫(AWS Lambda) # lambda_function.py import boto3 import requests from bs4 import BeautifulSoups3 = boto3.client(s3)def lambda_handler(event, context):# 抓取目标…...

(三) Trae 调试C++ 基本概念

调试C基本概念 一、调试基础概念1.1 调试信息格式1.2 DWARF格式和PDB格式生成(图解)1.3.典型工具链和调试信息 二、各工具链深度解析1. Clang 与 G 的 DWARF 差异 三 调试工具3.1 调试工具3.2 调试插件(Trae) 一、调试基础概念 1.1 调试信息格式 格式类型适用系统存在形式DWA…...

linux安装单节点Elasticsearch(es),安装可视化工具kibana

真的&#xff0c;我安装个es和kibana&#xff0c;找了好多帖子&#xff0c;问了好几遍ai才安装成功&#xff0c;在这里记录一下&#xff0c;我相信&#xff0c;跟着我的步骤走&#xff0c;99%会成功&#xff1b; 为了让大家直观的看到安装过程&#xff0c;我把我服务器的es和ki…...

Python项目--基于计算机视觉的手势识别控制系统

1. 项目概述 1.1 项目背景 随着人机交互技术的快速发展&#xff0c;传统的键盘、鼠标等输入设备已经不能满足人们对自然、直观交互的需求。手势识别作为一种非接触式的人机交互方式&#xff0c;具有操作自然、交互直观的特点&#xff0c;在智能家居、游戏控制、虚拟现实等领域…...

上海SMT贴片加工核心工艺与优化方案

内容概要 作为电子制造领域的核心环节&#xff0c;上海SMT贴片加工技术通过精密工艺实现元器件的高效贴装与可靠焊接。本文聚焦钢网印刷、回流焊、AOI检测等关键工艺节点&#xff0c;结合物料定位误差修正与BGA缺陷预防&#xff0c;系统阐述技术优化路径。同时&#xff0c;基于…...

RK3xxx 部分无法连接虚拟机 无法进行adb连接

我发现部分rk板子可以连接到虚拟机上&#xff0c;部分连接不上。其中尝试了一块是安卓系统的rk板子是可以连接虚拟机。但是用了linux系统的rk板子连接不上虚拟机。尝试了很多办法还是无法连接虚拟机。 然后也看到一些相关资料&#xff0c;但是太少了&#xff0c;只有这个链接提…...

Kohya-ss-gui v25.0.3 训练Flux.1 大模型命令参数

Kohya-ss-gui v25.0.3 训练Flux.1 大模型命令参数 本文是博主的训练笔记&#xff0c;这篇是记录训练Flux.1大模型的命令行参数&#xff1a; 数据结构 /app/data/Flux大模型/train/img . └── 10_skm qili├── 10x4096_4096x4096_flux.npz├── 10x4096.jpg├── 10x4096…...

26考研——存储系统(3)

408答疑 文章目录 一、存储器概述二、主存储器三、主存储器与 CPU 的连接四、外部存储器五、高速缓冲存储器六、虚拟存储器七、参考资料鲍鱼科技课件26王道考研书 八、总结复习提示思考题常见问题和易混淆知识点 一、存储器概述 文章链接: 点击跳转 二、主存储器 文章链接: …...

【prompt是什么?有哪些技巧?】

Prompt&#xff08;提示词&#xff09;是什么&#xff1f; Prompt 是用户输入给AI模型&#xff08;如ChatGPT、GPT-4等&#xff09;的指令或问题&#xff0c;用于引导模型生成符合预期的回答。它的质量直接影响AI的输出效果。 Prompt 的核心技巧 1. 明确目标&#xff08;Clar…...