用于将HDF5文件读入TensorFlow的接口。
tftables的Python项目详细描述
tftables允许使用tensorflow方便地访问hdf5文件。 提供了一个从数组或表中读取成批数据的类。 二级类将主读卡器和tensorflow fifoquee包装起来,用于直接流式处理 从hdf5文件到tensorflow操作的数据。
库由multitables支持,用于高速读取hdf5 数据集。multitables基于pytables(tables),因此此库可以使用任何压缩算法 pytables支持的。
许可证
这个软件是根据麻省理工学院的许可证发行的。 有关详细信息,请参见LICENSE.txt文件。
安装
pip install tftables
或者,要从头部安装,请运行
pip install git+https://github.com/ghcollin/tftables.git
你也可以download 或者clone the repository并运行
python setup.py install
tftables依赖于multitables、numpy和tensorflow。该包与最新版本的python兼容 2和3。
快速启动
访问HDF5文件中的表的示例。
importtftablesimporttensorflowastfwithtf.device('/cpu:0'):# This function preprocesses the batches before they# are loaded into the internal queue.# You can cast data, or do one-hot transforms.# If the dataset is a table, this function is required.definput_transform(tbl_batch):labels=tbl_batch['label']data=tbl_batch['data']truth=tf.to_float(tf.one_hot(labels,num_labels,1,0))data_float=tf.to_float(data)returntruth,data_float# Open the HDF5 file and create a loader for a dataset.# The batch_size defines the length (in the outer dimension)# of the elements (batches) returned by the reader.# Takes a function as input that pre-processes the data.loader=tftables.load_dataset(filename='path/to/h5_file.h5',dataset_path='/internal/h5/path',input_transform=input_transform,batch_size=20)# To get the data, we dequeue it from the loader.# Tensorflow tensors are returned in the same order as input_transformationtruth_batch,data_batch=loader.dequeue()# The placeholder can then be used in your networkresult=my_network(truth_batch,data_batch)withtf.Session()assess:# This context manager starts and stops the internal threads and# processes used to read the data from disk and store it in the queue.withloader.begin(sess):for_inrange(num_iterations):sess.run(result)
如果数据集是数组而不是表。那么input_transform可以省略 如果不需要预处理。如果只需要通过数据集一次, 然后应该将cyclic=False传递给load_dataset。
示例
有关完整示例,请参见unit tests。
示例
有关更深入的文档,请参见how-to,以及 unit tests完整示例。