TensorFlow per_image_standardization 与整个数据集的平均标准化

Posted

技术标签:

【中文标题】TensorFlow per_image_standardization 与整个数据集的平均标准化【英文标题】:TensorFlow per_image_standardization vs mean standardization across full dataset 【发布时间】:2019-06-06 21:42:41 【问题描述】:

我很好奇单独标准化每个图像与标准化整个数据集之间的区别。

我正在使用tensorflow/models/official/resnet,它是使用 tf.estimator 构建的。 tf 估计器支持生成 tf 数据集的输入管道函数。 Dataset 对象应用tf.image.per_image_standardization 操作,该操作通过从每个像素中减去图像本身的平均值来进行标准化并强制执行单位方差。

这与其他基于整个数据集的平均值对图像进行标准化的 ML 预处理不同,例如 sklearn.preprocessing.StandardScaler。

我很困惑这个输入管道的任何方面是否保留在从 tf.estimator.Estimator 导出的 tf SavedModel 中。

所以我想知道在通过 tf.contrib.predictor 或以任何其他 dnn 格式部署模型时,是否仍需要应用特征标准化。

即使我使用的是 per_image_standardization,我是否应该在数据集上应用标准化?如果是这样,我是否应该以某种方式从整个图像集中导出平均值,以便在为模型提供服务时服务器可以从整个数据集中获取平均值并以这种方式应用标准化?

【问题讨论】:

StandardScaler-type 不是唯一的选择;在Why do standardscaler and normalizer need different data input? 上查看最近的好答案。 【参考方案1】:

在 StandardScaler 中,我们进行特征标准化。在图像的情况下,我们可以通过考虑整个数据分布来进行逐像素归一化,但这没有帮助,因为分布的可变性。所以 per_image_standardization 是首选,它将整个图像归一化为均值 0 和标准 1。它还可以加快学习速度。

进一步this-link 可能会有所帮助。有another-link,作者已经举例说明了。

【讨论】:

感谢您的回答。我对如何在服务时使用 per_image_standardization 提供的相同操作感到有些困惑。例如,我正在构建一个 tf.Estimator,它有一个提供 tf.Dataset 的 input_fn,我在其上应用调用 per_image_standardization 的 map_and_batch。这将返回一个张量。但是当我导出模型时,没有导出相同的张量,因为输入管道不存在。我应该将 per_image_standardization 添加到 model_fn 吗?如果我这样做了,这个操作是否仍然可以转换为 caffe 作为计算图的一部分?

以上是关于TensorFlow per_image_standardization 与整个数据集的平均标准化的主要内容,如果未能解决你的问题,请参考以下文章

如何让 Tensorflow Profiler 在 Tensorflow 2.5 中使用“tensorflow-macos”和“tensorflow-metal”工作

python [test tensorflow] test tensorflow installation #tensorflow

关于tensorflow的显存占用问题

java调用tensorflow训练好的模型

tensorflow新手必看,tensorflow入门教程,tensorflow示例代码

tensorflow 如何在线训练模型