def random_augmentation(image, crop_size, resize_size):
# randomly choose crop size
image = image.transpose(1, 2, 0)
h, w, _ = image.shape
# random cropping
if crop_size != h:
top = random.randint(0, h - crop_size - 1)
left = random.randint(0, w - crop_size - 1)
bottom = top + crop_size
right = left + crop_size
image = image[top:bottom, left:right, :]
# random flipping
if random.randint(0, 1):
image = image[:, ::-1, :]
# randomly choose resize size
if resize_size != crop_size:
cv2.resize(image, (resize_size, resize_size), interpolation=cv2.INTER_AREA)
return image.transpose(2, 0, 1)
train_cycle_gan.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录