读取.h5里面的数据

我想要利用别人的训练过的参数来训练自己的神经网络,我遇到两种,一种参数是在mat文件里,一种是在.h5文件里。mat文件数据很容易读取。下面给出读取.h5文件里储存数据的代码:

import h5py
f = h5py.File('./pretrained/weights_c3d.h5','r')
for key, value in f.attrs.items():
    print("  {}: {}".format(key, value))
            

group1 = f.get('conv3d_1')
group2 = f.get('conv3d_2')
group3 = f.get('conv3d_3')
group4 = f.get('conv3d_4')
group5 = f.get('conv3d_5')
g1 = group1.get('conv3d_1')
g2 = group2.get('conv3d_2')
g3 = group3.get('conv3d_3')
g4 = group4.get('conv3d_4')
g5 = group5.get('conv3d_5')
w1 = g1.get('kernel:0')
w1 = np.array(w1)
b1 = g1.get('bias:0')
b1 = np.array(b1)
w2 = g2.get('kernel:0')
w2 = np.array(w2)
b2 = g2.get('bias:0')
b2 = np.array(b2)
w3 = g3.get('kernel:0')
w3 = np.array(w3)
b3 = g3.get('bias:0')
b3 = np.array(b3)
w4 = g4.get('kernel:0')
w4 = np.array(w4)
b4 = g4.get('bias:0')
b4 = np.array(b4)
w5 = g5.get('kernel:0')
w5 = np.array(w5)
b5 = g5.get('bias:0')
b5 = np.array(b5)
print(w1.shape)
print(w2.shape)
print(w3.shape)
print(w4.shape)
print(w5.shape)

 

以上代码读取了五个卷积层的参数,输出结果是:

读取.h5里面的数据_第1张图片

你可能感兴趣的:(读取.h5里面的数据)