当前位置: 首页>>代码示例>>Python>>正文


Python keras.callbacks方法代码示例

本文整理汇总了Python中tensorflow.keras.callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python keras.callbacks方法的具体用法?Python keras.callbacks怎么用?Python keras.callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.keras的用法示例。


在下文中一共展示了keras.callbacks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_callback_objects

# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import callbacks [as 别名]
def init_callback_objects(callbacks, logger):
    """
    Initialize a list of tf.keras/custom callback descriptors.

    Args:
        callbacks: List of callback descriptions. Each list entry should be
                   either a dictionary of the format
                   {"class_name": <name_of_CB_class>,
                   "kwargs": {<dict_with_kwargs>}}
                   ... or an already initialized callback object
                   (which will be skipped).
        logger:    A mpunet logger object logging to screen and/or file

    Returns:
        A list of initialized callbacks
    """
    from mpunet import callbacks as tcb

    cb_objs = []
    cb_dict = {}
    for i, callback in enumerate(callbacks):
        if not isinstance(callback, dict):
            # CB already initialized
            cb = callback
            kwargs = {"params": "?"}
            cls_name = callback.__class__.__name__
            start_from = 0
        else:
            kwargs = callback["kwargs"]
            cls_name = callback["class_name"]
            start_from = callback.get("start_from")
            if callback.get("pass_logger"):
                kwargs["logger"] = logger
            try:
                cb = getattr(tfcb, cls_name, None) or getattr(tcb, cls_name)
            except AttributeError as e:
                raise ValueError("No callback named %s" % cls_name) from e
            cb = cb(**kwargs)
        if start_from:
            logger("OBS: '%s' activates at epoch %i" % (cls_name, start_from))
            cb = DelayedCallback(callback=cb,
                                 start_from=start_from,
                                 logger=logger)
        cb_objs.append(cb)
        cb_dict[cls_name] = cb
        logger("[%i] Using callback: %s(%s)" % (i+1, cb.__class__.__name__,
                                                ", ".join(["%s=%s" % (a, kwargs[a]) for a in kwargs])))

    return cb_objs, cb_dict 
开发者ID:perslev,项目名称:MultiPlanarUNet,代码行数:51,代码来源:funcs.py


注:本文中的tensorflow.keras.callbacks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。