简体   繁体   English

对如何在 matlab 中的 HDF5 文件中存储 3D 矩阵感到困惑?

[英]Confused on how to store 3D matrices in HDF5 file in matlab?

I have multiple 3D matrices that need to be stored in a hdf5 file.我有多个 3D 矩阵需要存储在 hdf5 文件中。 I have looked everywhere but i am confused about the process of storing data in hdf5 file.我到处找,但我对在 hdf5 文件中存储数据的过程感到困惑。 Can i store multiple 3D matrices in a single dataset in hdf5 file or do i have to create separate dataset for each 3D matrix?我可以在 hdf5 文件的单个数据集中存储多个 3D 矩阵,还是必须为每个 3D 矩阵创建单独的数据集? I need this dataset for training a 3D CNN model.我需要这个数据集来训练 3D CNN 模型。 If both ways are possible, which is the best for training purpose?如果两种方式都可以,哪种方式最适合训练目的?

Additional information: Matrix size is 12x24x12 and a single data takes less than 100 kb storage space.附加信息:矩阵大小为 12x24x12,单个数据占用不到 100 kb 的存储空间。 Dataset is created in matlab and the resultant file will be used in python (where the model will be trained).数据集在 matlab 中创建,生成的文件将在 python 中使用(模型将在其中训练)。

In matlab you specify -v3.7 to save stuff in hdf5.在 matlab 中,您指定 -v3.7 以将内容保存在 hdf5 中。 You save your matrices like this:您可以像这样保存矩阵:

mat0 = zeros(12,24,12);
mat1 = ones(12,24,12);
mat2 = 2*ones(12,24,12);
save data.mat mat0 mat1 mat2 -v7.3

In python you read them like this:在 python 中,你可以这样阅读它们:

import numpy as np
import h5py
f = h5py.File('/home/innereye/data.mat','r')
mat1 = f.get('mat1')
mat1 = np.array(mat1)

you have a lot of material on Stackoverflow about reading mat files with python, for example, here and here .你在 Stackoverflow 上有很多关于用 python 读取 mat 文件的材料,例如, 这里这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM