import os
from PIL import Image
from torchvision import transforms
# 输入图片
file_list = os.listdir('E:/ly/train_data/')
h = 0
randomcrop = transforms.RandomCrop(790,1082) # 随机剪裁大小为99*99
randomhorizontalflip = transforms.RandomHorizontalFlip() # 对图片进行翻转
for i in file_list:
# 输入图片
img = Image.open('E:/ly/train_data/%s'%i)
print(img.size)
for j in range(1,101):
h = h + 1
# 输出图片路径
if not os.path.exists('E:/ly/aug_data/'):
os.mkdir('E:/ly/aug_data/')
# img1 = randomcrop(img)
# img1 = randomhorizontalflip(img)
img1 = img
img1.save(r'E:/ly/aug_data/%s.png'%h)
标签:os,img,数据,transforms,img1,data,ly
From: https://www.cnblogs.com/idazhi/p/17965594