Skip to content

[Seg] Day2_0427

nureesong edited this page Apr 27, 2021 · 3 revisions

ํ”ผ์–ด์„ธ์…˜ ์š”์•ฝ

  • ํด๋ž˜์Šค ๋ถˆ๊ท ํ˜• + ์ผ๋ฐ˜ํ™” ๊ณ ๋ฏผํ•ฉ์‹œ๋‹ค!!
    ๋ถ€์กฑํ•œ ํด๋ž˜์Šค ๋ณด์ถฉ (ํŠนํžˆ ๋ฐฐํ„ฐ๋ฆฌ)
    CutMix : ์–ด์ฐจํ”ผ ํ”ฝ์…€ ๋‹จ์œ„ ์˜ˆ์ธก์ธ๋ฐ ์ปท๋ฏน์Šค๊ฐ€ ํšจ๊ณผ๊ฐ€ ์žˆ์„์ง€ ๋ฏธ์ง€์ˆ˜.
    ์ปท๋ฏน์Šค ์ ์šฉํ–ˆ๋Š”๋ฐ ๊ฐ์ฒด ์œ„์— ๋ถ™์–ด๋ฒ„๋ฆฌ๋ฉด ์–ด๋–กํ•˜์ฃ ??

  • ํด๋ž˜์Šค๋ณ„๋กœ ์Šค์ฝ”์–ด ์ธก์ • (utils.py ์•ฝ๊ฐ„ ์ˆ˜์ •)
    ํŠน์ • ํด๋ž˜์Šค๋ฅผ ์œ ๋… ๋งŽ์ด ํ‹€๋ฆฌ๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž. ํŠนํžˆ, UNKNOWN์ด๋‚˜ ๋ฐฐํ„ฐ๋ฆฌ!!

  • Label smoothing

  • ์บ๊ธ€ ์†”๋ฃจ์…˜ ์ฐธ๊ณ : ๋‹ค์–‘ํ•œ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋กœ ์•™์ƒ๋ธ”

  • Loss function ์„ž์–ด๋ณด๊ธฐ!!
    ์„ฑ๋Šฅ ์ž˜ ๋‚˜์˜ค๋Š” ์ˆœ์„œ: CrossEntropy > Dice Loss > Focal Loss (ํ˜„์žฌ๊นŒ์ง€๋Š” ๊ทธ๋Ÿฌํ•จ)

  • Optimizer
    SOTA ๋…ผ๋ฌธ์€ ๊ฑฐ์˜ sgd๋กœ 2000 ์—ํญ ๋Œ๋ฆฐ๋‹ค. ASGNet๋„ sgd.
    ๋ฌด๋‚œํ•˜๊ฒŒ ํ•  ๋•Œ๋Š” Adam, CosineAnnealing(WarmRestarts)

  • ๋ชจ๋ธ ์•„ํ‚คํ…์ณ
    ํ˜„์žฌ๊นŒ์ง€ ์‹คํ—˜์— ์˜ํ•˜๋ฉด DeepLabV3 & Plus, EMANet ์„ฑ๋Šฅ ์ข‹์Œ

  • ์ตœ์ ์˜ augmentation ์กฐํ•ฉ ์ฐพ๊ธฐ (๋ชจ๋ธ ๋จผ์ € ์ •ํ•˜๊ณ  ๋‚˜์„œ)
    โ‡’ ์ตœ๋Œ€ํ•œ ๋งŽ์€ transform์„ ๋„ฃ๊ณ  ํ•˜๋‚˜์”ฉ ๋นผ๋ณด๋ฉด์„œ
    ์‹คํ—˜์— ํฐ ์˜ํ–ฅ์„ ๋ผ์น˜๋Š” ์š”์†Œ๋ฅผ ํŒŒ์•…ํ•œ๋‹ค.
    https://github.com/JeongMyeong/lotte-visionAI-competition/

  • k-fold cv (ํ•™์Šต ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋‹ˆ ๋งˆ์ง€๋ง‰์—)
    ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ํ• ์ง€? ํด๋ž˜์Šค ๋ถˆ๊ท ํ˜• ๊ณ ๋ คํ•ด์„œ ๋‚˜๋ˆŒ์ง€?


[์‹คํ—˜ ๋‚ด์šฉ ๋ฐ ๊ฒฐ๊ณผ ๊ณต์œ ]

