from PIL import Image
import torch
from torchvision import transforms
trans = transforms.Compose([transforms.ToTensor(), transforms.RandomErasing(p=0.9, value = 120, inplace=True)])
# 这里Compose是所做的变换
img_path = '02-56-45-060-1454-camra1.bmp'
img = Image.open(img_path)
img = trans(img)
image = img.cpu().clone()
image = transforms.ToPILImage()(image) # 自动转换为0-255
image.show()
image.save('b.jpg')
PyTorch数据增强后的结果展示
于 2023-09-24 16:14:39 首次发布