Muyun99's wiki Muyun99's wiki
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Muyun99

努力成为一个善良的人
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 代码实践-目标检测

  • 代码实践-图像分割

  • 代码实践-自监督学习

  • 竞赛笔记-视觉竞赛

    • 当我们在谈论图像竞赛EDA时在谈论些什么
    • kaggle-Classify Leaves 竞赛方案学习
      • kaggle-Classify Leaves 竞赛方案学习
        • 1、5th 解决方案
        • 2、7th 解决方案
        • 3、8th 解决方案
        • 4、9th 解决方案
        • 5、11th 解决方案
        • 6、12th 解决方案
        • 7、13th 解决方案
        • 8、19th 解决方案
        • 9、参考资料
    • 图像检索orReID 竞赛的 Tricks
    • kaggle-CowBoy Outfits Detection 竞赛方案学习
    • kaggle 图像分割竞赛学习
    • few-shot learning 竞赛学习
    • few-shot learning 竞赛学习-2
    • 遥感图像建筑物变化检测竞赛学习-1
  • 框架解析-mmlab系列

  • 讲座记录-有意思的文章集合

  • 体会感悟-产品沉思录观后有感

  • 体会感悟-摄影

  • 系列笔记-

  • 系列笔记-乐理和五线谱

  • 系列笔记-爬虫实践

  • 系列笔记-Django学习笔记

  • 系列笔记-Git 使用笔记

  • 系列笔记-网站搭建

  • 系列笔记-图卷积网络

  • 课程笔记-MIT-NULL

  • 系列笔记-OpenCV-Python

  • 系列笔记-使用 Beancount 记账

  • 系列笔记-Python设计模式

  • 系列笔记-MLOps

  • 系列笔记-Apollo自动驾驶

  • 系列笔记-PaddlePaddle

  • 系列笔记-视频操作

  • Vue+Django前后端分离开发

  • 深度学习及机器学习理论知识学习笔记

  • PyTorch Tricks

  • 学习笔记
  • 竞赛笔记-视觉竞赛
Muyun99
2021-06-28

kaggle-Classify Leaves 竞赛方案学习

# kaggle-Classify Leaves 竞赛方案学习

# 1、5th 解决方案 (opens new window)

模型:
	seresnext50和resnet50
数据增强:
	resize 320, HorizontalFlip, VerticalFlip, Rotate, RandomBrightnesContrasr, ShiftScaleRotate, Normalize
其他:
	优化器:AdamW 
	学习率调整器:CosineAnnealingLR
	损失函数:CrossEntropy
	5折交叉验证, 最终结果为五折准确率最高平均, 两个网络各自平均后再做平均。
1
2
3
4
5
6
7
8
9

# 2、7th 解决方案 (opens new window)

模型:
	ResNeSt50 + ResNeXt50_32x4d + DenseNet161
数据增强:
	train_transform = transforms.Compose([
    # 随机裁剪图像,所得图像为原始面积的0.08到1之间,高宽比在3/4和4/3之间。
    # 然后,缩放图像以创建224 x 224的新图像
    transforms.RandomResizedCrop(224, scale=(0.08, 1.0), ratio=(3.0 / 4.0, 4.0 / 3.0)),
    transforms.RandomHorizontalFlip(), 
    # 随机更改亮度,对比度和饱和度
    transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4),
    transforms.ToTensor(),   
    # 标准化图像的每个通道
    transforms.Normalize([0.485, 0.456, 0.406],[0.229, 0.224, 0.225])])
	
	训练时的 CutMix 以及 预测时的 TTA
	CutMix: https://github.com/ildoonet/cutmix
	TTA: https://github.com/qubvel/ttach
其他:
	总共训了 30 个 epoch
	优化器:使用 AdamW,torch.optim.AdamW(model.parameters(),lr=1e-4,weight_decay= 1e-3)
	学习率调整:CosineAnnealingLR: CosineAnnealingLR(optimizer,T_max=10)
	交叉验证:使用 5 折交叉验证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 3、8th 解决方案 (opens new window)


# Using an LR ramp up because fine-tuning a pre-trained model.
# Starting with a high LR would break the pre-trained weights.
# 提到一开始使用大的 LR 会破坏原有的预训练权重

1
2
3
4
5

# 4、9th 解决方案 (opens new window)

模型:
    0, resnet50d, input_size: 224 (selected)
    1, efficientnet_b3, input_size: 224 (selected)
    2, resnext50_32x4d, input_size: 224
    3, inception_resnet_v2, input_size: 299 (selected)
    4, vit_base_patch16_224, input_size: 224 (selected)
    5, tf_efficientnet_b3_ns, input_size: 224
    6, tf_efficientnet_b4_ns, input_size: 380 (selected)
    7, resnest200e, input_size 320 (selected)
    8, mixnet_s, input_size 224
    9, mixnet_xl, input_size 224 (selected)
    10, resnest50d, input_size 224
