Created
October 18, 2018 06:50
-
-
Save iaalm/fc4133707a33c99c693408c304d426bd to your computer and use it in GitHub Desktop.
Convert between .mat and .h5
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
#!/usr/bin/python3 | |
import h5py | |
import numpy | |
import scipy.io | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file", help="h5 file or mat file") | |
args = parser.parse_args() | |
data = {} | |
if args.file.endswith('.h5'): | |
with h5py.File(args.file) as fd: | |
for i in fd.keys(): | |
data[i] = fd[i][...] | |
scipy.io.savemat(args.file[:-3] + '.mat', data) | |
elif args.file.endswith('.mat'): | |
data = scipy.io.loadmat(args.file) | |
with h5py.File(args.file[:-4] + '.h5', 'w') as fd: | |
for i in data.keys(): | |
if i not in ['__globals__', '__header__', '__version__']: | |
fd[i] = numpy.squeeze(data[i]) | |
else: | |
raise ValueError('filename must ends with .h5 or .mat') | |
I got the same error! I would be greatful if you could post a solution.
Thanks so much.
Hello,
when i run
python convert.py trainedNet.mat
it converts the file into trainedNet.h5 but is it a correct conversion?
as i am getting error:
tid = h5t.py_create(dtype, logical=1)
File "h5py\h5t.pyx", line 1634, in h5py.h5t.py_create
File "h5py\h5t.pyx", line 1656, in h5py.h5t.py_create
File "h5py\h5t.pyx", line 1678, in h5py.h5t.py_create
File "h5py\h5t.pyx", line 1591, in h5py.h5t._c_compound
File "h5py\h5t.pyx", line 1656, in h5py.h5t.py_create
File "h5py\h5t.pyx", line 1711, in h5py.h5t.py_create
TypeError: Object dtype dtype('O') has no native HDF5 equivalent
please resolve this issue
Hi @AgriPooja , is it possible to share you .mat
files? I can have a try with it.
Hello, i am not able to share the .mat files here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for this gist.
while compiling this code I am getting error.(below-error-log).
python convert-mat.py SynthText.h5
Would you please help to solve this problem.