1 Star 0 Fork 1

booq/stylegan2-pytorch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dataset.py 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
Kim Seonghyeon 提交于 2019-12-14 15:46 . Initial implementations
from io import BytesIO
import lmdb
from PIL import Image
from torch.utils.data import Dataset
class MultiResolutionDataset(Dataset):
def __init__(self, path, transform, resolution=256):
self.env = lmdb.open(
path,
max_readers=32,
readonly=True,
lock=False,
readahead=False,
meminit=False,
)
if not self.env:
raise IOError('Cannot open lmdb dataset', path)
with self.env.begin(write=False) as txn:
self.length = int(txn.get('length'.encode('utf-8')).decode('utf-8'))
self.resolution = resolution
self.transform = transform
def __len__(self):
return self.length
def __getitem__(self, index):
with self.env.begin(write=False) as txn:
key = f'{self.resolution}-{str(index).zfill(5)}'.encode('utf-8')
img_bytes = txn.get(key)
buffer = BytesIO(img_bytes)
img = Image.open(buffer)
img = self.transform(img)
return img
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/booq_Lab/stylegan2-pytorch.git
git@gitee.com:booq_Lab/stylegan2-pytorch.git
booq_Lab
stylegan2-pytorch
stylegan2-pytorch
master

搜索帮助