数据增强:
	transforms.Compose([
        transforms.ToTensor(),
        transforms.RandomHorizontalFlip(p=0.5),
        transforms.RandomVerticalFlip(p=0.5),
        transforms.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0),
        transforms.RandomResizedCrop([CFG.size, CFG.size]),
        transforms.Normalize(
            mean=[0.5, 0.5, 0.5],
            std=[0.5, 0.5, 0.5],
        )
其他:
	总共训了 50 个epoch
	batch_size = 32
	criterion = CrossEntropyLoss()
	optimizer = MADGRAD 
    learning_rate = 1e-4
    weight_decay = 1e-9
    scheduler = 'ReduceLROnPlateau' 
    factor = 0.2 # ReduceLROnPlateau
    patience = 4 # ReduceLROnPlateau
    eps = 1e-6   # ReduceLROnPlateau
    交叉验证:5 折交叉验证
    模型选择:Stacked mean combinations & Weighted average(值得学习)
    
    probs_3D = np.zeros([train.shape[0],num_class,num_models])
    Weighted average 用来检验模型的重要性以及验证stacked mean method足够优秀
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

# 5、11th 解决方案 (opens new window)

自建的比赛tricks库:https://github.com/seefun/TorchUtils
Baseline:https://github.com/seefun/TorchUtils/blob/master/examples/kaggle_leaves_classification.ipynb



模型:

数据增强:
	train_transform = albumentations.Compose([
    albumentations.RandomRotate90(p=0.5),
    albumentations.Transpose(p=0.5),
    albumentations.Flip(p=0.5),
    albumentations.ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.0625, rotate_limit=45, border_mode=1, p=0.5),
    tu.randAugment(),
    albumentations.Normalize(),
    # 这里要使用 ToTensorV2()
    AT.ToTensorV2(),
    ])
其他:
	使用混合精度训练,节省时间,甚至能因为大batch而提升性能
	scaler = torch.cuda.amp.GradScaler() # for AMP training
	scaler.scale(loss).backward()
	scaler.step(optimizer)
    scaler.update()
	使用imagenet-21k上预训练的efficientnetv2模型:https://arxiv.org/abs/2104.00298
	mutli-dropout
	LR = 3e-4
	EPOCH = 36
	DECAY_SCALE = 20.0
	pooling时concat maxpooling与avgpooling
	mixup / Label Smoothing作为正则
	余弦学习率下降
	使用Ranger(RAdam+Lookahead+GC)/ RangerLars(Ranger+Lars)优化
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

总结:

  1. 比赛数据集存在大量leak,训练测试集大量图片重复或接近,过拟合反而能获得更好结果;
  2. 数据集存在很多噪声样本,过拟合这些错误标注反而能获得更高的LB;即LB本身并不可靠,更高的LB不代表真正更高的泛化性能;

# 6、12th 解决方案 (opens new window)

在 11th 的解决方案上进行微调

1、加入mixup,设为0.1(太大会使模型性能下降),使用
2、epoch 加大到 72
3、在 randAugment 中加入cutout
4、加入LabelSmoothing: tu.LabelSmoothingCrossEntropy()
- https://github.com/seefun/TorchUtils/blob/master/torch_utils/criterion/CrossEntropy.py
1
2
3
4
5
6
7

# 7、13th 解决方案 (opens new window)

模型:
	一个seresnext50,两个resnext50
数据增强:
	Resize 224            
    transforms.RandomHorizontalFlip(p=0.5),   #随机水平翻转
    transforms.RandomVerticalFlip(p=0.5),     #除了水平竖直反转之外其他的处理方法貌似都会降低acc       transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
其他:
	lr_scheduler:ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=3, verbose=True, min_lr=0.0000001)
	在训练过程中使用 cutmix
	验证和测试的时候使用TTA: tta.ClassificationTTAWrapper(model_1, tta.aliases.flip_transform(),  merge_mode='mean')
1
2
3
4
5
6
7
8
9
10
11

# 8、19th 解决方案 (opens new window)

模型:
	resnest50d
其他:
	三折交叉验证
1
2
3
4

# 9、参考资料

  • Guide-to-ensembling-methods (opens new window)

  • Guide to Pytorch Learning Rate Scheduling (opens new window)

  • Mixup, Cutmix, FMix Visualisations (opens new window)

上次更新: 2021/08/02, 21:04:52
当我们在谈论图像竞赛EDA时在谈论些什么
图像检索orReID 竞赛的 Tricks

← 当我们在谈论图像竞赛EDA时在谈论些什么 图像检索orReID 竞赛的 Tricks→

最近更新
01
Structured Knowledge Distillation for Semantic Segmentation
06-03
02
README 美化
05-20
03
常见 Tricks 代码片段
05-12
更多文章>
Theme by Vdoing | Copyright © 2021-2023 Muyun99 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×