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


Python callbacks.Callback方法代码示例

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


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

示例1: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, filepath, epoch_interval, verbose=0):
        """
        In:
            filepath - formattable filepath; possibilities:
                * weights.{epoch:02d}
                * weights.{era:02d}
            epoch_interval - 
                number of epochs that must be passed from the previous saving
            verbose - if nonzero then print out information on stdout;
                by default 0
        """
        super(KerasCallback, self).__init__()
        self.filepath = filepath
        self.epoch_interval = epoch_interval
        self.verbose = verbose
        self.era = 0 
开发者ID:mateuszmalinowski,项目名称:visual_turing_test-tutorial,代码行数:18,代码来源:callbacks.py

示例2: process_item_worker_triplet

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def process_item_worker_triplet(worker_id, lock, shared_mem_X, shared_mem_y, jobs, results):
    # make sure augmentations are different for each worker
    np.random.seed()
    random.seed()

    while True:
        items, augs, training, predict = jobs.get()
        img_p1, one_hot_class_idx_p1, item_p1 = process_item(items[0], augs[0], training, predict)
        img_p2, one_hot_class_idx_p2, item_p2 = process_item(items[1], augs[1], training, predict)
        img_n1, one_hot_class_idx_n1, item_n1 = process_item(items[2], augs[2], training, predict)
        is_good_item = False
        if (one_hot_class_idx_p1 is not None) and (one_hot_class_idx_p2 is not None) and (one_hot_class_idx_n1 is not None):
            lock.acquire()
            shared_mem_X[worker_id,...,0] = img_p1
            shared_mem_X[worker_id,...,1] = img_p2
            shared_mem_X[worker_id,...,2] = img_n1
            is_good_item = True
        results.put((worker_id, is_good_item, (item_p1, item_p2, item_n1)))


# Callback to monitor accuracy on a per-batch basis 
开发者ID:antorsae,项目名称:landmark-recognition-challenge,代码行数:23,代码来源:train.py

示例3: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, filepath, validation_data=(), interval=1, mymil=False):
    super(Callback, self).__init__()
    self.interval = interval
    self.auc = 0
    self.X_val, self.y_val = validation_data
    self.filepath = filepath
    self.mymil = mymil 
开发者ID:wentaozhu,项目名称:deep-mil-for-whole-mammogram-classification,代码行数:9,代码来源:roc_auc.py

示例4: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, patience=float(50000), division_cst=10.0, epsilon=1e-03, verbose=1, epoch_checkpoints={41, 61}):
		super(Callback, self).__init__()
		self.patience = patience
		self.checkpoints = epoch_checkpoints
		self.wait = 0
		self.previous_score = 0.
		self.division_cst = division_cst
		self.epsilon = epsilon
		self.verbose = verbose
		self.iterations = 0 
开发者ID:ChihebTrabelsi,项目名称:deep_complex_networks,代码行数:12,代码来源:training.py

示例5: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, base_lr = 0.01, max_epoch = 150, power=0.9, verbose=1):
    super(Callback, self).__init__()
    self.max_epoch = max_epoch
    self.power = power
    self.verbose = verbose
    self.base_lr = base_lr 
开发者ID:Vladkryvoruchko,项目名称:PSPNet-Keras-tensorflow,代码行数:8,代码来源:callbacks.py

示例6: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, validation_generate, steps_per_epoch):
        super(Callback, self).__init__()
        self.validation_generate = validation_generate
        self.steps_per_epoch = steps_per_epoch 
开发者ID:moxiu2012,项目名称:PJ_NLP,代码行数:6,代码来源:train.py

示例7: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, monitor='val_acc', mode='max', value=0.92, verbose=0):
        super(Callback, self).__init__()
        self.monitor = monitor
        self.value = value
        self.verbose = verbose 
开发者ID:ambujraj,项目名称:hacktoberfest2018,代码行数:7,代码来源:DenseNet_CIFAR10.py

示例8: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, monitor='val_loss', value=0.1, verbose=0):
        super(Callback, self).__init__()
        self.monitor = monitor
        self.value = value
        self.verbose = verbose 
开发者ID:nlinc1905,项目名称:Convolutional-Autoencoder-Music-Similarity,代码行数:7,代码来源:03_autoencoding_and_tsne.py

示例9: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, monitor='acc', threshold=0.98, verbose=0):
        super(Callback, self).__init__()
        self.monitor = monitor
        self.threshold = threshold
        self.verbose = verbose
        self.improved = 0 
开发者ID:dsgissin,项目名称:DiscriminativeActiveLearning,代码行数:8,代码来源:models.py

示例10: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, valid_toks, valid_y, X_valid, padlen, idx2label, pred_dir='./predictions'):
        super(Callback, self).__init__()
        self.valid_toks = valid_toks
        self.valid_y = valid_y
        self.X_valid = X_valid
        self.padlen = padlen
        assert X_valid.shape[0] == padlen * len(valid_toks)
        self.window = X_valid.shape[1]

        self.idx2label = idx2label
        self.pred_dir = pred_dir
        try:
            os.makedirs(pred_dir)
        except:
            pass 
