数据增强之mixup

数据增强之mixup,就是做一个图像融合,简单理解就是两张图像的叠加。具体细节见:https://blog.csdn.net/u013685264/article/details/122622919

具体效果如下:
原图:
数据增强之mixup_第1张图片

mixup后:
数据增强之mixup_第2张图片

代码实现:

import cv2
import numpy as np


# MixUP
img1 = cv2.imread('dog.png')
img1 = cv2.resize(img1, (1960, 1080))

img2 = cv2.imread('cat.png')
img2 = cv2.resize(img2, (1960, 1080))

alpha = 1.0
lam = np.random.beta(alpha, alpha)
print(lam)

mixed_img = lam * img1 + (1 - lam) * img2

cv2.imwrite('mixed_img.jpeg', mixed_img)

你可能感兴趣的:(深度学习小技巧,opencv,计算机视觉,python)