网站开发包含什么,太原新媒体运营公司,福田网络,宁波seo推广联系方法TensorFlow 提供了一些机器学习中常用的数学函数#xff0c;并封装在 Module 中#xff0c;例如 tf.nn Module 提供了神经网络常用的基本运算#xff0c;tf.math Module 则提供了机器学习中常用的数学函数。本文主要介绍 TensorFlow 深度学习中几个常用函数的定义与用法并封装在 Module 中例如 tf.nn Module 提供了神经网络常用的基本运算tf.math Module 则提供了机器学习中常用的数学函数。本文主要介绍 TensorFlow 深度学习中几个常用函数的定义与用法并给出相应用法示例。 目录
1 tf.nn.sigmoid
2 tf.nn.relu
3 tf.nn.softmax
4 tf.math.reduce_sum
5 tf.math.reduce_mean TensorFlow 提供了一些机器学习中常用的数学函数包括
基本的算术运算与三角函数复数运算例如 tf.math.imag, tf.math,angle 等Reduce 运算例如 tf.math.reduce_mean, tf.math.cumsum 等切片函数例如 tf.math.segment_sum 以下介绍几个 TensorFlow 中常用函数的用法。 1 tf.nn.sigmoid tf.nn.sigmoid 用于计算函数 的值用法为
tf.nn.sigmoid(x, nameNone)
其中 x 是一个 tf.Tensor 对象。 x tf.constant([-128., 0., 128.])
tf.nn.sigmoid(x).numpy()
输出array([0. , 0.5, 1. ], dtypefloat32) 2 tf.nn.relu tf.nn.relu 用于计算线性修正函数 的值, 用法为
tf.nn.relu(input_tensor, nameNone) relu tf.nn.relu([-2., 0., 3.])
relu.numpy()
输出array([0., 0., 3.], dtypefloat32) 3 tf.nn.softmax tf.nn.softmax 用于计算 softmax 函数值 用法为
tf.nn.softmax(input_tesnor, axisNone, nameNone)
其中 input_tesnor 是一个非空的 tf.Tensor 对象。 softmax tf.nn.softmax([-1., 0., 1.])
softmax.numpy()
输出array([0.09003057, 0.24472848, 0.66524094], dtypefloat32) sum(softmax).numpy()
输出1.0 4 tf.math.reduce_mean tf.math.reduce_mean 等同于 tf.reduce_mean, 用法为
tf.math.reduce_mean(input_tensor, axisNone, keepdimsFalse, nameNone) 如果 axis 值为 None则所有维度都被 reduced返回只包含 1 个元素的 tf.Tensor 对象。 x tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x).numpy()
输出1.5 tf.reduce_mean(x, 0).numpy()
输出array([1.5, 1.5], dtypefloat32) tf.reduce_mean(x, 1).numpy()
输出array([1., 2.], dtypefloat32) 5 tf.math.reduce_sum tf.math.reduce_sum 等同于 tf.reduce_sum, 用法为
tf.math.reduce_sum(input_tensor, axisNone, keepdimsFalse, nameNone)
x tf.constant([[1, 1, 1], [1, 1, 1]])
tf.reduce_sum(x).numpy()
输出6 tf.reduce_sum(x, 0).numpy()
输出array([2, 2, 2]) tf.reduce_sum(x, 1).numpy()
输出array([3, 3])