DD3D中估计目标速度和属性

如果你喜欢我的内容,别忘了一键三连(点赞、评论、分享)和关注哦!

整体思路

在DD3D 中我们经过head 头后,会拿到fcos2d_extra_output 特征。

py 复制代码
logits, box2d_reg, centerness, fcos2d_extra_output = self.fcos2d_head(features)

之后将fcos2d_extra_output 送入

  • 【计算attr_logits】送入一个标准的卷积层,将输入特征图转换为 max_num_attributes 个通道。核大小为 3x3,步幅为 1,填充为 1。
  • 【计算speed】送入另一个卷积层,将输入特征图转换为一个单通道输出。核大小为 3x3,步幅为 1,填充为 1。然后通过 F.relu 应用 ReLU 激活函数。

然后可以得到self.attr_logitsself.speed

py 复制代码
def forward(self, x):
    attr_logits_output = self.attr_logits(x)
    speed_output = F.relu(self.speed(x))
    return attr_logits_output, speed_output

这样定义的模型在进行前向传播时会计算两个输出:一个是 attr_logits_output,表示属性预测;另一个是 speed_output,表示速度预测并应用了 ReLU 激活函数。

示例展示

完整地展示如何实现这个操作:

我们模拟输入 fcos2d_extra_output :

py 复制代码
fcos2d_extra_output = {
    'cls_tower_out': [torch.randn(1, in_channels, 32, 32) for _ in range(4)]
}
py 复制代码
import torch
import torch.nn as nn
import torch.nn.functional as F

class MyModel(nn.Module):
    def __init__(self, in_channels, max_num_attributes):
        super(MyModel, self).__init__()
        self.attr_logits = nn.Conv2d(in_channels, max_num_attributes, kernel_size=3, stride=1, padding=1, bias=True)
        self.speed = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1, bias=True)

    def forward(self, fcos2d_extra_output):
        attr_logits = []
        speeds = []
        for x in fcos2d_extra_output['cls_tower_out']:
            attr_logits.append(self.attr_logits(x))
            speeds.append(F.relu(self.speed(x)))
        
        # Convert lists to tensors
        attr_logits = torch.stack(attr_logits)
        
        # Flatten and concatenate speed outputs
        speeds = torch.cat([x.permute(0, 2, 3, 1).reshape(-1) for x in speeds])
        
        return attr_logits, speeds

# Example usage
in_channels = 3
max_num_attributes = 10
model = MyModel(in_channels, max_num_attributes)

# Simulating fcos2d_extra_output with a list of random tensors
fcos2d_extra_output = {
    'cls_tower_out': [torch.randn(1, in_channels, 32, 32) for _ in range(4)]
}

attr_logits_output, speed_output = model(fcos2d_extra_output)

print("attr_logits_output shape:", attr_logits_output.shape)
print("speed_output shape:", speed_output.shape)
py 复制代码
attr_logits_output shape: torch.Size([4, 1, 10, 32, 32])
speed_output shape: torch.Size([4096])

模型定义:

定义了两个卷积层 attr_logits 和 speed。

前向传播:

  • 遍历 fcos2d_extra_output['cls_tower_out'],对每个张量 x 应用卷积层并将结果存储在 attr_logits 和 speeds 列表中。
  • 使用 torch.stack 将 attr_logits 列表转换为张量。
  • 使用 torch.cat 将 speeds 列表中的每个张量展平并连接成一个大的扁平化张量。

使用示例:

  • 创建了一个模拟的 fcos2d_extra_output,其中包含 4 个随机张量。
  • 通过模型的前向传播方法计算 attr_logits_output 和 speed_output。

输出形状:

  • attr_logits_output 的形状为 (4, max_num_attributes, 32, 32)。
  • speed_output 的形状为 (N,),其中 N 是所有速度张量展平后连接的总长度。

(正文完)

虽然不清楚这样的效果怎么样,但是也能有一定的预测作用。如果想效果好,fcos2d_extra_output 应该需要包含更多时序信息吧。

相关推荐
一点.点1 分钟前
简单分析自动驾驶发展现状与挑战
人工智能·自动驾驶
山重水复疑无路@2 分钟前
NVIDIA --- 端到端自动驾驶
人工智能·机器学习·自动驾驶
落樱弥城12 分钟前
光流法:从传统方法到深度学习方法
人工智能·深度学习
乙真仙人22 分钟前
从困局到破局的AI+数据分析
人工智能·数据挖掘·数据分析
量子位26 分钟前
阿里 Qwen3 问鼎开源王座!8 款模型全面开放,最大杯全方位超越 R1/o1,网友:让开源再次伟大
人工智能·开源·通义灵码
量子位26 分钟前
普通人也能用上超级智能体!实测 100+MCP 工具随便选,撰写报告 / 爬虫小红书效果惊艳
人工智能·mcp
酱酱们的每日掘金26 分钟前
用了 Trae 后,感觉离京东外卖不远了、Cursor 的系统级提示词逆向、前端也需要了解的 mcp 知识-AI Coding 周刊第 6 期
人工智能·ai编程·trae
机器之心28 分钟前
ChatGPT的尽头也是「带货」:3、2、1,上链接
人工智能
量子位31 分钟前
14.9 万元,满血流畅运行 DeepSeek 一体机抱回家!清华 90 后初创出品
人工智能·deepseek
mozun202033 分钟前
大学之大:韩国科学技术研究院2025.4.28
人工智能·科技·教育·高校·韩国名校·韩国科学技术研究院