h5 資料製作與讀取
阿新 • • 發佈:2018-11-25
資料集製作
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