In [ ]:
#@title Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Update button links]
[Put all your imports and installs up into a setup section.]
In [ ]:
import tensorflow as tf
import tensorflow_addons as tfa
H1 header for the title.H1.
In [ ]:
# Build the model
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu', input_shape=(None, 5)),
tf.keras.layers.Dense(3)
])
Run the model on a single batch of data, and inspect the output:
In [ ]:
import numpy as np
result = model(tf.constant(np.random.randn(10,5), dtype = tf.float32)).numpy()
print("min:", result.min())
print("max:", result.max())
print("mean:", result.mean())
print("shape:", result.shape)
Compile the model for training:
In [ ]:
model.compile(optimizer=tf.keras.optimizers.Adam(),
loss=tf.keras.losses.categorical_crossentropy)
keras.Sequential > keras functional api > keras model subclassing > ...model.fit > model.train_on_batch > manual GradientTapes.tensorflow_datasets and tf.data where possible.compat.v1.