Last active
          March 30, 2018 13:24 
        
      - 
      
- 
        Save chexov/79459c77ea3e73b3065087d2510a1d0b to your computer and use it in GitHub Desktop. 
    create HDF5 dataset
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | # coding: utf-8 | |
| import cv2 | |
| import h5py | |
| import numpy | |
| img = cv2.imread('/Users/chexov/opencv-lena.jpg', 1) | |
| f = h5py.File('test2.hdf5', mode='w') | |
| group = f.create_group("images") | |
| dset = group.create_dataset("img1", shape=(512,512,3), dtype=numpy.uint8, data=img) | |
| dset.attrs['CLASS'] = 'IMAGE' | |
| dset.attrs['IMAGE_VERSION'] = '1.2' | |
| dset.attrs['IMAGE_MINMAXRANGE'] = numpy.array([0,255], dtype=numpy.uint8) | |
| dset.attrs['IMAGE_SUBCLASS'] = 'IMAGE_TRUECOLOR' | |
| dset.attrs['INTERLACE_MODE'] = 'INTERLACE_PIXEL' | |
| group = f.create_group("imagebatches") | |
| dset = group.create_dataset("imgbatch", shape=(4, 512,512,3), dtype=numpy.uint8) | |
| dset.attrs['CLASS'] = 'IMAGE' | |
| dset.attrs['IMAGE_VERSION'] = '1.2' | |
| dset.attrs['IMAGE_MINMAXRANGE'] = numpy.array([0,255], dtype=numpy.uint8) | |
| dset.attrs['IMAGE_SUBCLASS'] = 'IMAGE_TRUECOLOR' | |
| dset.attrs['INTERLACE_MODE'] = 'INTERLACE_PIXEL' | |
| dset[0, ...] = img | |
| f.close() | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment