【问题标题】:The proper way to normalize images for training in Tensorflow标准化图像以在 Tensorflow 中进行训练的正确方法
【发布时间】:2021-08-08 20:07:28
【问题描述】:

我想在预处理中标准化图像。现在我知道了两种常用的方法:

# 1. min-max
min_, max_ = tf.reduce_min(image), tf.reduce_max(image)
image = (image - min_) / (max_ - min_) + min_

# standardization
image = tf.image.per_image_standardization(image)

不过,我还是想知道

  • 如果我需要在上述操作旁边的[-1, 1] 内进一步规范化它?我读到这对训练也有好处。
  • 从泛化的角度来看,我们真的需要per_image_standardization这样的操作吗?我的意思是,神经网络不会自己学会适应这种环境吗?

【问题讨论】:

    标签: python tensorflow image-processing deep-learning


    【解决方案1】:

    据我所知,在将图像标准化到某个范围时,使用上述方法很少见,更常见的是这样

    import tensorflow as tf
    
    image_path = '/path/to/image'
    image_byte = tf.io.read_file(image_path)
    image = tf.io.decode_jpeg(image_byte)
    
    # Normalize image
    img_norm_0_to_1 = tf.cast(image, tf.float32) / 255. # [0 - 1] range
    img_norm_neg1_to_1 = (tf.cast(image, tf.float32) / 127.5) - 1.0 # [-1 to 1] range
    

    【讨论】:

    • 感谢您的回复。我同意你的意见。其实我一直在用和你描述的一样的方法,只是不确定是否正确。
    猜你喜欢
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 2016-09-17
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多