本文整理匯總了Python中cntk.element_times方法的典型用法代碼示例。如果您正苦於以下問題:Python cntk.element_times方法的具體用法?Python cntk.element_times怎麽用?Python cntk.element_times使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cntk
的用法示例。
在下文中一共展示了cntk.element_times方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SmoothL1Loss
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import element_times [as 別名]
def SmoothL1Loss(sigma, bbox_pred, bbox_targets, bbox_inside_weights, bbox_outside_weights):
"""
From https://github.com/smallcorgi/Faster-RCNN_TF/blob/master/lib/fast_rcnn/train.py
ResultLoss = outside_weights * SmoothL1(inside_weights * (bbox_pred - bbox_targets))
SmoothL1(x) = 0.5 * (sigma * x)^2, if |x| < 1 / sigma^2
|x| - 0.5 / sigma^2, otherwise
"""
sigma2 = sigma * sigma
inside_mul_abs = C.abs(C.element_times(bbox_inside_weights, C.minus(bbox_pred, bbox_targets)))
smooth_l1_sign = C.less(inside_mul_abs, 1.0 / sigma2)
smooth_l1_option1 = C.element_times(C.element_times(inside_mul_abs, inside_mul_abs), 0.5 * sigma2)
smooth_l1_option2 = C.minus(inside_mul_abs, 0.5 / sigma2)
smooth_l1_result = C.plus(C.element_times(smooth_l1_option1, smooth_l1_sign),
C.element_times(smooth_l1_option2, C.minus(1.0, smooth_l1_sign)))
return C.element_times(bbox_outside_weights, smooth_l1_result)
示例2: test_element_times_1
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import element_times [as 別名]
def test_element_times_1():
cntk_op = C.element_times([1, 2, 3], [4, 5, 6])
cntk_ret = cntk_op.eval()
ng_op, _ = CNTKImporter().import_model(cntk_op)
ng_ret = ng.transformers.make_transformer().computation(ng_op)()
assert np.array_equal(cntk_ret, ng_ret)
示例3: test_element_times_2
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import element_times [as 別名]
def test_element_times_2():
cntk_op = C.element_times([[1, 2, 3], [4, 5, 6]], [7, 8, 9])
cntk_ret = cntk_op.eval()
ng_op, _ = CNTKImporter().import_model(cntk_op)
ng_ret = ng.transformers.make_transformer().computation(ng_op)()
assert np.array_equal(cntk_ret, ng_ret)
示例4: test_element_times_3
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import element_times [as 別名]
def test_element_times_3():
cntk_op = C.element_times([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
cntk_ret = cntk_op.eval()
ng_op, _ = CNTKImporter().import_model(cntk_op)
ng_ret = ng.transformers.make_transformer().computation(ng_op)()
assert np.array_equal(cntk_ret, ng_ret)
示例5: std_normalized_l2_loss
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import element_times [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