将批量的图片储存到h5py中,代码如下:
from scipy import misc
import h5py
import numpy as np
f = h5py.File(“myh5py.hdf5”, “w”) #创建h5py文件
d1 = f.create_dataset(“train_X_orig”, (6, 64, 64, 3), ‘i’) #设置要储存的样本个数,需要提前设置好,本例中为6个
for i in range(6):
X = misc.imread(‘shou zhi_%i.jpg’ % i) #进入储存循环,本例中写入的图片为shou zhi_0,shou zhi_1,…shou zhi_5
X = misc.imresize(X, (1, 64, 64, 3))
d1[i] = X # 将第i个保存到d1[i]中即可
for key in f.keys():
print(f[key].name)
print(f[key].value)
print(f[key].shape)