本文整理汇总了Python中cntk.reduce_mean方法的典型用法代码示例。如果您正苦于以下问题:Python cntk.reduce_mean方法的具体用法?Python cntk.reduce_mean怎么用?Python cntk.reduce_mean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cntk
的用法示例。
在下文中一共展示了cntk.reduce_mean方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _moments
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def _moments(x, axes=None, shift=None, keep_dims=False):
_axes = tuple(axes)
if shift is None:
shift = x
# Compute true mean while keeping the dims for proper broadcasting.
for axis in _axes:
shift = C.reduce_mean(shift, axis=axis)
shift = C.stop_gradient(shift)
shifted_mean = C.minus(x, shift)
for axis in _axes:
shifted_mean = C.reduce_mean(shifted_mean, axis=axis)
variance_mean = C.square(C.minus(x, shift))
for axis in _axes:
variance_mean = C.reduce_mean(variance_mean, axis=axis)
variance = C.minus(variance_mean, C.square(shifted_mean))
mean = C.plus(shifted_mean, shift)
if not keep_dims:
mean = squeeze(mean, _axes)
variance = squeeze(variance, _axes)
return mean, variance
示例2: test_reduce_mean
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def test_reduce_mean():
data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)
assert_cntk_ngraph_flat_equal(C.reduce_mean([1, 0], 0))
assert_cntk_ngraph_flat_equal(C.reduce_mean([[1., 1.], [3., 5.]], 0))
assert_cntk_ngraph_flat_equal(C.reduce_mean([[1., 1.], [3., 5.]], 1))
assert_cntk_ngraph_flat_equal(C.reduce_mean([[1., 1.], [3., 5.]], -1))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, 0))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, 1))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, 2))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, -1))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, (0, 1)))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, (0, 2)))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, (1, 2)))
assert_cntk_ngraph_flat_equal(C.reduce_mean(data, (-1, -2)))
示例3: mean
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def mean(x, axis=None, keepdims=False):
axis = _normalize_axis(axis, x)
output = _reduce_on_axis(x, axis, 'reduce_mean')
return _remove_dims(output, axis, keepdims)
示例4: classification_error
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def classification_error(target, output, axis=-1):
return C.ops.reduce_mean(
C.equal(
argmax(
output,
axis=-1),
argmax(
target,
axis=-1)),
axis=C.Axis.all_axes())
示例5: l2_loss
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def l2_loss(output, target):
return C.reduce_mean(C.square(output - target))
示例6: std_normalized_l2_loss
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def std_normalized_l2_loss(output, target):
std_inv = np.array([6.6864805402, 5.2904440280, 3.7165409939, 4.1421640454, 8.1537399389, 7.0312877415, 2.6712380967,
2.6372177876, 8.4253649884, 6.7482162880, 9.0849960354, 10.2624412692, 3.1325531319, 3.1091179819,
2.7337937590, 2.7336441031, 4.3542467871, 5.4896293687, 6.2003761588, 3.1290341469, 5.7677042738,
11.5460919611, 9.9926451700, 5.4259818848, 20.5060642486, 4.7692101480, 3.1681517575, 3.8582905289,
3.4222250436, 4.6828286809, 3.0070785113, 2.8936539301, 4.0649030157, 25.3068458731, 6.0030623160,
3.1151977458, 7.7773542649, 6.2057372469, 9.9494258692, 4.6865422850, 5.3300697628, 2.7722027974,
4.0658663003, 18.1101618617, 3.5390113731, 2.7794520068], dtype=np.float32)
weights = C.constant(value=std_inv) #.reshape((1, label_dim)))
dif = output - target
ret = C.reduce_mean(C.square(C.element_times(dif, weights)))
return ret
示例7: l1_reg_loss
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import reduce_mean [as 别名]
def l1_reg_loss(output):
# don't need C.abs(output), because output is already non-negative
# use abs() if your desired output could be negative
return C.reduce_mean(output)
#----------------------------------------
# create computational graph and learner
#----------------------------------------