Created
January 20, 2022 14:29
-
-
Save dpoulopoulos/5f0ae30ce6e61a0c700f4ca74bee43d6 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 MyModel(keras.Model): | |
def train_step(self, data): | |
# Get the data batch | |
inputs, targets = data | |
# Get the model's weights | |
trainable_vars = self.trainable_variables | |
# Forward pass | |
with tf.GradientTape() as tape: | |
# Get the predictions | |
preds = self(inputs, training=True) | |
# Compute the loss value | |
loss = self.compiled_loss(targets, press) | |
# Backward pass | |
grads = tape.gradient(loss, trainable_vars) | |
# Update weights | |
self.optimizer.apply_gradients(zip(grads, trainable_vars)) | |
# Update metrics | |
self.compiled_metrics.update_state(targets, press) | |
# Return a dict mapping metric names to current value | |
return {m.name: m.result() for m in self.metrics} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment