sfgan执行matlab生成的文件,如果文件超过2g,会用v7.3格式保存 python读取时候格式发生变化

Please use HDF reader for matlab v7.3 files

/home/gis/anaconda3/envs/pytguo35/bin/python /home/gis/PycharmProjects/guo/SFGAN-master/sfgan.py
Traceback (most recent call last):
  File "/home/gis/PycharmProjects/guo/SFGAN-master/sfgan.py", line 46, in <module>
    trainset = loadmat(data_dir + 'train_64x64.mat')  # read the images as .mat format
  File "/home/gis/anaconda3/envs/pytguo35/lib/python3.5/site-packages/scipy/io/matlab/mio.py", line 141, in loadmat
    MR, file_opened = mat_reader_factory(file_name, appendmat, **kwargs)
  File "/home/gis/anaconda3/envs/pytguo35/lib/python3.5/site-packages/scipy/io/matlab/mio.py", line 71, in mat_reader_factory
    raise NotImplementedError('Please use HDF reader for matlab v7.3 files')
NotImplementedError: Please use HDF reader for matlab v7.3 files

Process finished with exit code 1

MATLAB存储mat文件,数据大小超过2GB,采用-v7.3存储

python读取mat文件

-v7格式

scipy.io库

import scipy.io as sio 
matfn = '/home/weiliu/workspace/python/matlab/mat4py.mat'
data = sio.loadmat(matfn)
-v7.3格式 

h5py库

import h5py
path='C:/data.mat'                    #需要读取的mat文件路径
feature=h5py.File(path)               #读取mat文件
data = feature['feature_data'][:]     #读取mat文件中所有数据存储到array中
 

具体修改内容:原来 46-47行这样修改。
# Load the training and testing datasets
trainset =h5py.File(data_dir + 'train_64x64.mat') #读取mat文件  -v7.3格式 
testset = h5py.File(data_dir + 'test_64x64.mat')
#trainset = loadmat(data_dir + 'train_64x64.mat')  # read the images as .mat format
#testset = loadmat(data_dir + 'test_64x64.mat')

/home/gis/anaconda3/envs/pytguo35/bin/python /home/gis/PycharmProjects/guo/SFGAN-master/sfgan.py
Traceback (most recent call last):
  File "/home/gis/PycharmProjects/guo/SFGAN-master/sfgan.py", line 6, in <module>
    import h5py
ImportError: No module named 'h5py'

Process finished with exit code 1

ubuntu系统中import h5py, ImportError: No module named h5py的解决方法

sudo apt-get install libhdf5-dev
sudo apt-get install python-h5py

测试 import h5py 没有报错,成功

中间一直不成功,后来找资料

In my case (Ubuntu 15.04) installing libhdf5-dev was not enough.

I had to run:

HDF5_DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ pip install h5py

to make it work.  终于ok

猜你喜欢

转载自blog.csdn.net/gdengden/article/details/85855738