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


Python backend.set_value方法代码示例

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


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

示例1: reset_spikevars

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def reset_spikevars(self, sample_idx):
        """
        Reset variables present in spiking layers. Can be turned off for
        instance when a video sequence is tested.
        """

        mod = self.config.getint('simulation', 'reset_between_nth_sample')
        mod = mod if mod else sample_idx + 1
        do_reset = sample_idx % mod == 0
        if do_reset:
            k.set_value(self.mem, self.init_membrane_potential())
        k.set_value(self.time, np.float32(self.dt))
        zeros_output_shape = np.zeros(self.output_shape, k.floatx())
        if self.tau_refrac > 0:
            k.set_value(self.refrac_until, zeros_output_shape)
        if self.spiketrain is not None:
            k.set_value(self.spiketrain, zeros_output_shape)
        k.set_value(self.last_spiketimes, zeros_output_shape - 1) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:20,代码来源:ttfs.py

示例2: reset_spikevars

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def reset_spikevars(self, sample_idx):
        """
        Reset variables present in spiking layers. Can be turned off for
        instance when a video sequence is tested.
        """

        mod = self.config.getint('simulation', 'reset_between_nth_sample')
        mod = mod if mod else sample_idx + 1
        do_reset = sample_idx % mod == 0
        if do_reset:
            k.set_value(self.mem, self.init_membrane_potential())
        k.set_value(self.time, np.float32(self.dt))
        zeros_output_shape = np.zeros(self.output_shape, k.floatx())
        if self.tau_refrac > 0:
            k.set_value(self.refrac_until, zeros_output_shape)
        if self.spiketrain is not None:
            k.set_value(self.spiketrain, zeros_output_shape)
        k.set_value(self.last_spiketimes, zeros_output_shape - 1)
        k.set_value(self.v_thresh, zeros_output_shape + self._v_thresh)
        k.set_value(self.prospective_spikes, zeros_output_shape)
        k.set_value(self.missing_impulse, zeros_output_shape) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:23,代码来源:ttfs_dyn_thresh.py

示例3: _update_graph_variables

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def _update_graph_variables(self, learning_rate: float = None, momentum: float = None):
        """
        Update graph variables setting giving `learning_rate` and `momentum`

        Args:
            learning_rate: learning rate value to be set in graph (set if not None)
            momentum: momentum value to be set in graph (set if not None)

        Returns:
            None
        """
        if learning_rate is not None:
            K.set_value(self.get_learning_rate_variable(), learning_rate)
            # log.info(f"Learning rate = {learning_rate}")
        if momentum is not None:
            K.set_value(self.get_momentum_variable(), momentum)
            # log.info(f"Momentum      = {momentum}") 
开发者ID:deepmipt,项目名称:DeepPavlov,代码行数:19,代码来源:keras_model.py

示例4: reset_states

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def reset_states(self):
        for v in self.variables:
            K.set_value(v, 0) 
开发者ID:tech-srl,项目名称:code2vec,代码行数:5,代码来源:keras_words_subtoken_metrics.py

示例5: on_epoch_end

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def on_epoch_end (self, epoch, logs={}):
        if epoch >= self.kl_start_epoch - 2:
            new_kl_alpha = min(K.get_value(self.kl_alpha) + self.kl_alpha_increase_per_epoch, 1.)
            K.set_value(self.kl_alpha, new_kl_alpha)
        print ("Current KL Weight is " + str(K.get_value(self.kl_alpha))) 
开发者ID:sandialabs,项目名称:bcnn,代码行数:7,代码来源:utils.py

示例6: reset_states

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def reset_states(self):
        """Resets all of the metric state variables."""

        for v in self.variables:
            K.set_value(
                v,
                np.zeros((self.num_classes, self.num_classes), v.dtype.as_numpy_dtype),
            ) 
开发者ID:tensorflow,项目名称:addons,代码行数:10,代码来源:cohens_kappa.py

示例7: _set_model_layers

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def _set_model_layers(self, X, ts_sz, d, n_classes):
        super()._set_model_layers(X=X,
                                  ts_sz=ts_sz,
                                  d=d,
                                  n_classes=n_classes)
        K.set_value(self.model_.optimizer.lr, self.learning_rate) 
开发者ID:tslearn-team,项目名称:tslearn,代码行数:8,代码来源:shapelets.py

示例8: set_time

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def set_time(self, time):
        """Set simulation time variable.

        Parameters
        ----------

        time: float
            Current simulation time.
        """

        k.set_value(self.time, time) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:13,代码来源:ttfs.py

