【问题标题】:How do I normalize an image in Tensorflow?如何在 Tensorflow 中标准化图像?
【发布时间】:2021-05-12 08:47:46
【问题描述】:

我正在尝试通过 0.5均值标准差标准化我的每个输入图像.

每个图像都表示为具有三个通道 (RGB) 的介于 0 和 1 之间的浮点数。

我知道 PyTorch 相当于我正在尝试做的事情是:

torchvision.transforms.Normalize([0.5, 0.5, 0.5], [0.5,0.5,0.5])

在 TensorFlow 中如何实现?

【问题讨论】:

    标签: tensorflow machine-learning computer-vision


    【解决方案1】:

    不知道使用 tensorflow 方法的具体细节,但要去做 在python中你可以使用下面的代码

    def fit_data(x, mean, sd):
        # x is the input array, mean is the desired mean, sd is the desired standard deviation
        import numpy as np
        import math
        shape=x.shape
        x= x.flatten ()
        y=np.zeros((x.shape[0]))
        total=0
        for i in x:
            total += i
        x_mean=total/x.shape[0]    
        s_sq=0
        for i in x:
            s_sq +=(i-x_mean)**2     
        s=math.sqrt(s_sq/x.shape[0])        
        for i,v in enumerate(x):
            y[i]=mean + (v-x_mean)*sd/s
        y=np.reshape(y, shape)    
        return y
    

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 2016-10-27
      • 2012-11-29
      • 2013-05-17
      相关资源
      最近更新 更多