2017-08-05 115 views

回答

0

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

enter image description here

  • 第一節點計算K.not_equal(weights, 0)
  • 第二個節點是K.cast(..., K.floatx())
  • 所有其他節點是約K.mean(...)
    • 左支計算批量大小(調用shape,並獲得維度0從它)
    • 右分支由左支路的輸出計算張量總和
    • 鴻溝右側分支的輸出
  • 該塊的最終輸出是標量K.mean(K.cast(K.not_equal(weights, 0), K.floatx()))