์ค€์ฒ ๋‹˜

  • EMANet. input_size = 256 & focal loss ์‹คํ—˜ ์ค‘

  • ํŠธ๋žœ์Šคํฌ๋จธ ๊ณ„์—ด
    ๋ฐ์ดํ„ฐ๊ฐ€ ๋งŽ์„ ๋•Œ ์œ ๋ฆฌ โ†’ 1์—ํญ์— ๋ฐ”๋กœ ํ•™์Šต ๋กœ์Šค ๋‚ฎ๊ฒŒ ๋‚˜์˜ด. lr ์ค„์—ฌ์„œ ํ•ด๋ณด๊ธฐ
    context ๊ฐ•์ . ๋ฐฐ๊ฒฝ ๋ถ€๋ถ„์„ ๋งค๋„๋Ÿฝ๊ฒŒ ์ž˜ ์˜ˆ์ธกํ•˜๋Š” ํŽธ. ex) ๋ฐฐ๊ฒฝ์ด ๋ฐ•์Šค โ†’ ์ข…์ด๋กœ ๋ผ๋ฒจ๋ง
    ๋‹จ์ : ํŒŒ๋ผ๋ฏธํ„ฐ ๋„ˆ๋ฌด ๋งŽ์•„์„œ ์˜ค๋ž˜ ๊ฑธ๋ฆผ.

  • ๋ฐ์ดํ„ฐ ๋‚œ์žฅํŒ
    ๋น„๋‹์ด ๋„ˆ๋ฌด ๊ฐ•๋ ฅ!! ๋น„๋‹๋ด‰์ง€์— ์Œ“์—ฌ์žˆ์œผ๋ฉด ๋‹ค ๋น„๋‹. ํฌ์žฅ๋œ ๋นจ๋Œ€๋„.
    ๋ฐฐ๊ฒฝ์ด ๋ฐ•์Šค โ†’ ์ข…์ด๋กœ ๋ผ๋ฒจ๋ง.
    ํŽ˜ํŠธ๋ณ‘์— ๋ถ™์€ ๋น„๋‹ โ†’ ํ”Œ๋ผ์Šคํ‹ฑ
    ๋ฐฐ๊ฒฝ์— ๋ฌผ์ฒด๊ฐ€ ์žˆ์–ด๋„ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ผ๋ฒจ๋ง ๋œ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

       Q. ๊ทธ๋Ÿฌ๋ฉด texture๋ฅผ ๋ฌด์‹œํ•˜๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋Š” ๊ฑธ๊นŒ์š”??
    
  • ๋“œ๋ก  classifier ๋…ผ๋ฌธ: RandomRotation (augmentation)์œผ๋กœ ์„ฑ๋Šฅ ํฌ๊ฒŒ ํ–ฅ์ƒ
    โ†’ ์ƒํ•˜ ๋ฐ˜์ „์ด๋‚˜ 90๋„ ํšŒ์ „๋„ ์ ์šฉํ•ด๋ณด๋ฉด ์ข‹์„ ๋“ฏ!


ํ˜•๋ฏผ๋‹˜

  • [LB 2์œ„ - mIOU = 0.5823]
    DeepLabV3Plus (SE_ResNet101, batch=16, image_size=512)
    Adam (default), lr scheduler๋Š” ์•ˆ ์ผ์Œ
    2์—ํญ mIOU = 0.37 โ†’ 3์—ํญ mIOU = 0.41
    โ‡’ 20์—ํญ ์ฏค ๋ฉˆ์ถค loss = 0.29, mIOU = 0.46 (ํ•™์Šต 120~150๋ถ„ ์†Œ์š”)

  • PSPNet, UNet ์„ฑ๋Šฅ ๋‚ฎ์Œ. (PSPNet์€ ์Šคํ† ๋ฆฌํ…”๋ง ๊ธฐ๋ฐ˜์ด๋ฏ€๋กœ ์šฐ๋ฆฌ ๋ฌธ์ œ์—๋Š” ์•ˆ ๋งž๋Š” ๋“ฏ)

  • DeepLabV3Plus (resnet34, batch=16, image_size=512) โ†’ ํ•™์Šต 30๋ถ„~1์‹œ๊ฐ„ ์†Œ์š”

  • Augmentation : ์ •๊ทœํ™” ํ–ˆ๋”๋‹ˆ ๋„ˆ๋ฌด ์–ด๋‘์›Œ์ง€๋Š” ๊ฒฝํ–ฅ โ†’ ๊ธฐ๋ฏผ๋‹˜์€ ์ •๊ทœํ™” ์ œ์™ธ์‹œํ‚ด.
    ์ •๊ทœํ™” + horizontal flip ๋กœ ์‹คํ—˜ : mIOU = 0.434

