当前位置:   article > 正文

Keras的loss_weights和class_weight

loss_weights

loss_weights

model.compile的参数,对应于模型的每个输出的损失的权重。loss_weights是一个列表,对应于每个输出的权重,默认1.

  1. Model.compile(
  2. optimizer="rmsprop",
  3. loss=None,
  4. metrics=None,
  5. loss_weights=None,
  6. weighted_metrics=None,
  7. run_eagerly=None,
  8. steps_per_execution=None,
  9. **kwargs
  10. )
  • loss_weights: Optional list or dictionary specifying scalar coefficients (Python floats) to weight the loss contributions of different model outputs. The loss value that will be minimized by the model will then be the weighted sum of all individual losses, weighted by the loss_weights coefficients. If a list, it is expected to have a 1:1 mapping to the model's outputs. If a dict, it is expected to map output names (strings) to scalar coefficients.

class_weight

是model.fit的参数,对应于样本类别的权重,可以更加关注数量少得样本。

当数据集不平衡时,可以为每个类设置类权重。假设有 5000 个类狗样本和 45000 个类非狗样本,class_weight= [0:5,1:0.5],这给类"狗"10倍的权重作用在损失函数。

  1. Model.fit(
  2. x=None,
  3. y=None,
  4. batch_size=None,
  5. epochs=1,
  6. verbose="auto",
  7. callbacks=None,
  8. validation_split=0.0,
  9. validation_data=None,
  10. shuffle=True,
  11. class_weight=None,
  12. sample_weight=None,
  13. initial_epoch=0,
  14. steps_per_epoch=None,
  15. validation_steps=None,
  16. validation_batch_size=None,
  17. validation_freq=1,
  18. max_queue_size=10,
  19. workers=1,
  20. use_multiprocessing=False,
  21. )
  • class_weight: Optional dictionary mapping class indices (integers) to a weight (float) value, used for weighting the loss function (during training only). This can be useful to tell the model to "pay more attention" to samples from an under-represented class.

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/133356
推荐阅读
相关标签
  

闽ICP备14008679号