Skip to content

Instantly share code, notes, and snippets.

@paulaksm
Created November 26, 2018 14:51
Show Gist options
  • Save paulaksm/6677bd14a468ccf656c22c6e7ac5df5d to your computer and use it in GitHub Desktop.
Save paulaksm/6677bd14a468ccf656c22c6e7ac5df5d to your computer and use it in GitHub Desktop.
Generate HDF5 files for array images with their labels
''' Generate HDF5 files for array images and their labels... unfortunately this function won't work inside the Kaggle kernel
because of its limited resources
'''
def create_data_labels(height=256, width=455, channels=3, filename='driving'):
data_filename = filename + '_data'
label_filename = filename + '_labels'
txt_labels = pd.read_csv('../input/driving_dataset/driving_dataset/data.txt', sep=" ", header=None)
path = '../input/driving_dataset/driving_dataset/'
hdf5_file = h5py.File('self_driving_dataset.hdf5', mode='w')
hdf5_file.create_dataset(data_filename, (txt_labels.shape[0], height, width, channels), np.uint8)
hdf5_file.create_dataset(label_filename, (txt_labels.shape[0],), np.float16)
for i, (name, steer) in enumerate(txt_labels.values):
img_name = path + name
img = Image.open(img_name)
hdf5_file[data_filename][i, ...] = img
hdf5_file[label_filename][i, ...] = steer
hdf5_file.close()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment