在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()))