H5py: Converting hdf5 file to csv

Created on 22 Oct 2015  路  3Comments  路  Source: h5py/h5py

Hi, how do we convert a hdf5 file to csv format using python?

Most helpful comment

file = h5py.File('model.h5','r+')

dataset1 = file['/dense_1/dense_1/kernel'] // suppose kernel contains the weights
numpy.savetxt("dataset1.csv",dataset1)

All 3 comments

In general, you can't just map directly to a single CSV file. The "H" in HDF5 stands for "hierarchical", so HDF5 data is actually tree-like. There is also metadata in HDF5 files that is not part of the arrays stored in the files.

Agreed... this is a very general question. I'd recommend getting used to NumPy, exporting some arrays to CSV, and then move on to h5py using the online user guide (docs.h5py.org.).

file = h5py.File('model.h5','r+')

dataset1 = file['/dense_1/dense_1/kernel'] // suppose kernel contains the weights
numpy.savetxt("dataset1.csv",dataset1)

Was this page helpful?
0 / 5 - 0 ratings