import random
import numpy as np
seed =666
np.random.seed(seed)# Numpy module.
random.seed(seed)# Python random module.for i inrange(10):
P = random.random()print(P)
数据增强旋转
defrotate_nobound(image, angle, center=None, scale=1.):(h, w)= image.shape[:2]# if the center is None, initialize it as the center of the imageif center isNone:
center =(w //2, h //2)# perform the rotation
M = cv2.getRotationMatrix2D(center, angle, scale)
rotated = cv2.warpAffine(image, M,(w, h))return rotated
数据增强应用
p = random.random()if p <=0.25:
imgo_arr = rotate_nobound(imgo_arr,90, center=None, scale=1.)# 转为numpy 进行数据增强
mask = rotate_nobound(mask,90, center=None, scale=1.)# 转为numpy 进行数据增强elif0.25< p and p<=0.5:
imgo_arr = rotate_nobound(imgo_arr,180, center=None, scale=1.)# 转为numpy 进行数据增强
mask = rotate_nobound(mask,180, center=None, scale=1.)# 转为numpy 进行数据增强else:# 0.5 < p and p<= 0.75:
imgo_arr = rotate_nobound(imgo_arr,270, center=None, scale=1.)# 转为numpy 进行数据增强
mask = rotate_nobound(mask,270, center=None, scale=1.)# 转为numpy 进行数据增强