Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import os
  3. import numpy as np
  4. import imageio
  5. import zipfile
  6.  
  7. output_dir='/home/belarm/laotzu/source/nns/datasets/nist-sd19/parsed'
  8. # output_dir='/home/ubuntu/efs/nist-sd19/parsed'
  9.  
  10. out_zips = {}
  11.  
  12. for i in range(0x30, 0x7b):
  13.     out_zips["{:x}".format(i)] = zipfile.ZipFile(os.path.join(output_dir, '{:x}.zip'.format(i)), 'w')
  14.  
  15. zfile = zipfile.ZipFile('/home/belarm/Downloads/by_class.zip')
  16. # zfile = zipfile.ZipFile('/home/ubuntu/by_class.zip')
  17. old_img_class = ''
  18.  
  19. for f in zfile.namelist():
  20.     if f.endswith('.png') and 'train' not in f:
  21.         _, img_class, _, key  = f.split('/')
  22.         img = imageio.imread(zfile.open(f).read())
  23.         img_normalized = img.astype(np.bool)
  24.         out_zips[img_class].writestr(key + '_raw', img.tobytes())
  25.         out_zips[img_class].writestr(key + '_normalized', img_normalized.tobytes())
  26.         if old_img_class != img_class:
  27.             print(img_class)
  28.             old_img_class = img_class
  29. for key, val in out_zips:
  30.     val.close()
  31. zfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement