-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
157 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
from keras.layers.core import Layer | ||
from keras import backend as K | ||
|
||
|
||
class Squash(Layer): | ||
def __init__(self,axis=-1,**kwargs): | ||
self.axis=axis | ||
super(Squash,self).__init__(**kwargs) | ||
def build(self,input_shape): | ||
super(Squash,self).build(input_shape) | ||
def call(self,inputs): | ||
def __init__(self, axis=-1, **kwargs): | ||
self.axis = axis | ||
super(Squash, self).__init__(**kwargs) | ||
|
||
def build(self, input_shape): | ||
super(Squash, self).build(input_shape) | ||
|
||
def call(self, inputs): | ||
s_squared_norm = K.sum(K.square(inputs), self.axis, keepdims=True) | ||
scale = s_squared_norm / (1 + s_squared_norm) / K.sqrt(s_squared_norm +1e-7) | ||
scale = s_squared_norm / (1 + s_squared_norm) / K.sqrt(s_squared_norm + 1e-7) | ||
return scale * inputs | ||
def compute_output_shape(self,input_shape): | ||
|
||
def compute_output_shape(self, input_shape): | ||
return input_shape | ||
|
||
def get_config(self): | ||
base_config=super(Squash,self).get_config() | ||
base_config['axis']=self.axis | ||
return base_config | ||
base_config = super(Squash, self).get_config() | ||
base_config['axis'] = self.axis | ||
return base_config | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.