Comments (11)
Hi,
I work with Ubuntu 18.04,
and i changed the function to:
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)
print('Current key:', key)
image_out_path = join(image_out_dir, key.decode() + '.jpg')
img = cv2.imdecode(
numpy.fromstring(val, dtype=numpy.uint8), 1)
cv2.imwrite(image_out_path, img)
count += 1
if count == limit:
break
if count % 1000 == 0:
print('Finished', count, 'images')
and it works, all images save in image_out_dir.
but the problem is each image saved in separately,
so i recommend to add in finish --flat to your command, for example:
python data.py export ./bedroom_val_lmdb --out_dir ./bedroom_val --flat
it extracts that all images into one folder, so this is a more neat..
from lsun.
The changes below fixes this issue when running the script in a windows environment. Using .decode() for the key and 'wb' for writing in binary mode seems to work in my case. Modify these lines in the data.py script:
LINE 44 : image_out_dir = join(out_dir, '/'.join(key[:6].decode()))
LINE 50 : with open(image_out_path, 'wb') as fp:
from lsun.
@patriciaVitoria
line 49 :
image_out_path = join(image_out_dir, key.decode() + '.webp')
from lsun.
Is this still a problem? Can you print the key on that line?
from lsun.
@fyu, @ratsuki
I can confirm it is still a problem.
My environment is python 3.6 & opencv 3.4.1
from lsun.
I encounter the same problem, my env is python 3.6 . Didyou solve the problem ?
@ratsuki @fyu @shirishr
from lsun.
Same issue. They key prints fine : b'000013'. Any solutions ?
from lsun.
When i modify both lines below i get the following error:
python data.py export bedroom_val_lmdb --out_dir data
Exporting bedroom_val_lmdb to data
Traceback (most recent call last):
File "data.py", line 89, in
main()
File "data.py", line 85, in main
export_images(lmdb_path, args.out_dir, args.flat)
File "data.py", line 49, in export_images
image_out_path = join(image_out_dir, key + '.webp')
TypeError: can't concat str to bytes
Anyone know how to solve it?
from lsun.
The changes below fixes this issue when running the script in a windows environment. Using .decode() for the key and 'wb' for writing in binary mode seems to work in my case. Modify these lines in the data.py script:
LINE 44 : image_out_dir = join(out_dir, '/'.join(key[:6].decode()))
LINE 50 : with open(image_out_path, 'wb') as fp:
It works on Ubuntu16.04 with python3.6, thanks!
from lsun.
it exports the image as webp, how do you convert it as jpg?
from lsun.
Hi,
I work with Ubuntu 18.04,
and i changed the function to: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) print('Current key:', key) image_out_path = join(image_out_dir, key.decode() + '.jpg') img = cv2.imdecode( numpy.fromstring(val, dtype=numpy.uint8), 1) cv2.imwrite(image_out_path, img) count += 1 if count == limit: break if count % 1000 == 0: print('Finished', count, 'images')
and it works, all images save in image_out_dir.
but the problem is each image saved in separately,
so i recommend to add in finish --flat to your command, for example:python data.py export ./bedroom_val_lmdb --out_dir ./bedroom_val --flat
it extracts that all images into one folder, so this is a more neat..
Hi, thanks for the sharing. When I use this code to extract jpg images from mdb, I got the error:
Traceback (most recent call last):
File "exportmdb.py", line 88, in
main()
File "exportmdb.py", line 84, in main
export_images(lmdb_path, args.out_dir, args.flat)
File "exportmdb.py", line 49, in export_images
img = cv2.imdecode(numpy.fromstring(val, dtype=numpy.uint8), 1)
cv2.error: OpenCV(4.5.2) ../modules/imgcodecs/src/loadsave.cpp:736: error: (-215:Assertion failed) !buf.e
mpty() in function 'imdecode_'
Do you know how to fix this? Thanks so much!
from lsun.
Related Issues (20)
- cannot get data HOT 1
- What's the mean and std for lsun dataset?
- LSUN Layout HOT 1
- What does the acronym "LSUN" mean? HOT 1
- 404 not found HOT 3
- .mat files HOT 1
- Seems like http://dl.yf.io/lsun/objects is down? HOT 2
- The transformed images hint PIL. UnidentifiedImageError: always identify a image file
- Download very slow HOT 4
- TEST set has only label 0 HOT 1
- HTTP 404 Error
- Could someone share the church_outdoor dataset to me? HOT 1
- Server is down HOT 2
- Can this dataset be used for commercial purposes ?
- curl http://dl.yf.io/lsun/scenes/classroom_train_lmdb.zip timed out HOT 2
- urlopen error No route to host HOT 3
- curl: (18) transfer closed with (1729112674) bytes remaining to read
- No route to host HOT 1
- The directory structure is not onsistent with meta list HOT 2
- Broken link HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsun.