h5py数据存储格式
h5py是python中一种数据压缩格式,它的优势:速度快、压缩效率高。尤其是在处理深度学习的大量图像时,常常用到。
h5py 的写入与读取
import h5py
import numpy as np
X= np.random.rand(100, 1000, 1000).astype('float32')
y = np.random.rand(1, 1000, 1000).astype('float32')
# Create a new file
f = h5py.File('data.h5', 'w')
f.create_dataset('X_train', data=X)
f.create_dataset('y_train', data=y)
f.close()
# Load hdf5 dataset
f = h5py.File('data.h5', 'r')
X = f['X_train']
Y = f['y_train']
f.close()
---------------------
给定一个压缩的h5py 图像数据,读取并查看它
mport h5py
import numpy as np
import tensorflow as tf
import math
#定义一个读取函数,这个数据是借用别人的手势数据
def load_dataset():
train_dataset = h5py.File('datasets/train_signs.h5', "r")
train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # your train set labels
test_dataset = h5py.File('datasets/test_signs.h5', "r")
test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels
classes = np.array(test_dataset["list_classes"][:]) # the list of classes
train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes
#查看
X_train_orig , Y_train_orig , X_test_orig , Y_test_orig , classes = tf_utils.load_dataset()
index = 11#查看数据中索引11的图像
plt.imshow(X_train_orig[index])
pylab.show()
print("Y = " + str(np.squeeze(Y_train_orig[:,index])))
结果显示
附上代手势数据集
手势h5py数据
参考
https://blog.csdn.net/u013733326/article/details/79971488#commentBox
https://blog.csdn.net/qq_23968185/article/details/77671726