[pytorch] 图像识别之mixup/cutmix

本人kaggle分享链接:https://www.kaggle.com/c/bengaliai-cv19/discussion/126504

效果图: (目标检测中)

[pytorch] 图像识别之mixup/cutmix_第1张图片

代码如下:



def rand_bbox(size, lam):
    W = size[2]
    H = size[3]
    cut_rat = np.sqrt(1. - lam)
    cut_w = np.int(W * cut_rat)
    cut_h = np.int(H * cut_rat)

    # uniform
    cx = np.random.randint(W)
    cy = np.random.randint(H)

    bbx1 = np.clip(cx - cut_w // 2, 0, W)
    bby1 = np.clip(cy - cut_h // 2, 0, H)
    bbx2 = np.clip(cx + cut_w // 2, 0, W)
    bby2 = np.clip(cy + cut_h // 2, 0, H)

    return bbx1, bby1, bbx2, bby2
def cutmix(data, targets1, targets2, targets3, alpha):
    

你可能感兴趣的:(Deep,learning,比赛方案总结)