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