mirror of
https://github.com/wassname/keras-contrib.git
synced 2026-08-03 13:00:13 +08:00
28 lines
520 B
Python
28 lines
520 B
Python
from __future__ import absolute_import
|
|
from . import backend as K
|
|
from keras.utils.generic_utils import get_from_module
|
|
|
|
from keras.constraints import *
|
|
|
|
|
|
class Clip(Constraint):
|
|
"""Clips weights to [-c, c].
|
|
|
|
# Arguments
|
|
c: Clipping parameter.
|
|
"""
|
|
|
|
def __init__(self, c=0.01):
|
|
self.c = c
|
|
|
|
def __call__(self, p):
|
|
return K.clip(p, -self.c, self.c)
|
|
|
|
def get_config(self):
|
|
return {'name': self.__class__.__name__,
|
|
'c': self.c}
|
|
|
|
# Aliases.
|
|
|
|
clip = Clip
|