Created
August 22, 2019 12:25
-
-
Save koyamalmsteen/4f2329aadde6eadbe24b163833bc00d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I referred https://qiita.com/yuishihara/items/3f0adf0877cd8fe1c394 and modif\ | |
ied | |
import scipy | |
import numpy as np | |
import lmdb | |
import sys | |
from caffe.io import caffe_pb2 | |
def main(): | |
argv = sys.argv | |
argc = len(argv) | |
if (argc ==2 ): | |
convert_to_jpeg(argv[1]) | |
def convert_to_jpeg(db_dir): | |
env = lmdb.open(db_dir) | |
datum = caffe_pb2.Datum() | |
with env.begin() as txn: | |
cursor = txn.cursor() | |
for key_val, ser_str in cursor: | |
datum.ParseFromString(ser_str) | |
print "\nKey val: ", key_val | |
print "\nLabel: ",datum.label | |
rows = datum.height; | |
cols = datum.width; | |
img_pre = np.fromstring(datum.data,dtype=np.uint8) | |
img = img_pre.reshape(rows, cols) | |
file_name = str(key_val) + "_" + str(datum.label) +".jpg" | |
scipy.misc.toimage(img, cmin=0.0, cmax=255.0).save("data/mnist/jpg\ | |
/" + file_name) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment