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

相关推荐
CV-King25 分钟前
opencv实战项目(三十):使用傅里叶变换进行图像边缘检测
人工智能·opencv·算法·计算机视觉
禁默28 分钟前
2024年计算机视觉与艺术研讨会(CVA 2024)
人工智能·计算机视觉
slomay1 小时前
关于对比学习(简单整理
经验分享·深度学习·学习·机器学习
whaosoft-1431 小时前
大模型~合集3
人工智能
Dream-Y.ocean2 小时前
文心智能体平台AgenBuilder | 搭建智能体:情感顾问叶晴
人工智能·智能体
丶21362 小时前
【CUDA】【PyTorch】安装 PyTorch 与 CUDA 11.7 的详细步骤
人工智能·pytorch·python
春末的南方城市2 小时前
FLUX的ID保持项目也来了! 字节开源PuLID-FLUX-v0.9.0,开启一致性风格写真新纪元!
人工智能·计算机视觉·stable diffusion·aigc·图像生成
zmjia1112 小时前
AI大语言模型进阶应用及模型优化、本地化部署、从0-1搭建、智能体构建技术
人工智能·语言模型·自然语言处理
jndingxin2 小时前
OpenCV视频I/O(14)创建和写入视频文件的类:VideoWriter介绍
人工智能·opencv·音视频
AI完全体3 小时前
【AI知识点】偏差-方差权衡(Bias-Variance Tradeoff)
人工智能·深度学习·神经网络·机器学习·过拟合·模型复杂度·偏差-方差