如何读取一个hdf5数据文件中的批次进行培训? [英] how to read batches in one hdf5 data file for training?

查看:95
本文介绍了如何读取一个hdf5数据文件中的批次进行培训?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个hdf5训练数据集,大小为(21760,1,33,33) 21760 是训练样本的总数。我想使用大小为 128 的小批量训练数据来训练网络。

I have a hdf5 training dataset with size (21760, 1, 33, 33). 21760 is the whole number of training samples. I want to use the mini-batch training data with the size 128 to train the network.

我想问:

如何喂食 128 每次都使用张量流从整个数据集中进行小批量训练数据吗?

How to feed 128 mini-batch training data from the whole dataset with tensorflow each time?

推荐答案

您可以将hdf5数据集读入numpy中数组,并将numpy数组的切片供入TensorFlow模型。像下面这样的伪代码将起作用:

You can read the hdf5 dataset into a numpy array, and feed slices of the numpy array to the TensorFlow model. Pseudo code like the following would work :

import numpy, h5py
f = h5py.File('somefile.h5','r')
data = f.get('path/to/my/dataset')
data_as_array = numpy.array(data)
for i in range(0, 21760, 128):
  sess.run(train_op, feed_dict={input:data_as_array[i:i+128, :, :, :]})

这篇关于如何读取一个hdf5数据文件中的批次进行培训?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