本文整理匯總了Python中cntk.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Python cntk.sqrt方法的具體用法?Python cntk.sqrt怎麽用?Python cntk.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cntk
的用法示例。
在下文中一共展示了cntk.sqrt方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: batch_normalization
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def batch_normalization(x, mean, var, beta, gamma, axis=-1, epsilon=1e-3):
# The mean / var / beta / gamma may be processed by broadcast
# so it may have an extra batch axis with 1, it is not needed
# in cntk, need to remove those dummy axis.
if ndim(mean) == ndim(x) and shape(mean)[0] == 1:
mean = _reshape_dummy_dim(mean, [0])
if ndim(var) == ndim(x) and shape(var)[0] == 1:
var = _reshape_dummy_dim(var, [0])
if gamma is None:
gamma = ones_like(var)
elif ndim(gamma) == ndim(x) and shape(gamma)[0] == 1:
gamma = _reshape_dummy_dim(gamma, [0])
if beta is None:
beta = zeros_like(mean)
elif ndim(beta) == ndim(x) and shape(beta)[0] == 1:
beta = _reshape_dummy_dim(beta, [0])
return (x - mean) / C.sqrt(var + epsilon) * gamma + beta
示例2: _layer_BatchNorm
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def _layer_BatchNorm(self):
self.add_body(0, """
def batch_normalization(input, name, epsilon, **kwargs):
mean = cntk.Parameter(init = __weights_dict[name]['mean'],
name = name + "_mean")
var = cntk.Parameter(init = __weights_dict[name]['var'],
name = name + "_var")
layer = (input - mean) / cntk.sqrt(var + epsilon)
if 'scale' in __weights_dict[name]:
scale = cntk.Parameter(init = __weights_dict[name]['scale'],
name = name + "_scale")
layer = scale * layer
if 'bias' in __weights_dict[name]:
bias = cntk.Parameter(init = __weights_dict[name]['bias'],
name = name + "_bias")
layer = layer + bias
return layer
""")
示例3: batch_normalization
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def batch_normalization(x, mean, var, beta, gamma, epsilon=1e-3):
# The mean / var / beta / gamma may be processed by broadcast
# so it may have an extra batch axis with 1, it is not needed
# in cntk, need to remove those dummy axis.
if ndim(mean) == ndim(x) and shape(mean)[0] == 1:
mean = _reshape_dummy_dim(mean, [0])
if ndim(var) == ndim(x) and shape(var)[0] == 1:
var = _reshape_dummy_dim(var, [0])
if gamma is None:
gamma = ones_like(var)
elif ndim(gamma) == ndim(x) and shape(gamma)[0] == 1:
gamma = _reshape_dummy_dim(gamma, [0])
if beta is None:
beta = zeros_like(mean)
elif ndim(beta) == ndim(x) and shape(beta)[0] == 1:
beta = _reshape_dummy_dim(beta, [0])
return (x - mean) / (C.sqrt(var) + epsilon) * gamma + beta
示例4: batch_normalization
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def batch_normalization(x, mean, var, beta, gamma, epsilon=1e-3):
# The mean / var / beta / gamma may be processed by broadcast
# so it may have an extra batch axis with 1, it is not needed
# in cntk, need to remove those dummy axis.
if ndim(mean) == ndim(x) and shape(mean)[0] == 1:
mean = _reshape_dummy_dim(mean, [0])
if ndim(var) == ndim(x) and shape(var)[0] == 1:
var = _reshape_dummy_dim(var, [0])
if gamma is None:
gamma = ones_like(var)
elif ndim(gamma) == ndim(x) and shape(gamma)[0] == 1:
gamma = _reshape_dummy_dim(gamma, [0])
if beta is None:
beta = zeros_like(mean)
elif ndim(beta) == ndim(x) and shape(beta)[0] == 1:
beta = _reshape_dummy_dim(beta, [0])
return gamma * ((x - mean) / C.sqrt(var + epsilon)) + beta
示例5: test_sqrt
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def test_sqrt():
assert_cntk_ngraph_isclose(C.sqrt([0., 4.]))
assert_cntk_ngraph_isclose(C.sqrt([[1, 2], [3, 4]]))
assert_cntk_ngraph_isclose(C.sqrt([[[1, 2], [3, 4]], [[1, 2], [3, 4]]]))
示例6: std
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def std(x, axis=None, keepdims=False):
return C.sqrt(var(x, axis=axis, keepdims=keepdims))
示例7: sqrt
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def sqrt(x):
return C.sqrt(x)
示例8: l2_normalize
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import sqrt [as 別名]
def l2_normalize(x, axis=None):
axis = [axis]
axis = _normalize_axis(axis, x)
norm = C.sqrt(C.reduce_sum(C.square(x), axis=axis[0]))
return x / norm