示例9: on_batch_end

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def on_batch_end(self, batch, logs):
        if self.iteration_id > self.start_iteration:
            # (1, 0)
            cosine_decay = 0.5 * (1 + np.cos(np.pi * (self.cycle_iteration_id / self.cycle_iterations)))
            decayed_lr = (self.max_lr - self.min_lr) * cosine_decay + self.min_lr
            K.set_value(self.model.optimizer.lr, decayed_lr)
            if self.cycle_iteration_id == self.cycle_iterations:
                self.cycle_iteration_id = 0
                self.cycle_iterations = int(self.cycle_iterations * self.t_mu)
            else:
                self.cycle_iteration_id = self.cycle_iteration_id + 1
            self.lrs.append(decayed_lr)
        elif self.iteration_id == self.start_iteration:
            self.max_lr = K.get_value(self.model.optimizer.lr)
        self.iteration_id += 1 
开发者ID:xuannianz,项目名称:EfficientDet,代码行数:17,代码来源:callbacks.py

示例10: on_train_begin

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def on_train_begin(self, logs={}):
        K.set_value(self.model.optimizer.lr, self.min_lr) 
开发者ID:xuannianz,项目名称:EfficientDet,代码行数:4,代码来源:callbacks.py

示例11: on_batch_begin

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def on_batch_begin(self, batch, logs):
        if self.iteration_id < self.iterations:
            lr = (self.max_lr - self.min_lr) / self.iterations * (self.iteration_id + 1) + self.min_lr
            K.set_value(self.model.optimizer.lr, lr)
        self.iteration_id += 1
        self.lrs.append(K.get_value(self.model.optimizer.lr)) 
开发者ID:xuannianz,项目名称:EfficientDet,代码行数:8,代码来源:callbacks.py

示例12: train_one_step

# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import set_value [as 别名]
def train_one_step(self, data_batch, step, training):
        dtn = self.dtn
        dtn_op = self.dtn_op
        image, dmap, labels = data_batch
        with tf.GradientTape() as tape:
            dmap_pred, cls_pred, route_value, leaf_node_mask, tru_loss, mu_update, eigenvalue, trace =\
                dtn(image, labels, True)

            # supervised feature loss
            depth_map_loss = leaf_l1_loss(dmap_pred, tf.image.resize(dmap, [32, 32]), leaf_node_mask)
            class_loss = leaf_l1_loss(cls_pred, labels, leaf_node_mask)
            supervised_loss = depth_map_loss + 0.001*class_loss

            # unsupervised tree loss
            route_loss = tf.reduce_mean(tf.stack(tru_loss[0], axis=0) * [1., 0.5, 0.5, 0.25, 0.25, 0.25, 0.25])
            uniq_loss  = tf.reduce_mean(tf.stack(tru_loss[1], axis=0) * [1., 0.5, 0.5, 0.25, 0.25, 0.25, 0.25])
            eigenvalue = np.mean(np.stack(eigenvalue, axis=0) * [1., 0.5, 0.5, 0.25, 0.25, 0.25, 0.25])
            trace = np.mean(np.stack(trace, axis=0) * [1., 0.5, 0.5, 0.25, 0.25, 0.25, 0.25])
            unsupervised_loss = 2*route_loss + 0.001*uniq_loss

            # total loss
            if step > 10000:
                loss = supervised_loss + unsupervised_loss
            else:
                loss = supervised_loss

        if training:
            # back-propagate
            gradients = tape.gradient(loss, dtn.variables)
            dtn_op.apply_gradients(zip(gradients, dtn.variables))

            # Update mean values for each tree node
            mu_update_rate = self.config.TRU_PARAMETERS["mu_update_rate"]
            mu = [dtn.tru0.project.mu, dtn.tru1.project.mu, dtn.tru2.project.mu, dtn.tru3.project.mu,
                  dtn.tru4.project.mu, dtn.tru5.project.mu, dtn.tru6.project.mu]
            for mu, mu_of_visit in zip(mu, mu_update):
                if step == 0:
                    update_mu = mu_of_visit
                else:
                    update_mu = mu_of_visit * mu_update_rate + mu * (1 - mu_update_rate)
                K.set_value(mu, update_mu)

        # leaf counts
        spoof_counts = []
        for leaf in leaf_node_mask:
            spoof_count = tf.reduce_sum(leaf[:, 0]).numpy()
            spoof_counts.append(int(spoof_count))

        _to_plot = [image, dmap, dmap_pred[0]]

        return depth_map_loss, class_loss, route_loss, uniq_loss, spoof_counts, eigenvalue, trace, _to_plot 
开发者ID:yaojieliu,项目名称:CVPR2019-DeepTreeLearningForZeroShotFaceAntispoofing,代码行数:53,代码来源:model.py


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