作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 tensorflow 中编写一个数据输入管道,它使用一堆具有不同示例(类型)的 tfrecord 文件。
我正在使用如下代码:
filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"]
dataset = tf.data.TFRecordDataset(filenames)
dataset = dataset.map(_parse_function)
但是我希望我的 parse_function 对于 file1.tfrecord 与 file2.tfrecord 不同。我如何实现这一点。在 parse_example 中是否有某种方式知道特定示例来自哪个文件?
最佳答案
您可以使用 Dataset.flat_map()
将文件名包含在每条记录中的转换如下:
filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"]
filenames = tf.data.from_tensor_slices(filenames)
# `Dataset.flat_map()` creates a nested dataset from each element in `filenames`.
#
# For each file in filename, zip together the filename (repeated infinitely) with
# the records read from that file.
dataset = filenames.flat_map(
lambda fn: tf.data.Dataset.zip((tf.data.Dataset.from_tensors(fn).repeat(None),
tf.data.TFRecordDataset(fn))))
# The _parse_function can now be modified to take both the filename and the record.
dataset = dataset.map(lambda fn, record: _parse_function(fn, record))
关于tensorflow - 获取文件名示例来自 tf,parse_example,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49739206/
我正在 tensorflow 中编写一个数据输入管道,它使用一堆具有不同示例(类型)的 tfrecord 文件。 我正在使用如下代码: filenames = ["/var/data/file1.tf
我的 Tensorflow 模型为每个示例接收一系列序列数据,即单词序列中的字符标记序列(例如,[[3]、[4,3]、[6,1,20]] ).我之前可以通过填充 3D numpy 数组 [batch_
我是 tensorflow 的新手,正在阅读 tensorflow 服务示例中的 mnist_export.py。 这里有一些我无法理解的东西: sess = tf.InteractiveSess
我是一名优秀的程序员,十分优秀!