本文整理汇总了Python中tensorflow.python.ops.gen_math_ops._sqrt_grad方法的典型用法代码示例。如果您正苦于以下问题:Python gen_math_ops._sqrt_grad方法的具体用法?Python gen_math_ops._sqrt_grad怎么用?Python gen_math_ops._sqrt_grad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.gen_math_ops
的用法示例。
在下文中一共展示了gen_math_ops._sqrt_grad方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _SqrtGrad
# 需要导入模块: from tensorflow.python.ops import gen_math_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_math_ops import _sqrt_grad [as 别名]
def _SqrtGrad(op, grad):
y = op.outputs[0] # y = x^(1/2)
return gen_math_ops._sqrt_grad(y, grad)
示例2: testGradGrad
# 需要导入模块: from tensorflow.python.ops import gen_math_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_math_ops import _sqrt_grad [as 别名]
def testGradGrad(self):
np.random.seed(7)
shape = (5,)
dtype_tols = [(np.float32, 5e-4), (np.float64, 1e-6), (np.complex64, 5e-4),
(np.complex128, 1e-6)]
op_range = [(gen_math_ops._inv_grad, [-2, 2]),
(gen_math_ops._rsqrt_grad, [0.1, 3]),
(gen_math_ops._sigmoid_grad, [-2, 2]),
(gen_math_ops._sqrt_grad, [0.1, 3]),
(gen_math_ops._tanh_grad, [-2, 2]),]
def rand(dtype):
x = np.random.uniform(
real_range[0], real_range[1], size=shape[0]).astype(dtype)
if dtype in (np.complex64, np.complex128):
x += 1j * np.random.uniform(-2, 2, size=shape[0]).astype(dtype)
return x
for op, real_range in op_range:
with self.test_session():
for dtype, tol in dtype_tols:
x = tf.constant(rand(dtype))
y = tf.constant(rand(dtype))
z = op(x, y)
grads = tf.test.compute_gradient(
[x, y], [shape, shape],
z,
shape,
x_init_value=[rand(dtype), rand(dtype)])
if isinstance(grads, tuple):
grads = [grads]
for analytical, numerical in grads:
self.assertAllClose(analytical, numerical, rtol=tol, atol=tol)
示例3: _SqrtGrad
# 需要导入模块: from tensorflow.python.ops import gen_math_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_math_ops import _sqrt_grad [as 别名]
def _SqrtGrad(op, grad):
y = op.outputs[0] # y = x^(1/2)
# pylint: disable=protected-access
return gen_math_ops._sqrt_grad(y, grad)
# pylint: enable=protected-access
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:7,代码来源:math_grad.py