1 Star 0 Fork 0

peakmeans/FUNIT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data.py 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
Ming-Yu Liu 提交于 2019-10-17 13:54 . PetSwap -> GANimal
"""
Copyright (C) 2019 NVIDIA Corporation. All rights reserved.
Licensed under the CC BY-NC-SA 4.0 license
(https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
"""
import os.path
from PIL import Image
import torch.utils.data as data
def default_loader(path):
return Image.open(path).convert('RGB')
def default_filelist_reader(filelist):
im_list = []
with open(filelist, 'r') as rf:
for line in rf.readlines():
im_path = line.strip()
im_list.append(im_path)
return im_list
class ImageLabelFilelist(data.Dataset):
def __init__(self,
root,
filelist,
transform=None,
filelist_reader=default_filelist_reader,
loader=default_loader,
return_paths=False):
self.root = root
self.im_list = filelist_reader(os.path.join(filelist))
self.transform = transform
self.loader = loader
self.classes = sorted(
list(set([path.split('/')[0] for path in self.im_list])))
self.class_to_idx = {self.classes[i]: i for i in
range(len(self.classes))}
self.imgs = [(im_path, self.class_to_idx[im_path.split('/')[0]]) for
im_path in self.im_list]
self.return_paths = return_paths
print('Data loader')
print("\tRoot: %s" % root)
print("\tList: %s" % filelist)
print("\tNumber of classes: %d" % (len(self.classes)))
def __getitem__(self, index):
im_path, label = self.imgs[index]
path = os.path.join(self.root, im_path)
img = self.loader(path)
if self.transform is not None:
img = self.transform(img)
if self.return_paths:
return img, label, path
else:
return img, label
def __len__(self):
return len(self.imgs)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peak_means/FUNIT.git
git@gitee.com:peak_means/FUNIT.git
peak_means
FUNIT
FUNIT
master

搜索帮助