def __call__(self, w): maximum_weight = K.max(K.abs(w)) w = w / (K.epsilon() + maximum_weight) # On [-1,1]. signs = K.sign(w) unsigned_w = K.abs(w) # On [0,1]. edge_scaled_w_unsigned = unsigned_w * ( 1. - self.min_value) + self.min_value # On [min_value,1]. edge_scaled_w = signs * edge_scaled_w_unsigned # On [-1,-min_value] U [min_value,1]. return edge_scaled_w
def __call__(self, w): # First apply DivideByMax. maximum_weight = K.max(K.abs(w)) w = w / (K.epsilon() + maximum_weight) # On [-1, 1]. # Then apply MinMaxNorm. norms = K.sqrt( math_ops.reduce_sum(math_ops.square(w), axis=self.axis, keepdims=True)) desired = (self.rate * K.clip(norms, self.min_value, self.max_value) + (1 - self.rate) * norms) return w * (desired / (K.epsilon() + norms))
def softmax(x, axis=-1): """Softmax activation function. Arguments: x : Tensor. axis: Integer, axis along which the softmax normalization is applied. Returns: Tensor, output of softmax transformation. Raises: ValueError: In case `dim(x) == 1`. """ ndim = K.ndim(x) if ndim == 2: return K.softmax(x) elif ndim > 2: e = K.exp(x - K.max(x, axis=axis, keepdims=True)) s = K.sum(e, axis=axis, keepdims=True) return e / s else: raise ValueError('Cannot apply softmax to a tensor that is 1D')
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5): return K.mean(K.in_top_k(y_pred, K.cast(K.max(y_true, axis=-1), 'int32'), k), axis=-1)
def sparse_categorical_accuracy(y_true, y_pred): return K.cast( K.equal( K.max(y_true, axis=-1), K.cast(K.argmax(y_pred, axis=-1), K.floatx())), K.floatx())
def call(self, inputs): if self.data_format == 'channels_last': return K.max(inputs, axis=[1, 2, 3]) else: return K.max(inputs, axis=[2, 3, 4])
def call(self, inputs): return K.max(inputs, axis=1)
def call(self, inputs): if self.data_format == 'channels_last': return K.max(inputs, axis=[1, 2, 3]) else: return K.max(inputs, axis=[2, 3, 4])
def call(self, inputs): return K.max(inputs, axis=1)
def categorical_hinge(y_true, y_pred): pos = K.sum(y_true * y_pred, axis=-1) neg = K.max((1. - y_true) * y_pred, axis=-1) return K.maximum(neg - pos + 1., 0.)
def call(self, inputs): return backend.max(inputs, axis=1)
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5): return K.mean(K.in_top_k(y_pred, K.cast(K.max(y_true, axis=-1), 'int32'), k), axis=-1)
def sparse_categorical_accuracy(y_true, y_pred): return K.cast( K.equal(K.max(y_true, axis=-1), K.cast(K.argmax(y_pred, axis=-1), K.floatx())), K.floatx())
def call(self, inputs): return backend.max(inputs, axis=1)
def __call__(self, w): maximum_weight = K.max(K.abs(w)) return w / (K.epsilon() + maximum_weight)