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 应该需要包含更多时序信息吧。

相关推荐
wayman_he_何大民17 分钟前
初识机器学习算法 - AUM时间序列分析
前端·人工智能
什么都想学的阿超1 小时前
【大语言模型 00】导读
人工智能·语言模型·自然语言处理
lxmyzzs1 小时前
【图像算法 - 16】庖丁解牛:基于YOLO12与OpenCV的车辆部件级实例分割实战(附完整代码)
人工智能·深度学习·opencv·算法·yolo·计算机视觉·实例分割
明心知1 小时前
DAY 45 Tensorboard使用介绍
人工智能·深度学习
维维180-3121-14552 小时前
AI大模型+Meta分析:助力发表高水平SCI论文
人工智能·meta分析·医学·地学
程序员陆通2 小时前
CloudBase AI ToolKit + VSCode Copilot:打造高效智能云端开发新体验
人工智能·vscode·copilot
程高兴2 小时前
遗传算法求解冷链路径优化问题matlab代码
开发语言·人工智能·matlab
拾零吖2 小时前
吴恩达 Machine Learning(Class 1)
人工智能·机器学习
数据皮皮侠2 小时前
最新上市公司业绩说明会文本数据(2017.02-2025.08)
大数据·数据库·人工智能·笔记·物联网·小程序·区块链
智算菩萨3 小时前
【计算机视觉与深度学习实战】05计算机视觉与深度学习在蚊子检测中的应用综述与假设
人工智能·深度学习·计算机视觉