当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python tf.keras.metrics.get用法及代码示例

检索 Keras 指标作为 function /Metric 类实例。

用法

tf.keras.metrics.get(
    identifier
)

参数

  • identifier 度量标识符。度量函数/类或度量配置字典或度量函数或度量类实例的无或字符串名称之一

返回

  • 作为 function /Metric 类实例的 Keras 指标。

抛出

  • ValueError 如果无法解释identifier

identifier 可能是度量函数或类的字符串名称。

metric = tf.keras.metrics.get("categorical_crossentropy")
type(metric)
<class 'function'>
metric = tf.keras.metrics.get("CategoricalCrossentropy")
type(metric)
<class '...keras.metrics.CategoricalCrossentropy'>

您还可以通过将包含 class_nameconfig 作为标识符的 dict 传递给该函数来指定度量的 config。另请注意,class_name 必须映射到 Metric

identifier = {"class_name":"CategoricalCrossentropy",
              "config":{"from_logits":True} }
metric = tf.keras.metrics.get(identifier)
type(metric)
<class '...keras.metrics.CategoricalCrossentropy'>

相关用法


注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.keras.metrics.get。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。