Last active
March 10, 2021 15:51
-
-
Save geoffreyvd/076e5129f4c1a01800c81644b72357db to your computer and use it in GitHub Desktop.
Straight through estimator for tensforflow/keras 2+
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
@tf.custom_gradient | |
def binairy_STE_after_sigmoid(x): | |
def grad(dy): | |
return dy | |
result = tf.round(x) | |
return result, grad | |
def model(): | |
output_dim = 1 | |
x = Dense(output_dim, activation='sigmoid')(x) | |
x = Lambda(binairy_STE_after_sigmoid)(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment