TF.KERAS /// SEQUENTIAL API /// DENSE LAYERS /// MODEL.COMPILE /// MODEL.FIT /// TF.KERAS /// SEQUENTIAL API /// DENSE LAYERS /// MODEL.COMPILE ///

Intro To TensorFlow & Keras

Module 2: Core Architecture. Move beyond basic perceptrons and start building scalable Neural Networks using the industry standard Python frameworks.

keras_sandbox.py
1 / 10
12345
tf.Keras

Instructor:Deep Learning starts here. TensorFlow is the engine, and Keras is the high-level API that makes building neural networks intuitive.


Architecture Graph

UNLOCK LAYERS BY MASTERING CONCEPTS.

Core: Tensors

Tensors are multi-dimensional arrays optimized for GPU processing. They are the fundamental data structure flowing through a neural network.

Validation Loss Check

Why do we use Tensors instead of standard Python Lists?


AI Engineering Hub

Share Your Models

EPOCH 1

Built an image classifier? Getting strange loss curves? Drop your Colab notebooks in our Slack!

Demystifying TensorFlow & Keras

Author

Pascual Vila

Lead AI Instructor // Code Syllabus

"TensorFlow is the engine under the hood; Keras is the steering wheel." Understanding how these two interact is the first step in your Deep Learning journey.

What is TensorFlow?

Developed by Google Brain, TensorFlow is an open-source library for numerical computation and large-scale machine learning. At its core, it takes high-dimensional data arraysβ€”known as Tensorsβ€”and processes them through mathematical graphs.

Because matrix multiplications are computationally expensive, TensorFlow is designed to run computations in parallel across GPUs (Graphics Processing Units), vastly accelerating the training of Neural Networks.

Enter Keras: The High-Level API

Writing raw TensorFlow graph code can be tedious and complex. Keras acts as an interface for the TensorFlow library. It allows you to build models intuitively by stacking layers like LEGO blocks.

The most common way to build models in Keras is the Sequential API. It implies that your network is a linear stack of layers, where the output of one layer is passed directly as the input to the next.

The Compile-Fit Lifecycle

  • Building: Instantiating the model and adding layers (e.g., Dense, Dropout).
  • Compiling: Linking the model to an optimizer (the algorithm that updates the weights, like Adam) and a loss function (the mathematical formula that evaluates how "wrong" the model is).
  • Fitting: Executing the training loop with model.fit(). The model iteratively predicts, measures its loss, and updates its weights via backpropagation over a set number of epochs.

πŸ€– AI Engine Knowledge Base (FAQ)

What is the exact difference between TensorFlow and Keras?

TensorFlow is the underlying mathematical framework and engine that handles tensor operations, GPU acceleration, and gradient calculations. Keras is the high-level Python API wrapper that sits on top of TensorFlow, making it easier for developers to define and train neural networks using intuitive methods like `add()` and `compile()`. As of TensorFlow 2.0, Keras is tightly integrated as `tf.keras`.

How does the Sequential API work in Keras?

The Sequential API allows you to create models layer-by-layer for most problems. It represents a linear pipeline: data flows from the input layer, through hidden layers, directly to the output layer. It is not suitable for models with multiple inputs, multiple outputs, or branching layers (for those, you use the Keras Functional API).

model = Sequential()
model.add(Dense(32, activation='relu'))
model.add(Dense(10, activation='softmax'))
What do "Optimizer", "Loss", and "Epochs" mean?

- Loss: A mathematical penalty score indicating how bad the model's current predictions are compared to the true labels. Goal is to minimize it.

- Optimizer: The algorithm (e.g., SGD, Adam) that adjusts the neural network's internal weights based on the Loss to improve future predictions.

- Epochs: One complete iteration over the entire training dataset. If you have 1000 images and train for 5 epochs, the model sees those 1000 images five times.

Keras API Glossary

tf.constant
Creates an immutable multi-dimensional array (Tensor). The fundamental data building block.
Python Snippet
Sequential
A Keras API model that lets you stack layers linearly, one after another.
Python Snippet
Dense
A standard neural network layer where every neuron is connected to every neuron in the preceding layer.
Python Snippet
compile()
Configures the model for training by defining the loss function and the optimizer.
Python Snippet
fit()
Executes the training loop, passing the input data and labels through the network over defined epochs.
Python Snippet
evaluate()
Tests the trained model against unseen testing data to return the final loss and metrics.
Python Snippet