# Stage 1 ๊ทธ๋Œ€๋กœ ์ ์šฉ -> ํ˜„ ๋ฆฌ๋”๋ณด๋“œ 2์œ„
train_transform = A.Compose([
                  #Resize(height=CFG['resize'], width=CFG['resize'], p=1.0),
                  HorizontalFlip(p = 0.5),
                  VerticalFlip(p = 0.5),
                  #CLAHE(clip_limit=4.0, tile_grid_size=(8, 8), always_apply=False, p=0.5),
                  IAAPerspective(scale=(0.05, 0.1), keep_size=True, always_apply=False, p=0.5),
                  HueSaturationValue(hue_shift_limit=0.2, sat_shift_limit=0.2, val_shift_limit=0.2, p = 0.5),
                  RandomBrightnessContrast(brightness_limit=(-0.1, 0.1), contrast_limit = (-0.1, 0.1), p = 0.5),
                  Normalize(mean = [0.485, 0.456, 0.406], 
                            std = [0.229, 0.224, 0.225],
                            max_pixel_value=1.0 ,
                            p = 1.0
                           ),
                  Cutout(p=0.5),
                  ToTensorV2(p=1.0),
      ], p = 1.0)

๊ธฐ๋ฏผ๋‹˜

  • ์–ด์ œ ์‹คํ—˜๊ฒฐ๊ณผ: valid mIOU 0.46 (best_epoch=12) โ†’ Public LB = 0.5599
    DeepLabV3 (resnet101, batch=5)
    DataLoader โ†’ num_worker=0์œผ๋กœ ํ•ด์•ผ cpu ์•ˆ ํ„ฐ์ง!!

  • Dice Loss : mIOU ์—„์ฒญ ๋Š๋ฆฌ๊ฒŒ ์ƒ์Šน. 60์—ํญ์— mIOU=0.32 โ†’ Public LB 0.5099 (๋ฏผ์ •๋‹˜ ์ œ์ถœ)

  • ์˜ค๋Š˜์˜ ์‹คํ—˜
    ํ˜„์žฌ focal loss + dice loss ์‹คํ—˜ ์ค‘. ๋ชจ๋ธ์€ ๊ณ„์† DeepLabV3 (resnet101)
    ์‹œ๋„ํ•  ์˜ˆ์ • : Label smoothing + ํด๋ž˜์Šค ๋งˆ๋‹ค ์Šค์ฝ”์–ด ๋ฝ‘๊ธฐ
    ์ธ์ฝ”๋” ์ „์ฒด๋ฅผ ํ•™์Šตํ•˜์ง€ ๋ง๊ณ  ์•ž์ชฝ ๋ช‡ ๋‹จ์ด๋ผ๋„ freezeํ•˜๋ฉด ์–ด๋–จ์ง€ ๊ณ ๋ฏผ ์ค‘.

  • ํ•™์Šตํ•  ๋•Œ๋Š” ๊ณ ํ•ด์ƒ๋„๊ฐ€ ์œ ๋ฆฌํ•˜๋ฏ€๋กœ ๋ณดํ†ต down sizingํ•˜๋ฉด ์†ํ•ด๋‹ค.
    ๊ทธ๋Ÿฐ๋ฐ, 256๋„ ํฌ๊ฒŒ ์ฐจ์ด๊ฐ€ ์—†์œผ๋ฉด RandomCrop์„ ์จ์„œ ๋ฐ์ดํ„ฐ ์ฆ๊ฐ• ํšจ๊ณผ๋ฅผ ๋‚ด๋ณด๋Š” ๊ฒŒ ์–ด๋–จ๊นŒ??

  • CRF layer https://pypi.org/project/crfseg/ (boundary ํ›„์ฒ˜๋ฆฌ, ์ตœํ›„์˜ ์ˆ˜๋‹จ)
    ์ธํผ๋Ÿฐ์Šค ๋•Œ๋งŒ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด์ง€ ํ•™์Šตํ•  ๋•Œ ๊ฐ™์ด ๋ผ์›Œ๋„ฃ๋Š” ๊ฑด์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค.
    RNN + crf๋ž‘ ๋™์‹œ์— ์‚ฌ์šฉ โ†’ ํ…Œ๋‘๋ฆฌ๋ฅผ ์ฐพ์•„๋‚ด๋Š” end-to-end ๋ชจ๋ธ์ด PASCAL ์„ฑ๋Šฅ 75% ๋‚˜์˜ด.


