📌 1. Model Training
Training is the process where a machine learning model learns patterns from data.
🔄 Steps in Training
- Data Preparation
- Split data into training, validation, and test sets.
- Preprocess (normalize, encode, clean).
- Initialization
- Model starts with random parameters (weights & biases).
- Forward Propagation
- Input data passes through the model → generates predictions.
- Loss Calculation
- Compute error between predictions and actual labels using a loss function.
- Backward Propagation (Backpropagation)
- Compute gradients of loss w.r.t. model parameters.
- Parameter Update
- Use Gradient Descent (or variants like Adam, RMSProp) to adjust weights.
- Repeat (Epochs)
- Continue until the model’s performance converges.
👉 Goal: Find the set of parameters that minimize loss and generalize well.
📌 2. Model Inference
Inference is the process of using the trained model to make predictions on new, unseen data.
🔄 Steps in Inference
- Input new data.
- Forward propagate through the trained network.
- Output prediction (class label, probability, value, etc.).
👉 Goal: Deploy the model to make real-world predictions.
⚖️ Training vs Inference
Aspect | Training | Inference |
---|---|---|
Purpose | Learn from data | Make predictions |
Data | Labeled training data | New, unseen data |
Computational Cost | High (requires GPUs/TPUs) | Lower (can run on CPUs or edge devices) |
Adjusts Parameters? | ✅ Yes (weights updated) | ❌ No (weights fixed) |
Speed | Slow (epochs, iterations) | Fast (real-time possible) |
🚀 Example: Image Classification with CNN
- Training: CNN learns features (edges, shapes, objects) from labeled images (cat 🐱 vs dog 🐶).
- Inference: Given a new photo, the CNN predicts whether it’s a cat or dog.
💡 Optimization for Inference (Deployment Stage)
Since inference often happens in real-world apps (mobile, IoT, servers), models may be optimized by:
- Quantization → reduce precision (FP32 → INT8).
- Pruning → remove unnecessary weights.
- Knowledge Distillation → use smaller models trained from larger ones.
- Hardware Acceleration → GPUs, TPUs, NPUs for faster predictions.
📖 Analogy:
- Training = Teaching a student with textbooks, tests, and practice.
- Inference = The student answering questions in an exam using learned knowledge.