比较与tf.image.per_image_standardization的功能差异
tf.image.per_image_standardization
tf.image.per_image_standardization(
image
)
mindspore.dataset.vision.c_transforms.Normalize
class mindspore.dataset.vision.c_transforms.Normalize(
mean,
std
)
使用方式
TensorFlow:对图像进行标准化,均值和标准差将根据图像自动计算。
MindSpore:对图像进行标准化,均值和标准差通过参数输入。
代码示例
# The following implements Normalize with MindSpore.
import numpy as np
import mindspore.dataset as ds
image = np.random.random((28, 28, 3))
mean = list(np.mean(image, axis=(-1, -2, -3), keepdims=True))
std = np.std(image, axis=(-1, -2, -3), keepdims=True)
adjusted_stddev = list(np.maximum(std, 1.0 / np.sqrt(image.size)))
result = ds.vision.c_transforms.Normalize(mean, adjusted_stddev)(image)
print(result.mean())
# 0.0
print(result.std())
# 1.0
# The following implements per_image_standardization with TensorFlow.
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
image = tf.random.normal((28, 28, 3))
result = tf.image.per_image_standardization(image)
print(tf.math.reduce_mean(result))
# 0.0
print(tf.math.reduce_std(result))
# 1.0