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 小时前
【机器学习】吴恩达机器学习笔记
人工智能·笔记·机器学习
却道天凉_好个秋1 小时前
深度学习(二):神经元与神经网络
人工智能·神经网络·计算机视觉·神经元
UQI-LIUWJ1 小时前
unsloth笔记:运行&微调 gemma
人工智能·笔记·深度学习
THMAIL2 小时前
深度学习从入门到精通 - 生成对抗网络(GAN)实战:创造逼真图像的魔法艺术
人工智能·python·深度学习·神经网络·机器学习·生成对抗网络·cnn
却道天凉_好个秋2 小时前
计算机视觉(八):开运算和闭运算
人工智能·计算机视觉·开运算与闭运算
无风听海2 小时前
神经网络之深入理解偏置
人工智能·神经网络·机器学习·偏置
JoinApper2 小时前
目标检测系列-Yolov5下载及运行
人工智能·yolo·目标检测
北京地铁1号线2 小时前
GPT(Generative Pre-trained Transformer)模型架构与损失函数介绍
gpt·深度学习·transformer
飞哥数智坊2 小时前
即梦4.0实测:我真想对PS说“拜拜”了!
人工智能
fantasy_arch2 小时前
9.3深度循环神经网络
人工智能·rnn·深度学习