当前位置:   article > 正文

深度学习初学--数据增强可视化

深度学习初学--数据增强可视化

在深度学习中,数据增强是个很重要的数据预处理过程,处理的好坏影响训练的结果,以下是一个可视化数据增强后图像的可视化代码:

import numpy as np
import torchvision.transforms as transforms
from matplotlib import pyplot as plt
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.utils import make_grid
transform = transforms.Compose([
    transforms.Resize(256),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize(mean=(0.485,0.455,0.406),std=(0.229,0.224,0.225))
])
traindata = datasets.ImageFolder(root ='train', transform=transform)
trainloader = DataLoader(dataset=traindata, batch_size=64, shuffle=True,num_workers=8)

def image_show(image):
    plt.figure(figsize=(50,50))
    image = image.numpy().transpose((1,2,0))
    mean = np.array([0.485,0.456,0.406])
    std = np.array([0.229,0.224,0.225])
    image = std *image +mean
    image = np.clip(image,0,1)
    plt.imshow(image)
    plt.show()
datas , targets = next(iter(trainloader))
out = make_grid(datas,nrow=4,padding=10)
image_show(out)
print(targets)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/133036
推荐阅读
相关标签
  

闽ICP备14008679号