数据增强之cutout变体,添加噪声
生成框
def rand_bbox(size, lam):
W = size[2]
H = size[3]
# ratio = np.sqrt(1. - lam)
cut_w = np.int(W * lam)
cut_h = np.int(H * lam)
# 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
CutMix
def mix_make_data(img, label):
b, _, h, w = img.shape
bflag = random.randint(0, b // 2 - 1)
fflag = random.randint(0, 100)
rrate = 1.0
if fflag < 50:
hflag = random.randint(0, 100)
rflag = random.randint(2, 6)
pflag = random.randint(0, rflag)
wsp = 0
hsp = 0
sw = w
sh = h