TensorFlow and Keras Tutorial
Learn TensorFlow and Keras step by step: 40 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Are TensorFlow and Keras? Learn what TensorFlow and Keras are, how Keras 3 fits in, what you can build with them, and how this course teaches them with runnable NumPy stand-ins.
- Installing and Your First Model Install TensorFlow 2 and Keras 3 with pip, check versions and GPU, then read a complete first model and rebuild its forward pass and parameter count in NumPy.
- How Neural Networks Learn Understand neurons, layers, loss and gradient descent, then train a tiny network on XOR with a NumPy stand-in before using Keras's compile and fit.
- The Keras Workflow and Backends Learn the end-to-end Keras workflow, how to pick the TensorFlow, JAX or PyTorch backend, what keras.ops is, and which model-building style to use.
- Data Basics for Keras Prepare data for Keras models: features and labels, train/validation/test splits, scaling, one-hot labels, shuffling and batching, with NumPy examples.
Tensors and Automatic Differentiation
- Tensors and Shapes Learn TensorFlow tensors: rank, shape and dtype, creating tensors, indexing, reshaping, stacking and converting to NumPy, with runnable NumPy stand-ins.
- Tensor Operations and Broadcasting Master tensor math for deep learning: element-wise operations, matmul, reductions with axis, softmax, argmax and broadcasting rules, with NumPy stand-ins.
- Variables and Data Types Learn why TensorFlow has tf.Variable for model weights, how assign works, how dtypes and tf.cast behave, and why float32 precision matters, with NumPy stand-ins.
- Automatic Differentiation Understand automatic differentiation: how tf.GradientTape records operations and computes gradients, plus a runnable reverse-mode autodiff built from scratch.
- Gradient Descent from Scratch Build gradient descent step by step: learning rate effects, mini-batches, a linear regression training loop in NumPy and the same custom loop in TensorFlow.
Building Models with Keras
- Building a Dense Layer from Scratch Build a Dense layer with forward and backward passes in NumPy, check its gradients, then map every piece to keras.layers.Dense and its arguments.
- Activation Functions Compare ReLU, leaky ReLU, sigmoid, tanh, softmax, GELU and swish in Keras: formulas, derivatives, output layer choices and how to use them in a model.
- The Sequential API Build Keras models with the Sequential API: Input, add(), summary(), naming layers, inspecting weights, when to use it, and a NumPy shape and parameter tracker.
- The Functional API Use the Keras Functional API to build models with multiple inputs and outputs, skip connections and shared layers, with a runnable NumPy graph stand-in.
- Initializers and Regularizers Learn how weight initialization (Glorot, He) keeps signals stable, how L1 and L2 regularizers shrink weights, and how to set both on Keras layers.
Training and Evaluation
- Loss Functions Choose and understand Keras losses: MSE, MAE, Huber, binary and categorical cross-entropy, from_logits, the p minus y gradient, with runnable NumPy versions.
- Optimizers Compare SGD, momentum, RMSprop, Adam and AdamW, set learning rates and schedules, clip gradients, and watch each optimizer run on a hard problem in NumPy.
- compile, fit, evaluate and predict Master the four Keras training methods: compile, fit with validation, evaluate and predict, read the History object, and rebuild them in a NumPy mini-framework.
- Metrics and Validation Measure Keras models honestly: accuracy traps, confusion matrix, precision, recall, F1, ROC AUC, regression metrics, validation splits and k-fold, in NumPy.
- Overfitting and Callbacks Detect and fight overfitting with dropout, early stopping, checkpoints and learning-rate callbacks in Keras, with runnable NumPy stand-ins for each idea.
Convolutional Networks
- How Convolution Works Understand the convolution operation behind CNNs: kernels, sliding windows, feature maps and edge detection, built from scratch in NumPy before using Keras Conv2D.
- Padding, Strides and Pooling Control CNN output sizes with padding and strides, use max and average pooling, and compute shapes with the output-size formula. NumPy demos and Keras Conv2D code.
- Building a CNN with Keras Build and train a convolutional network in Keras for image classification: stacking Conv2D and pooling, reading model.summary, counting parameters and avoiding overfitting.
- Augmentation and Transfer Learning Reduce CNN overfitting with data augmentation layers, reuse pretrained models with transfer learning, and fine-tune safely in Keras. Includes NumPy augmentation demos.
Sequences and Text
- Text Vectorization and Embeddings Turn text into numbers for neural networks: tokenization, vocabularies, padding, the Keras TextVectorization and Embedding layers, with plain Python and NumPy demos.
- Recurrent Neural Networks Learn how a recurrent neural network processes sequences step by step with a hidden state, build an RNN cell in NumPy, and use SimpleRNN in Keras with correct shapes.
- LSTM and GRU Layers Understand LSTM and GRU gates, build a gated cell in NumPy, count parameters, and use LSTM, GRU, Bidirectional and stacked recurrent layers in Keras models.
- Attention and Transformers Learn scaled dot-product attention, multi-head self-attention, positional encoding and the Transformer encoder block, with NumPy demos and Keras MultiHeadAttention code.
Data Pipelines and Saving Models
- tf.data Pipelines Build fast input pipelines with tf.data: from_tensor_slices, map, shuffle, batch, cache and prefetch. Includes plain-Python stand-ins that show how each step behaves.
- Loading Images and Text Datasets Load datasets from disk for Keras: image_dataset_from_directory, text_dataset_from_directory, CSV data, TFRecord files and train/validation splits, with Python stand-ins.
- Saving and Loading Models Save and restore Keras models: the .keras format, weights-only files, checkpoints, custom objects, SavedModel export and what is stored, with a NumPy weights round trip.
- Deploying Models Take a trained Keras model to production: export a SavedModel, serve it over REST with TensorFlow Serving, convert to TFLite, and understand quantization with NumPy demos.
Advanced Topics
- Custom Layers and Models Write your own Keras layers and models by subclassing: build(), call(), add_weight, get_config, custom losses and metrics, plus a NumPy layer class that mirrors the pattern.
- Custom Training Loops Write your own training loop with tf.GradientTape, override train_step, use tf.function and metrics, and see the loop's structure with a NumPy gradient descent stand-in.
- Mixed Precision and Distributed Training Train faster with mixed precision (float16, loss scaling) and scale across GPUs with tf.distribute strategies. NumPy demos of float16 limits and data-parallel gradient averaging.
- Autoencoders and GANs Learn autoencoders for compression and denoising and GANs for generating data: encoder, bottleneck, generator, discriminator and the training loop, with NumPy demos.
Projects and Practice
- Project: Image Classifier Build an image classifier end to end: data split, baseline, CNN with augmentation, evaluation with a confusion matrix, error analysis and export, with a runnable NumPy mini version.
- Project: Sentiment Classifier Build a movie-review style sentiment classifier: text preprocessing, bag-of-words baseline, Keras embedding and LSTM models, metrics beyond accuracy and error analysis.
- Project: Time Series Forecasting Forecast a seasonal time series: chronological splits, sliding windows, naive and linear baselines, normalization without leakage, then Keras Dense, LSTM and multi-step models.
- Practice and Troubleshooting A debugging playbook for TensorFlow and Keras: overfit one batch, shape errors, NaN losses, learning-rate checks and learning curves, plus exercises and interview questions.