A deep learning-based document image classification system built using PyTorch, MobileNetV2 Transfer Learning, and Grad-CAM Explainable AI.
The system classifies scanned document images into 10 different document categories based solely on visual layout patterns, eliminating the need for Optical Character Recognition (OCR).
https://automated-document-classifier-2026.streamlit.app/
Organizations process thousands of scanned documents every day, including:
- Emails
- Letters
- Reports
- Forms
- Scientific Papers
- Memos
- Resumes
Traditional OCR-based solutions are computationally expensive and often fail on:
- Low-quality scans
- Skewed documents
- Handwritten content
- Noisy images
This project solves the problem using a visual layout classification approach.
Instead of reading text, the model learns structural patterns such as:
- Headers
- Paragraph layouts
- Tables
- Signatures
- Multi-column formats
- Form grids
and automatically predicts the document category.
β MobileNetV2 Transfer Learning
β Document Layout Classification
β 10 Document Categories
β Grad-CAM Explainability
β Interactive Streamlit Dashboard
β Class Imbalance Handling
β Precision-Recall Analysis
β Confusion Matrix Visualization
β Real-Time Inference
The project uses the benchmark Tobacco3482 document image dataset.
- Total Images: 3,482
- Classes: 10
- Format: Scanned Document Images
The original Tobacco3482 dataset is derived from the Truth Tobacco Industry Documents archive maintained by UCSF.
https://www.kaggle.com/datasets/patrickaudriaz/tobacco3482jpg
Note: The dataset is not included in this repository due to its size and licensing considerations. Please download it separately from Kaggle and place it inside the
data/directory.
Extract the dataset and organize it as:
data/
βββ Tobacco3482/
βββ ADVE/
βββ Email/
βββ Form/
βββ Letter/
βββ Memo/
βββ News/
βββ Note/
βββ Report/
βββ Resume/
βββ Scientific/
Input Document Image
β
βΌ
Preprocessing
(Resize 384Γ384, Normalize)
β
βΌ
MobileNetV2 Backbone
(Transfer Learning)
β
βΌ
Global Average Pooling
β
βΌ
Linear Classifier Head
β
βΌ
10 Document Classes
β
βΌ
Grad-CAM Heatmap Generation
β
βΌ
Streamlit Dashboard
To improve model transparency, Grad-CAM is integrated into the prediction pipeline.
The heatmap highlights document regions responsible for predictions such as:
- Email Headers
- Signature Blocks
- Tables
- Form Grids
- Scientific Paper Columns
This helps users understand why the model made a specific classification.
MobileNetV2 (ImageNet Pretrained)
Frozen Layers:
0 - 13Fine-tuned Layers:
14 - 18Custom Classifier:
1280 β 10| Metric | Value |
|---|---|
| Final Train Accuracy | 86.78% |
| Final Validation Accuracy | 79.94% |
| Test Accuracy | 85.10% |
| Macro F1 Score | 84.13% |
| Weighted F1 Score | 85.09% |
| Class | Precision | Recall | F1 Score |
|---|---|---|---|
| ADVE | 0.9583 | 1.0000 | 0.9787 |
| 0.9516 | 0.9833 | 0.9672 | |
| Form | 0.9394 | 0.7209 | 0.8158 |
| Letter | 0.8772 | 0.8772 | 0.8772 |
| Memo | 0.8060 | 0.8710 | 0.8372 |
| News | 1.0000 | 0.9474 | 0.9730 |
| Note | 0.7619 | 0.8000 | 0.7805 |
| Report | 0.7000 | 0.7778 | 0.7368 |
| Resume | 0.9091 | 0.8333 | 0.8696 |
| Scientific | 0.5769 | 0.5769 | 0.5769 |
The confusion matrix shows strong performance across most categories.
Main confusion observed:
- Scientific β Report
- Scientific β Letter
Reason:
These document types often share:
- Similar paragraph structures
- Multi-column layouts
- Formal formatting styles
Average Precision (AP):
| Class | AP Score |
|---|---|
| ADVE | 0.9982 |
| 0.9984 | |
| Form | 0.9549 |
| Letter | 0.9610 |
| Memo | 0.9409 |
| News | 0.9950 |
| Note | 0.8803 |
| Report | 0.8392 |
| Resume | 0.9594 |
| Scientific | 0.6787 |
The project includes a fully interactive Streamlit dashboard.
- Upload custom documents
- Predict document category
- View confidence scores
- Generate Grad-CAM heatmaps
- Compare original and heatmap images
- Test using sample dataset images
Launch:
streamlit run src/app.pyOr
run.batDOCUMENT_CLASSIFIER
β
βββ src
β βββ app.py
β βββ train.py
β βββ evaluate.py
β βββ utils.py
β
βββ models
β βββ document_classifier.pth
β βββ class_mapping.json
β
βββ reports
β βββ confusion_matrix.png
β βββ precision_recall.png
β βββ training_curves.png
β βββ evaluation_report.md
β
β
βββ requirements.txt
βββ run.bat
βββ README.md
Clone repository:
git clone https://github.com/NimilPGopal/tobacco3482-document-classifier.git
cd tobacco3482-document-classifierCreate virtual environment:
python -m venv venvActivate:
venv\Scripts\activatesource venv/bin/activateInstall dependencies:
pip install -r requirements.txtstreamlit run src/app.py- Python
- PyTorch
- TorchVision
- MobileNetV2
- Streamlit
- NumPy
- Pillow
- Scikit-Learn
- Matplotlib
- Seaborn

