Created
November 17, 2018 19:07
-
-
Save hadifar/644bac6efa739c93f94bed25e7562aa0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Linear(tf.keras.Model): | |
def __init__(self): | |
super().__init__() | |
self.layer = LinearLayer() | |
def call(self, input): | |
output = self.layer(input) | |
return output | |
model = Linear() | |
optimizer = tf.train.GradientDescentOptimizer(1e-3) | |
for _ in range(10000): | |
with tf.GradientTape() as tape: | |
y_pred = model(X) | |
loss = tf.reduce_mean(tf.square(y_pred - y)) | |
grads = tape.gradient(loss, model.variables) | |
optimizer.apply_gradients(grads_and_vars=zip(grads, model.variables)) | |
print(model.variables) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment