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

相关推荐
ACP广源盛139246256731 小时前
(ACP广源盛)GSV1175---- MIPI/LVDS 转 Type-C/DisplayPort 1.2 转换器产品说明及功能分享
人工智能·音视频
胡耀超1 小时前
隐私计算技术全景:从联邦学习到可信执行环境的实战指南—数据安全——隐私计算 联邦学习 多方安全计算 可信执行环境 差分隐私
人工智能·安全·数据安全·tee·联邦学习·差分隐私·隐私计算
停停的茶3 小时前
深度学习(目标检测)
人工智能·深度学习·目标检测
Y200309163 小时前
基于 CIFAR10 数据集的卷积神经网络(CNN)模型训练与集成学习
人工智能·cnn·集成学习
老兵发新帖3 小时前
主流神经网络快速应用指南
人工智能·深度学习·神经网络
AI量化投资实验室4 小时前
15年122倍,年化43.58%,回撤才20%,Optuna机器学习多目标调参backtrader,附python代码
人工智能·python·机器学习
java_logo4 小时前
vllm-openai Docker 部署手册
运维·人工智能·docker·ai·容器
倔强青铜三4 小时前
苦练Python第67天:光速读取任意行,linecache模块解锁文件处理新姿势
人工智能·python·面试
算家计算4 小时前
重磅突破!全球首个真实物理环境机器人基准测试正式发布,具身智能迎来 “ImageNet 时刻”
人工智能·资讯
新智元4 小时前
苹果 M5「夜袭」高通英特尔!AI 算力狂飙 400%,Pro 三剑客火速上新
人工智能·openai