335 Star 1.5K Fork 862

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
per_image_standardization.md 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
俞涵 提交于 2023-01-29 16:21 . add mindquantum and modify url

Function Differences with tf.image.per_image_standardization

tf.image.per_image_standardization

tf.image.per_image_standardization(
    image
)

For more information, see tf.image.per_image_standardization.

mindspore.dataset.vision.Normalize

class mindspore.dataset.vision.Normalize(
    mean,
    std,
    is_hwc
)

For more information, see mindspore.dataset.vision.Normalize.

Differences

TensorFlow: Normalize the image using mean and standard deviation calculated automatically from the image.

MindSpore: Normalize the image using the specified mean and standard deviation.

Code Example

# The following implements Normalize with MindSpore.
import numpy as np
import mindspore.dataset as ds

image = np.random.random((28, 28, 3))
mean = [np.mean(image, axis=(-1, -2, -3), keepdims=False)]
std = [np.std(image, axis=(-1, -2, -3), keepdims=False)]
adjusted_stddev = list(np.maximum(std, 1.0 / np.sqrt(image.size)))
result = ds.vision.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
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0.0-alpha

搜索帮助

53164aa7 5694891 3bd8fe86 5694891