h5 数据制作与读取

数据集制作
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

猜你喜欢

转载自blog.csdn.net/weixin_41855385/article/details/84395949