数据集

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)
posted @ 2024-01-15 16:06  idazhi  阅读(11)  评论(0编辑  收藏  举报