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
| np.random.seed(2); tf.random.set_seed(5) | |
| def make_model(): | |
| # this constructs a keras Model. We use the functional API and add a custom | |
| # layer for demo purposes but a model of any complexity can be used here | |
| from tensorflow.keras import layers | |
| class CustomLayer(keras.layers.Layer): | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) |
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
| for epoch in range(epochs): | |
| print("\nStart of epoch %d" % (epoch,)) | |
| start_time = time.time() | |
| # Iterate over the batches of the dataset. | |
| for step, (x_batch_train, y_batch_train) in enumerate(train_dataset): | |
| with tf.GradientTape() as tape: | |
| logits = model(x_batch_train, training=True) | |
| loss_value = loss_fn(y_batch_train, logits) | |
| grads = tape.gradient(loss_value, model.trainable_weights) |
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
| # This was tested from tf-nightly 2.1.0.dev20191111 (Linux Ubuntu 18.04) | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| import seaborn as sns | |
| from scipy import stats | |
| import os | |
| import tensorflow as tf | |
| from tensorflow import keras |
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
| # https://github.com/tensorflow/tensorflow/issues/33150 | |
| import tensorflow as tf | |
| class Net(tf.keras.Model): | |
| def __init__(self): | |
| super(Net, self).__init__() | |
| self.l1 = tf.keras.layers.Dense(5) | |
| def call(self, x): | |
| return self.l1(x) |
NewerOlder