-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core\refac: #68 prepare bayesian optimization
- prepare unet arch for bayesian optimizer
- Loading branch information
Showing
4 changed files
with
158 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import keras.backend as K | ||
from keras.layers import Layer | ||
from tensorflow import Tensor | ||
|
||
|
||
class SparseSoftmax(Layer): | ||
"""Custom layer implementing the sparse softmax activation function.""" | ||
|
||
def _init_(self, name="SparseSoftmax", **kwargs): | ||
super()._init_(name=name, **kwargs) | ||
|
||
def call(self, inputs: Tensor) -> Tensor: # pylint: disable=arguments-differ | ||
e_x = K.exp(inputs - K.max(inputs, axis=-1, keepdims=True)) | ||
sum_e_x = K.sum(e_x, axis=-1, keepdims=True) | ||
output = e_x / (sum_e_x + K.epsilon()) | ||
return output |
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