An educational PyTorch experiment demonstrating how a neural network can learn new classes without forgetting previously learned ones.
This project explores Incremental Learning using the Learning without Forgetting (LwF) approach.
Instead of retraining from scratch when new classes arrive, we retain knowledge from the old model while adapting to new data β reducing catastrophic forgetting.
The experiment is implemented in PyTorch and applied to a subset of the Animal Image Dataset (Kaggle).
-
Stage 1 β Initial Training:
Train a ResNet-18 model on 3 animal classes:cow,donkey, andsheep. -
Stage 2 β Incremental Learning:
Introduce a new classhorseand fine-tune the model using LwF to preserve old knowledge. -
Knowledge Distillation:
Combine standard classification loss with a distillation loss that aligns new model outputs with those of the frozen old model.
| Component | Description |
|---|---|
| Backbone | Pretrained ResNet-18 (ImageNet weights) |
| Optimizer | Adam |
| Initial Learning Rate | 0.001 |
| Incremental Learning Rate | 0.0001 |
| Initial Epochs | 20 |
| Incremental Epochs | 10 |
- The model successfully learns the new class (horse) without completely forgetting the original classes.
- Knowledge distillation stabilizes logits for old classes, achieving balanced performance across all four categories.
| Stage | Classes | Accuracy (approx.) | Observation |
|---|---|---|---|
| Initial | cow, donkey, sheep | ~95% | Good base performance |
| Incremental | +horse | ~90β92% | Slight drop, minimal forgetting |
- Extend to multi-step incremental learning (add more classes sequentially)
- Add visualization for logits drift and forgetting metrics
Pranta Barua Educational experiment on continual learning (2025)
β If you found this useful or educational, consider starring the repository!