- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Tensorflow 的 Estimator API,我应该在管道中的哪个点执行数据增强?
据此官方Tensorflow guide ,执行数据增强的一个位置是 input_fn
:
def parse_fn(example):
"Parse TFExample records and perform simple data augmentation."
example_fmt = {
"image": tf.FixedLengthFeature((), tf.string, ""),
"label": tf.FixedLengthFeature((), tf.int64, -1)
}
parsed = tf.parse_single_example(example, example_fmt)
image = tf.image.decode_image(parsed["image"])
# augments image using slice, reshape, resize_bilinear
# |
# |
# |
# v
image = _augment_helper(image)
return image, parsed["label"]
def input_fn():
files = tf.data.Dataset.list_files("/path/to/dataset/train-*.tfrecord")
dataset = files.interleave(tf.data.TFRecordDataset)
dataset = dataset.map(map_func=parse_fn)
# ...
return dataset
如果我在 input_fn
内执行数据增强,parse_fn
是否返回单个示例或包含原始输入图像 + 所有增强变体的批处理?如果它只返回一个[增强]示例,我如何确保数据集中的所有图像以及所有变体都以其未增强的形式使用?
最佳答案
如果您在数据集上使用迭代器,则您的 _augment_helper 函数将在输入的每个数据 block 上的数据集的每次迭代中被调用(就像您在 dataset.map 中调用 parse_fn 一样)
将代码更改为
ds_iter = dataset.make_one_shot_iterator()
ds_iter = ds_iter.get_next()
return ds_iter
我已经用一个简单的增强函数对此进行了测试
def _augment_helper(image):
print(image.shape)
image = tf.image.random_brightness(image,255.0, 1)
image = tf.clip_by_value(image, 0.0, 255.0)
return image
将 255.0 更改为数据集中的最大值,我使用 255.0 作为示例的数据集采用 8 位像素值
关于tensorflow - 如何在 Tensorflow Estimator 的 input_fn 中执行数据增强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51594027/
几个月前,我使用了tf.contrib.learn.DNNRegressor来自 TensorFlow 的 API,我发现它使用起来非常方便。最近几个月我没有跟上TensorFlow的发展。现在我有一
我们正在尝试将旧的训练代码转换为更符合 tf.estimator.Estimator 的代码。在初始代码中,我们针对目标数据集微调原始模型。在使用 variables_to_restore 和 ini
我目前运行的是 TensorFlow 1.9.0。我的自定义估算器是使用 tf.estimator.Estimator 创建的,并且运行时没有出现任何故障。但是,我在 model_dir 下没有找到任
我刚刚用 tensorflow 训练了一个 CNN 来识别太阳黑子。我的模型与 this 几乎相同.问题是我无法在任何地方找到关于如何使用训练阶段生成的检查点进行预测的明确解释。 尝试使用标准恢复方法
我正在尝试使用我自己的数据集和类对在 imagenet 上预训练的 Inception-resnet v2 模型进行迁移学习。我的原始代码库是对 tf.slim 的修改我再也找不到的示例,现在我正在尝
在 train(...) 完成后,如何从 tf.estimator.Estimator 获取最后一个 global_step ?例如,典型的基于估算器的训练例程可能如下设置: n_epochs = 1
一年多来我一直在使用自己的 Estimator/Experiment 之类的代码,但我最终想加入 Dataset+Estimator 的行列。 我想做如下的事情: for _ in range(N):
我正在考虑将我的代码库移动到 tf.estimator.Estimator ,但我找不到如何将它与张量板摘要结合使用的示例。 MWE: import numpy as np import tensor
我的印象是在 tf.estimator.Estimator 实例上调用 evaluate() 不会在多个 GPU 上运行模型,即使分配策略是 MirroredStrategy,配置为至少使用 2 个
我遇到了一些小问题,但我不知道如何处理。 当我使用 tf.estimator.Estimator 时,它会在每个步骤中记录两行,例如: INFO:tensorflow:global_step/sec:
在此tutorial ,他们通过为 tf.nn.softmax 节点命名成功地记录了 softmax 函数。 tf.nn.softmax(logits, name="softmax_tensor")
我发现 tensorflow train_and_evaluate 的工作方式与传统的 tf.estimator train 和 evaluate 相比有点不同。train_and_evaluate
我正在使用 tensorflow 版本 2.0.0-beta1。打电话时 tf.estimator.inputs.pandas_input_fn 它给了我一个错误。 module 'tensorflo
有没有办法在另一个模型 B 中使用经过 tf.estimator 训练的模型 A? 这是情况,假设我有一个训练有素的“模型 A”和 model_a_fn()。“模型 A”获取图像作为输入,并输出一些类
我正在尝试在本地运行对象检测 API。 我相信我已经按照 TensorFlow Object Detection API 中的描述设置了所有内容。但是,当我尝试运行 model_main.py 时,会
请原谅我的编码经验。我正在尝试使用 GridSearch 进行一系列回归。我正在尝试循环整个过程以使过程更快,但我的代码不够好并且不介意提高效率。这是我的代码: classifiers=[Lasso(
我在将纯 Keras 模型转换为不平衡数据集上的 TensorFlow Estimator API 时遇到了一些麻烦。 使用纯 Keras API 时,class_weight 参数在 model.f
当发生上述错误时,我经常使用有关估计器的tensorflow官方教程,而它在google.colab中正常运行。 我使用的环境是win10-64bit&tensorflow-gpu==1.12.0&p
Closed. This question is opinion-based。它当前不接受答案。 想要改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 已关闭6年。
Closed. This question is opinion-based。它当前不接受答案。 想要改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 1年前关闭。
我是一名优秀的程序员,十分优秀!