2017-08-05 112 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()))