fyu / lsun

LSUN Dataset Documentation and Demo Code
531 stars 175 forks source link

cannot get data #30

Open DikshaMeghwal opened 4 years ago

DikshaMeghwal commented 4 years ago

sequence item 0: expected str instance, int found Any help would be appreciated.

dejanaugrenovic commented 4 years ago

Look at this solution: https://github.com/fyu/lsun/issues/22 - It solves the issue. Basically you need in function export_images to change two lines: image_out_path = join(image_out_dir, key + '.webp') with image_out_path = join(image_out_dir, key.decode() + '.webp') and open(image_out_path, 'w') as fp: with `open(image_out_path, 'wb') as fp:

I put the export_image function in separate file and also set absolute paths. This worked for me: export_images.py:

from __future__ import print_function
import argparse
import cv2
import lmdb
import numpy
import os
from os.path import exists, join
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]))
            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() + '.webp')
            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')
if __name__ == '__main__':
    export_images(r'C:\Users\Dejana\Documents\lsun-master\bedroom_val_lmdb',r'C:\Users\Dejana\Documents\lsun-master\data',True)