This is a fast overview how to get an MNIST example running under TF Keras
If you just want to start with Tensorflow / Keras (especially if it is a scientific project), then you want to reconsider using Keras. In this case please check (& use) PyTorch.
Questions to [David Rotermund](mailto:davrot@uni-bremen.de)
## Data loader / Data generator
|||
|---|---|
| [keras.utils.Sequence](https://www.tensorflow.org/api_docs/python/tf/keras/utils/Sequence) | "Base object for fitting to a sequence of data, such as a dataset."|
| [tf.keras.utils.to_categorical](https://www.tensorflow.org/api_docs/python/tf/keras/utils/to_categorical) | "Converts a class vector (integers) to binary class matrix."|
To the pre-processing chain **self.data_augmentation** you can add other preprocessing layers which are then applied to the input before given to the network.
|[tf.keras.backend.clear_session](https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session) | "Resets all state generated by Keras."|
|[tf.keras.Sequential](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential) | "Sequential groups a linear stack of layers into a tf.keras.Model."|
|[network.add()](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#add) | "Adds a layer instance on top of the layer stack." |
|[tf.keras.layers.Conv2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D) | "2D convolution layer (e.g. spatial convolution over images)."|
|[tf.keras.layers.MaxPool2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPooling2D) | "Max pooling operation for 2D spatial data."|
|[tf.keras.layers.Flatten](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Flatten) | "Flattens the input. Does not affect the batch size."|
|[tf.keras.layers.Dense](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense) | "Just your regular densely-connected NN layer."|
|[network.compile()](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#compile) | "Configures the model for training."|
|[tf.keras.metrics.categorical_crossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/categorical_crossentropy) | "Computes the categorical crossentropy loss."|
|[tf.keras.optimizers.Adam](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adam) | "Optimizer that implements the Adam algorithm."|
|[network.fit() ](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#fit) | Trains the model for a fixed number of epochs (iterations on a dataset).|
|[network.summary()](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#summary) | "Prints a string summary of the network."|
|[network.save()](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#save) | "Saves the model to Tensorflow SavedModel or a single HDF5 file."|
|[padding](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D) | "One of "valid", "same" or "causal" (case-insensitive). "valid" means no padding. "same" results in padding with zeros evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input. "causal" results in causal (dilated) convolutions, e.g. output[t] does not depend on input[t+1:]. "|
|[use_bias](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D)| "Boolean, whether the layer uses a bias vector."|
|[activation](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D)| "Activation function to use. If you don't specify anything, no activation is applied (see [keras.activations](https://www.tensorflow.org/api_docs/python/tf/keras/activations))."|
[data_format](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D)| " A string, one of channels_last (default) or channels_first."|
|[tf.keras.models.load_model](https://www.tensorflow.org/api_docs/python/tf/keras/saving/load_model) | "Loads a model saved via model.save()."|
|[network.evaluate()](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#evaluate) | "Returns the loss value & metrics values for the model in test mode."|
print("Strongest reponse is at " + str(np.argmax(output_6.numpy())))
print("Correct output is " + str(np.argmax(the_target)))
```
## Extracting weight and bias
Here is one way to extract the weights and bias of the whole network. Alternatively you can use [get_weights](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer#get_weights) from [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) in combination with [get_layer](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#get_layer) of [tf.keras.Sequential](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential).
|[Activation](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Activation)| Applies an activation function to an output.|
|[AveragePooling1D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling1D)| Average pooling for temporal data.|
|[AveragePooling2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D)| Average pooling operation for spatial data.|
|[AveragePooling3D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling3D) |Average pooling operation for 3D data (spatial or spatio-temporal).|
|[BatchNormalization](https://www.tensorflow.org/api_docs/python/tf/keras/layers/BatchNormalization)| Layer that normalizes its inputs.|
|[Conv2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D) |2D convolution layer (e.g. spatial convolution over images).|
|[Conv3D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv3D)| 3D convolution layer (e.g. spatial convolution over volumes).|
|[Dense](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense)| Just your regular densely-connected NN layer.|
|[Dropout](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dropout) |Applies Dropout to the input.|
|[Flatten](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Flatten) |Flattens the input. Does not affect the batch size.|
|[MaxPooling1D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPooling1D)| Max pooling operation for 1D temporal data.|
|[MaxPooling2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPooling2D) |Max pooling operation for 2D spatial data.|
|[MaxPooling3D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPooling3D) |Max pooling operation for 3D data (spatial or spatio-temporal).|
|[SpatialDropout1D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/SpatialDropout1D) |Spatial 1D version of Dropout.|
|[SpatialDropout2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/SpatialDropout2D) |Spatial 2D version of Dropout.|
|[SpatialDropout3D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/SpatialDropout3D) |Spatial 3D version of Dropout.|
|[ZeroPadding1D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/ZeroPadding1D) |Zero-padding layer for 1D input (e.g. temporal sequence).|
|[ZeroPadding2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/ZeroPadding2D) |Zero-padding layer for 2D input (e.g. picture).|
|[ZeroPadding3D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/ZeroPadding3D) |Zero-padding layer for 3D data (spatial or spatio-temporal).|
|[CenterCrop](https://www.tensorflow.org/api_docs/python/tf/keras/layers/CenterCrop) |A preprocessing layer which crops images.|
|[RandomContrast](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomContrast) |A preprocessing layer which randomly adjusts contrast during training.|
|[RandomCrop](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomCrop) |A preprocessing layer which randomly crops images during training.|
|[RandomFlip](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomFlip) |A preprocessing layer which randomly flips images during training.|
|[RandomHeight](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomHeight)| A preprocessing layer which randomly varies image height during training.|
|[RandomRotation](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomRotation) |A preprocessing layer which randomly rotates images during training.|
|[RandomTranslation](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomTranslation) |A preprocessing layer which randomly translates images during training.|
|[RandomWidth](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomWidth) |A preprocessing layer which randomly varies image width during training.|
|[RandomZoom](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomZoom) |A preprocessing layer which randomly zooms images during training.|
|[Rescaling](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Rescaling) |A preprocessing layer which rescales input values to a new range.|
|[Resizing](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Resizing) |A preprocessing layer which resizes images.|
|[softmax(...)](https://www.tensorflow.org/api_docs/python/tf/keras/activations/softmax) |Softmax converts a vector of values to a probability distribution.|
|[BinaryCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/losses/BinaryCrossentropy) |Computes the cross-entropy loss between true labels and predicted labels.|
|[CategoricalCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/losses/CategoricalCrossentropy) |Computes the crossentropy loss between the labels and predictions.|
|[KLDivergence](https://www.tensorflow.org/api_docs/python/tf/keras/losses/KLDivergence) |Computes Kullback-Leibler divergence loss between y_true and y_pred.|
|[MeanAbsoluteError](https://www.tensorflow.org/api_docs/python/tf/keras/losses/MeanAbsoluteError) |Computes the mean of absolute difference between labels and predictions.|
|[MeanSquaredError](https://www.tensorflow.org/api_docs/python/tf/keras/losses/MeanSquaredError) |Computes the mean of squares of errors between labels and predictions.|
|[Poisson](https://www.tensorflow.org/api_docs/python/tf/keras/losses/Poisson) |Computes the Poisson loss between y_true and y_pred.|
|[SparseCategoricalCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/losses/SparseCategoricalCrossentropy) |Computes the crossentropy loss between the labels and predictions.|
|[Accuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Accuracy) | Calculates how often predictions equal labels.|
|[BinaryAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/BinaryAccuracy) | Calculates how often predictions match binary labels.|
|[BinaryCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/BinaryCrossentropy) | Computes the crossentropy metric between the labels and predictions.|
|[CategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/CategoricalAccuracy) | Calculates how often predictions match one-hot labels.|
|[CategoricalCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/CategoricalCrossentropy) | Computes the crossentropy metric between the labels and predictions.|
|[KLDivergence](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/KLDivergence) | Computes Kullback-Leibler divergence metric between y_true and y_pred.|
|[Mean](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Mean) | Computes the (weighted) mean of the given values.|
|[MeanAbsoluteError](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/MeanAbsoluteError) | Computes the mean absolute error between the labels and predictions.|
|[MeanSquaredError](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/MeanSquaredError) | Computes the mean squared error between y_true and y_pred.|
|[Poisson](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Poisson) | Computes the Poisson metric between y_true and y_pred.|
|[Precision](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Precision) | Computes the precision of the predictions with respect to the labels.|
|[RootMeanSquaredError](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/RootMeanSquaredError) | Computes root mean squared error metric between y_true and y_pred.|
|[SparseCategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/SparseCategoricalAccuracy) | Calculates how often predictions match integer labels.|
|[SparseCategoricalCrossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/SparseCategoricalCrossentropy) | Computes the crossentropy metric between the labels and predictions.|
|[SparseTopKCategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/SparseTopKCategoricalAccuracy) | Computes how often integer targets are in the top K predictions.|
|[Sum](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Sum) | Computes the (weighted) sum of the given values.|
|[TopKCategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/TopKCategoricalAccuracy)| Computes how often targets are in the top K predictions.|