本文整理汇总了Python中keras.backend.epsilon方法的典型用法代码示例。如果您正苦于以下问题:Python backend.epsilon方法的具体用法?Python backend.epsilon怎么用?Python backend.epsilon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.backend的用法示例。
在下文中一共展示了backend.epsilon方法的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: call
点赞 6
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import epsilon [as 别名]
def call(self, x, mask=None):
# computes a probability distribution over the timesteps
# uses 'max trick' for numerical stability
# reshape is done to avoid issue with Tensorflow
# and 1-dimensional weights
logits = K.dot(x, self.W)
x_shape = K.shape(x)
logits = K.reshape(logits, (x_shape[0], x_shape[1]))
ai = K.exp(logits - K.max(logits, axis=-1, keepdims=True))
# masked timesteps have zero weight
if mask is not None:
mask = K.cast(mask, K.floatx())
ai = ai * mask
att_weights = ai / (K.sum(ai, axis=1, keepdims=True) + K.epsilon())
weighted_input = x * K.expand_dims(att_weights)
result = K.sum(weighted_input, axis=1)
if self.return_attention:
return [result, att_weights]
return result
开发者ID:minerva-ml,项目名称:steppy-toolkit,代码行数:22,
示例2: get_config
点赞 6
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import epsilon [as 别名]
def get_config(self):
config = {
'learning_rate': float(K_eval(self.learning_rate)),
'beta_1': float(K_eval(self.beta_1)),
'beta_2': float(K_eval(self.beta_2)),
'decay': float(K_eval(self.decay)),
'batch_size': int(self.batch_size),
'total_iterations': int(self.total_iterations),
'weight_decays': self.weight_decays,
'lr_multipliers': self.lr_multipliers,
'use_cosine_annealing': self.use_cosine_annealing,
't_cur': int(K_eval(self.t_cur)),
'eta_t': float(K_eval(self.eta_t)),
'eta_min': float(K_eval(self.eta_min)),
'eta_max': float(K_eval(self.eta_max)),
'init_verbose': self.init_verbose,
'epsilon': self.epsilon,
'amsgrad': self.amsgrad
}
base_config = super(AdamW, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
开发者ID:OverLordGoldDragon,项目名称:keras-adamw,代码行数:23,
示例3: get_config
点赞 6
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import epsilon [as 别名]
def get_config(self):
config = {
'lr': float(K.get_value(self.lr)),
'beta_1': float(K.get_value(self.beta_1)),
'beta_2': float(K.get_value(self.beta_2)),
'decay': float(K.get_value(self.decay)),
'batch_size': int(self.batch_size),
'total_iterations': int(self.total_iterations),
'weight_decays': self.weight_decays,
'lr_multipliers': self.lr_multipliers,
'use_cosine_annealing': self.use_cosine_annealing,
't_cur': int(K.get_value(self.t_cur)),
'eta_t': float(K.eval(self.eta_t)),
'eta_min': float(K.get_value(self.eta_min)),
'eta_max': float(K.get_value(self.eta_max)),
'init_verbose': self.init_verbose,
'epsilon': self.epsilon,
'amsgrad': self.amsgrad
}
base_config = super(AdamW, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
开发者ID:OverLordGoldDragon,项目名称:keras-adamw,代码行数:23,
示例4: call
点赞 6
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import epsilon [as 别名]
def call(self, x, mask=None):
uit = dot_product(x, self.W)
if self.bias:
uit += self.b
uit = K.tanh(uit)
ait = dot_product(uit, self.u)
a = K.exp(ait)
# apply mask after the exp. will be re-normalized next
if mask is not None:
# Cast the mask to floatX to avoid float64 upcasting in theano
a *= K.cast(mask, K.floatx())
# in some cases especially in the early stages of training the sum may be almost zero
# and this results in NaN's. A workaround is to add a very small positive number ε to the sum.
# a /= K.cast(K.sum(a, axis=1, keepdims=True), K.floatx())
a /= K.cast(K.sum(a, axis=1, keepdims=True) + K.epsilon(), K.floatx())
a = K.expand_dims(a)
weighted_input = x * a
return K.sum(weighted_input, axis=1)
开发者ID:Hsankesara,项目名称:DeepResearch,代码行数:26,
示例5: deprocess_image
点赞 6
# 需要导入模块: from keras imp