Loading

Quipoin Menu

Learn • Practice • Grow

deep-learning / TensorFlow Keras Basics
tutorial

TensorFlow Keras Basics

TensorFlow with Keras provides a high‑level API for building and training deep learning models. It is beginner‑friendly and widely used in production.

Sequential API (Simple Stack of Layers)

import tensorflow as tf

model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28,28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])

Compile and Train

model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

model.fit(X_train, y_train, epochs=5, batch_size=32, validation_split=0.2)

Functional API (For Complex Models)

Allows multiple inputs/outputs, shared layers, and non‑linear topology.
inputs = tf.keras.Input(shape=(784,))
x = tf.keras.layers.Dense(128, activation='relu')(inputs)
outputs = tf.keras.layers.Dense(10, activation='softmax')(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

Callbacks

Callbacks like `ModelCheckpoint`, `EarlyStopping`, and `TensorBoard` add functionality during training.
callbacks = [
tf.keras.callbacks.EarlyStopping(patience=3),
tf.keras.callbacks.ModelCheckpoint('best_model.h5', save_best_only=True)
]


Two Minute Drill
  • Keras Sequential API: simple stack of layers.
  • Compile with optimizer, loss, metrics.
  • Fit trains the model.
  • Functional API for complex architectures.
  • Callbacks for early stopping, checkpointing.

Need more clarification?

Drop us an email at career@quipoinfotech.com