์ฃผ์˜๋‹˜

  • ์บ๊ธ€์ด๋ž‘ ๋˜‘๊ฐ™์€ ํ•˜์ดํผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์‹คํ—˜ ์ค‘
    UNet + EfficientNet, batch_size=16, accumulation_step=2
    Dice Loss. 10์—ํญ ์งธ ๋Œ๋ฆฌ๋Š” ์ค‘.

๋ฏผ์ •๋‹˜

  • ๊นƒ ์‚ฌ์šฉ๋ฒ• pdf 1~7ํŽ˜์ด์ง€
    private repo๋ผ์„œ ์„œ๋ฒ„์— ssh ๋“ฑ๋ก ์•ˆ ํ•ด๋‘๋ฉด git cloneํ•  ๋•Œ๋งˆ๋‹ค ์—๋Ÿฌ ๋ฐœ์ƒ!!

  • ๋ฌด์กฐ๊ฑด git pull origin - commit - git push ๋ณธ์ธ๋ธŒ๋žœ์น˜ ํ•˜๋Š” ์Šต๊ด€!! main์€ ๊ฑด๋“œ๋ฆฌ์ง€ ๋ง์ž!!
    git remote add origin [repo์ฃผ์†Œ]
    git push origin(=repo์ฃผ์†Œ) ๋ณธ์ธ๋ธŒ๋žœ์น˜

  • Wiki์— ์‹คํ—˜ ๊ฒฐ๊ณผ ์˜ฌ๋ฆด ๋•Œ ์–ด๋–ค ๋ถ€๋ถ„์ด ์ข‹์•„์กŒ๋Š”์ง€, ๋‚˜๋น ์กŒ๋Š”์ง€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๊ธฐ

  • ASGNet https://github.com/Reagan1311/ASGNet (์ตœ์‹  ๋…ผ๋ฌธ, weight๋„ ์žˆ์Œ)

  • HRNet https://github.com/HRNet/HRNet-Semantic-Segmentation
    COCO(์šฐ๋ฆฌ ๋ฐ์ดํ„ฐ๋ž‘ ์œ ์‚ฌ)์— ๋Œ€ํ•ด ์„ฑ๋Šฅ ์ข‹์€ ํŽธ
    sgd, RMI loss

  • Region Mutual Information (RMI) Loss for Semantic Segmentation
    https://arxiv.org/pdf/1910.12037.pdf
    https://github.com/ZJULearning/RMI


๋ˆ„๋ฆฌ๋‹˜ (๋Œ€๋ฆฌ์‹คํ—˜)

  • DeepLabV3 (resnet101, batch=5, image_size=512)
    CrossEntropy
    AdamW(lr=1e-4, weight_decay=4e-2)
    CosineAnnealingWarmRestarts(optimizer, T_0=5, eta_min=1.2e-5)
    Transform : ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2, always_apply=False, p=0.5) + HorizontalFlip()
    ====================================
    5์—ํญ CEloss = 0.2758, mIOU = 0.4415
    10์—ํญ CEloss = 0.2532, mIOU = 0.4498 (best)
    14์—ํญ CEloss = 0.2563, mIOU = 0.4518
    15์—ํญ CEloss = 0.2602, mIOU = 0.4650
    20์—ํญ CEloss = 0.2608, mIOU = 0.4455
    ===================================
    ํ•™์Šต์‹œ๊ฐ„ : ์ด 5์‹œ๊ฐ„ ์†Œ์š”
    1-7์—ํญ : ์—ํญ๋‹น 12๋ถ„ 40์ดˆ
    8-11์—ํญ : 25๋ถ„ (2๋ฐฐ๋กœ ์ฆ๊ฐ€)
    12์—ํญ : 16๋ถ„
    13-20์—ํญ : ๋‹ค์‹œ 12๋ถ„ 40์ดˆ

  • DeepLabV3 (resnet101, batch=5, image_size=512)
    FocalLoss(gamma=2)
    AdamW(lr=1e-4, weight_decay=4e-2)
    CosineAnnealingWarmRestarts(optimizer, T_0=5, eta_min=1.2e-5)
    Transform : ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2, always_apply=False, p=0.5) + HorizontalFlip()
    ====================================
    5์—ํญ FocalLoss = 0.1572, mIOU = 0.4413
    9์—ํญ (best) FocalLoss = 0.1534, mIOU = 0.4333
    10์—ํญ FocalLoss = 0.1555, mIOU = 0.4350
    ============ ์ง„ํ–‰ ์ค‘ ============

Clone this wiki locally