【发布时间】:2016-11-22 04:08:23
【问题描述】:
我的目标是为固定数量的时期或步骤训练神经网络,我希望每个步骤都使用 .tfrecords 文件中特定大小的一批数据。
目前我正在使用这个循环从文件中读取:
i = 0
data = np.empty(shape=[x,y])
for serialized_example in tf.python_io.tf_record_iterator(filename):
example = tf.train.Example()
example.ParseFromString(serialized_example)
Labels = example.features.feature['Labels'].byte_list.value
# Some more features here
data[i-1] = [Labels[0], # more features here]
if i == 3:
break
i = i + 1
print data # do some stuff etc.
我是一个 Python 菜鸟,我怀疑在循环之外创建“i”并在它达到某个值时中断只是一个hacky word-around。
有没有一种方法可以从文件中读取数据,但指定“我想要标签功能中包含的 byte_list 中的前 100 个值”,然后指定“我想要接下来的 100 个值”。
为了澄清,我不熟悉的事情是以这种方式循环文件,我不确定如何操作循环。
谢谢。
【问题讨论】:
-
你可以试试
enumerate():stackoverflow.com/questions/522563/…
标签: python python-2.7 numpy machine-learning tensorflow