1 Star 1 Fork 0

LYHCV/A002-1-PSGAN

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dataloder.py 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
Zhaoyi Wan 提交于 2020-07-13 21:05 . Add training code and refine structure
from torchvision import transforms
from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
from data_loaders.makeup_dataloader import MakeupDataloader
import torch
import numpy as np
import PIL
from psgan.preprocess import PreProcess
def ToTensor(pic):
# handle PIL Image
if pic.mode == 'I':
img = torch.from_numpy(np.array(pic, np.int32, copy=False))
elif pic.mode == 'I;16':
img = torch.from_numpy(np.array(pic, np.int16, copy=False))
else:
img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))
# PIL image mode: 1, L, P, I, F, RGB, YCbCr, RGBA, CMYK
if pic.mode == 'YCbCr':
nchannel = 3
elif pic.mode == 'I;16':
nchannel = 1
else:
nchannel = len(pic.mode)
img = img.view(pic.size[1], pic.size[0], nchannel)
# put it from HWC to CHW format
# yikes, this transpose takes 80% of the loading time/CPU
img = img.transpose(0, 1).transpose(0, 2).contiguous()
if isinstance(img, torch.ByteTensor):
return img.float()
else:
return img
def get_loader(config, mode="train"):
# return the DataLoader
transform = transforms.Compose([
transforms.Resize(config.DATA.IMG_SIZE),
transforms.ToTensor(),
transforms.Normalize([0.5,0.5,0.5],[0.5,0.5,0.5])])
transform_mask = transforms.Compose([
transforms.Resize(config.DATA.IMG_SIZE, interpolation=PIL.Image.NEAREST),
ToTensor])
dataset = MakeupDataloader(
config.DATA.PATH, transform=transform,
transform_mask=transform_mask, preprocess=PreProcess(config))
#"""
dataloader = DataLoader(dataset=dataset,
batch_size=config.DATA.BATCH_SIZE,
shuffle=True, num_workers=config.DATA.NUM_WORKERS)
return dataloader
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lyhcv/PSGAN.git
git@gitee.com:lyhcv/PSGAN.git
lyhcv
PSGAN
A002-1-PSGAN
master

搜索帮助