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.pswp.cn/pingmian/78154.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/78154.shtml
英文地址,請注明出處:http://en.pswp.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界…