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') | |
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
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:
please resolve this issue