在Keras,损失计算,样本权重和损失的权重被应用到丢失后,看到这些线路中的脚本training.py。
样品重量:
score_array = K.mean(score_array, axis=list(range(weight_ndim, ndim)))
score_array *= weights
score_array /= K.mean(K.cast(K.not_equal(weights, 0), K.floatx()))
return K.mean(score_array)
失重:
if total_loss is None:
total_loss = loss_weight * output_loss
这是简单的将这些行映射回计算图形。例如,下面的块计算K.mean(K.cast(K.not_equal(weights, 0), K.floatx()))
:

- 第一节点计算
K.not_equal(weights, 0)
- 第二个节点是
K.cast(..., K.floatx())
- 所有其他节点是约
K.mean(...)
- 左支计算批量大小(调用
shape
,并获得维度0
从它)
- 右分支由左支路的输出计算张量总和
- 鸿沟右侧分支的输出
- 该块的最终输出是标量
K.mean(K.cast(K.not_equal(weights, 0), K.floatx()))