lsun数据集下载、转换、使用 |
您所在的位置:网站首页 › mdb格式转换 › lsun数据集下载、转换、使用 |
最近复现SAGAN用到了lsun数据集 1.下载地址 http://dl.yf.io/lsun/scenes/ 我下载了church_outdoor_train_lmdb.zip 中间还安装了lmdb库 2.转换 一般下载的data.py(转换代码)有bug,这段代码已经进行了修复,编译脚本并运行即可 python data.py export ./church_outdoor_train_lmdb --out_dir ./lsun --flat # -*- coding: utf-8 -*- """ Created on Mon Sep 28 10:28:13 2020 @author: ZM """ from __future__ import print_function import argparse import cv2 import lmdb import numpy import os from os.path import exists, join __author__ = 'Fisher Yu' __email__ = '[email protected]' __license__ = 'MIT' def view(db_path): print('Viewing', db_path) print('Press ESC to exist or SPACE to advance.') window_name = 'LSUN' cv2.namedWindow(window_name) env = lmdb.open(db_path, map_size=1099511627776, max_readers=100, readonly=True) with env.begin(write=False) as txn: cursor = txn.cursor() for key, val in cursor: print('Current key:', key) img = cv2.imdecode( numpy.fromstring(val, dtype=numpy.uint8), 1) cv2.imshow(window_name, img) c = cv2.waitKey() if c == 27: break def export_images(db_path, out_dir, flat=False, limit=-1): print('Exporting', db_path, 'to', out_dir) env = lmdb.open(db_path, map_size=1099511627776, max_readers=100, readonly=True) count = 0 with env.begin(write=False) as txn: cursor = txn.cursor() for key, val in cursor: if not flat: image_out_dir = join(out_dir, '/'.join(key[:6].decode())) else: image_out_dir = out_dir if not exists(image_out_dir): os.makedirs(image_out_dir) image_out_path = join(image_out_dir, key.decode() + '.jpg') with open(image_out_path, 'wb') as fp: fp.write(val) count += 1 if count == limit: break if count % 1000 == 0: print('Finished', count, 'images') def main(): parser = argparse.ArgumentParser() parser.add_argument('command', nargs='?', type=str, choices=['view', 'export'], help='view: view the images in the lmdb database ' 'interactively.\n' 'export: Export the images in the lmdb databases ' 'to a folder. The images are grouped in subfolders' ' determinted by the prefiex of image key.') parser.add_argument('lmdb_path', nargs='+', type=str, help='The path to the lmdb database folder. ' 'Support multiple database paths.') parser.add_argument('--out_dir', type=str, default='') parser.add_argument('--flat', action='store_true', help='If enabled, the images are imported into output ' 'directory directly instead of hierarchical ' 'directories.') args = parser.parse_args() command = args.command lmdb_paths = args.lmdb_path for lmdb_path in lmdb_paths: if command == 'view': view(lmdb_path) elif command == 'export': export_images(lmdb_path, args.out_dir, args.flat) if __name__ == '__main__': main()3.根据具体代码使用lmdb格式或者jpg格式
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |