當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。