开发者ID:chop-dbhi,项目名称:twitter-adr-blstm,代码行数:17,代码来源:approximateMatch.py

示例11: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, output_dir, num_identities, batch_size=32, use_yale=False,
                 use_jaffe=False):
        """
        Constructor for a GenerateIntermediate object.

        Args:
            output_dir (str): Directory to save intermediate results in.
            num_identities (int): Number of identities in the training set.
        Args: (optional)
            batch_size (int): Batch size to use when generating images.
        """
        super(Callback, self).__init__()

        self.output_dir = output_dir
        self.num_identities = num_identities
        self.batch_size = batch_size
        self.use_yale = use_yale
        self.use_jaffe = use_jaffe

        self.parameters = dict()

        # Sweep through identities
        self.parameters['identity'] = np.eye(num_identities)

        if use_yale:
            # Use pose 0, lighting at 0deg azimuth and elevation
            self.parameters['pose'] = np.zeros((num_identities, NUM_YALE_POSES))
            self.parameters['lighting'] = np.zeros((num_identities, 4))
            for i in range(0, num_identities):
                self.parameters['pose'][i,0] = 0
                self.parameters['lighting'][i,1] = 1
                self.parameters['lighting'][i,3] = 1
        else:
            # Make all have neutral expressions, front-facing
            self.parameters['emotion'] = np.empty((num_identities, Emotion.length()))
            self.parameters['orientation'] = np.zeros((num_identities, 2))
            for i in range(0, num_identities):
                self.parameters['emotion'][i,:] = Emotion.neutral
                self.parameters['orientation'][i,1] = 1 
开发者ID:zo7,项目名称:deconvfaces,代码行数:41,代码来源:train.py

示例12: reset_accuracy

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def reset_accuracy(self, group=-1, save = False):
        self.accuracy_reached = False
        self.last_accuracies = np.zeros(AccuracyReset.N_BATCHES)
        self.last_accuracies_i = 0
        if group != -1 and save:
            self.model.save(
                self.filepath.format(group= group, epoch= self.epoch + 1), 
                overwrite=True)
        return

# Callback to monitor accuracy on a per-batch basis 
开发者ID:antorsae,项目名称:landmark-recognition-challenge,代码行数:13,代码来源:train.py

示例13: create_callbacks

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def create_callbacks(self, callback: Callable[[], None], tensor_board_log_directory: Path, net_directory: Path,
                         callback_step: int = 1, save_step: int = 1) -> List[Callback]:
        class CustomCallback(Callback):
            def on_epoch_end(self_callback, epoch, logs=()):
                if epoch % callback_step == 0:
                    callback()

                if epoch % save_step == 0 and epoch > 0:
                    mkdir(net_directory)

                    self.predictive_net.save_weights(str(net_directory / self.model_file_name(epoch)))

        tensorboard_if_running_tensorflow = [TensorBoard(
            log_dir=str(tensor_board_log_directory), write_images=True)] if backend.backend() == 'tensorflow' else []
        return tensorboard_if_running_tensorflow + [CustomCallback()] 
开发者ID:JuliusKunze,项目名称:speechless,代码行数:17,代码来源:net.py

示例14: __init__

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def __init__(self, validation_data=(), interval=10):
        super(Callback, self).__init__()

        self.interval = interval
        self.X_val, self.y_val = validation_data 
开发者ID:ikki407,项目名称:stacking,代码行数:7,代码来源:base.py

示例15: set_dimensions

# 需要导入模块: from keras import callbacks [as 别名]
# 或者: from keras.callbacks import Callback [as 别名]
def set_dimensions(self):
        """Locate given hyperparameters that are `space` choice declarations and add them to
        :attr:`dimensions`"""
        all_dimension_choices = []

        #################### Remap Extra Objects ####################
        if self.module_name == "keras":
            from keras.initializers import Initializer as KerasInitializer
            from keras.callbacks import Callback as KerasCB

            self.init_iter_attrs.append(lambda _p, _k, _v: isinstance(_v, KerasInitializer))
            self.extra_iter_attrs.append(lambda _p, _k, _v: isinstance(_v, KerasCB))

        #################### Collect Choice Dimensions ####################
        init_dim_choices = get_choice_dimensions(self.model_init_params, self.init_iter_attrs)
        extra_dim_choices = get_choice_dimensions(self.model_extra_params, self.extra_iter_attrs)
        fe_dim_choices = get_choice_dimensions(self.feature_engineer, self.fe_iter_attrs)

        for (path, choice) in init_dim_choices:
            choice._name = ("model_init_params",) + path
            all_dimension_choices.append(choice)

        for (path, choice) in extra_dim_choices:
            choice._name = ("model_extra_params",) + path
            all_dimension_choices.append(choice)

        for (path, choice) in fe_dim_choices:
            choice._name = ("feature_engineer",) + path
            all_dimension_choices.append(choice)

        self.dimensions = all_dimension_choices

        if self.module_name == "keras":
            self.model_extra_params = link_choice_ids(
                self.dummy_layers,
                self.dummy_compile_params,
                self.model_extra_params,
                self.dimensions,
            ) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:41,代码来源:protocol_core.py


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