h 5データ作成と読み出し
1226 ワード
データセットはdataを作成し、listはnumpy形式であり、一般的にlist形式であり、np.array変換を使用する.作成:
データセット読み込み
with h5py.File(savepath, 'w') as hf:
hf.create_dataset(name , value)
with h5py.File(savepath, 'r') as hf:
hf.get(name)
def make_data(sess, data, label):
"""
Make input data as h5 file format
Depending on 'is_train' (flag value), savepath would be changed.
"""
if FLAGS.is_train:
savepath = os.path.join(os.getcwd(), 'checkpoint/train.h5')
else:
savepath = os.path.join(os.getcwd(), 'checkpoint/test.h5')
with h5py.File(savepath, 'w') as hf:
hf.create_dataset('data', data=data)
hf.create_dataset('label', data=label)
データセット読み込み
def read_data(path):
"""
Read h5 format data file
Args:
path: file path of desired file
data: '.h5' file format that contains train data values
label: '.h5' file format that contains train label values
"""
with h5py.File(path, 'r') as hf:
data = np.array(hf.get('data'))
label = np.array(hf.get('label'))
return data, label