1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| import torch import torch.nn as nn
class DriverGaze360Net(nn.Module): """ DriverGaze360-Net: 全景驾驶员注意力预测网络 CVPR 2026 核心创新: 1. 全景图像输入(360°视野) 2. 注意力图+语义分割联合学习 3. 对象级引导提升空间感知 """ def __init__(self, num_classes_seg=20): super().__init__() self.encoder = SwinTransformerEncoder( img_size=(512, 1024), patch_size=4, embed_dim=128, depths=[2, 2, 18, 2], num_heads=[4, 8, 16, 32] ) self.attention_decoder = AttentionDecoder( in_channels=128, mid_channels=64, out_channels=1 ) self.segmentation_head = SegmentationHead( in_channels=128, num_classes=num_classes_seg ) def forward(self, panoramic_image): """ Args: panoramic_image: 全景图像 (B, 3, 512, 1024) Returns: attention_map: 驾驶员注意力图 (B, 1, H, W) seg_map: 语义分割图 (B, C, H, W) - 辅助任务 """ features = self.encoder(panoramic_image) attention_map = self.attention_decoder(features) seg_map = self.segmentation_head(features) return attention_map, seg_map
class AttentionDecoder(nn.Module): """多尺度注意力图解码器""" def __init__(self, in_channels, mid_channels, out_channels): super().__init__() self.layers = nn.Sequential( nn.Conv2d(in_channels, mid_channels, 3, 1, 1), nn.BatchNorm2d(mid_channels), nn.ReLU(), nn.Conv2d(mid_channels, mid_channels, 3, 1, 1), nn.BatchNorm2d(mid_channels), nn.ReLU(), nn.Conv2d(mid_channels, out_channels, 1), nn.Sigmoid() ) def forward(self, x): return self.layers(x)
class SegmentationHead(nn.Module): """语义分割辅助头""" def __init__(self, in_channels, num_classes): super().__init__() self.head = nn.Sequential( nn.Conv2d(in_channels, 64, 3, 1, 1), nn.ReLU(), nn.Conv2d(64, num_classes, 1) ) def forward(self, x): return self.head(x)
|