返回列表

27th solution, Swin transformer. Simple and Lucky.

473. PetFinder.my - Pawpularity Contest | petfinder-pawpularity-score

开始: 2021-09-23 结束: 2022-01-14 计算机视觉 数据算法赛
第27名方案,Swin Transformer。简单且幸运。

第27名方案,Swin Transformer。简单且幸运。

作者: coolz (Grandmaster) | 比赛排名: 27

恭喜所有的获奖者。

我的方案非常简单,但在这次比赛中这是一个非常幸运的模型。它在 Private LB 上取得了 16.98523 的成绩,在 Public LB 上取得了 17.83676 的成绩。

实际上我在最后几天训练了一个高效的模型,但我太懒了,没有把它和我之前的 Swin Transformer 模型进行融合。

所以我在这分享我的方案。

这是一个输入尺寸为 384 的 Swin Large 模型,使用了 10 折交叉验证(10 folds)进行训练。

我将从 3 个部分介绍我的方案:模型、数据增强和训练策略

1. 模型:

class Net(nn.Module):
    def __init__(self, num_classes= 1):
        super().__init__()

        self.model = timm.create_model('swin_large_patch4_window12_384', pretrained=True)

        self._fc = nn.Sequential(nn.Linear(1536+256 , num_classes, bias=True))

        self.extra_dense=nn.Sequential(nn.Linear(12,256,bias=True),
                                       nn.GELU(),
                                       nn.Linear(256, 256,bias=True),
                                       nn.GELU()
                                       )
    def forward(self, x,extra):

        x = self.model.forward_features(x)
        extra_fm=self.extra_dense(extra)
        fm=torch.cat([x,extra_fm],dim=1)
        x = self._fc(fm)
        return x

2. 数据增强:

self.train_trans=A.Compose([

                                    A.RandomResizedCrop(height=384,
                                                        width=384,
                                                        scale=(0.8, 1.0),
                                                        ratio=(0.9, 1.1),),

                                    A.ShiftScaleRotate(shift_limit=0.1,
                                                       scale_limit=0.1,
                                                       rotate_limit=30,
                                                       p=1.),

                                    A.HorizontalFlip(p=0.5),
                                    A.Normalize()

                              ])

3. 训练策略:

  • 每折(fold)训练 4 个 epoch
  • 优化器:Adamw
  • 初始学习率 (init_lr):0.0001
  • 学习率调度器 (lr_scheduler):余弦退火
  • 无预热
  • 梯度裁剪 (gradient_clip):5
  • 损失函数:BCEWithLogitsLoss
  • 权重衰减因子 (weight_decay_factor):1.e-5
同比赛其他方案