A complete deep learning compression pipeline implementing multiple model optimization strategies including:
- Structured Pruning
- Unstructured Pruning
- Quantization-Aware Training (QAT)
- Full INT8 TFLite Quantization
- Model size benchmarking (raw + gzipped)
- Accuracy comparison across strategies
This repository demonstrates practical model compression techniques using:
- TensorFlow
- TensorFlow Model Optimization Toolkit (TF-MOT)
- TFLite INT8 conversion
The goal is to compare:
- Accuracy retention
- Model size reduction
- Parameter count
- Compression efficiency
Standard CNN model trained normally.
Removes entire filters or channels.
Removes individual weights based on sparsity target.
Simulates quantization during training.
Converts trained model to TFLite INT8.
For each strategy:
- Accuracy
- Raw model size (KB)
- Gzipped model size (KB)
- Parameter count
- Convolution filter count
Model_Optimization
├── .gitignore
├── environment.yml # Environment file
├── notebook
│ └── ModelOptimization.ipynb # Notebook version of the pipeline
├── README.md
├── requirements.txt # Packages required
├── scripts
│ └── run_pipeline.py # To run the whole pipeline
└── src
├── __init__.py
├── configs
│ └── compression.yaml # Model configuration file
├── data
│ └── mnist.py # Data loader
├── evaluation
│ └── test.py # Testing the model
├── models
│ ├── base_model.py # Base line model architecture
│ ├── clustering.py # Clustered model
│ ├── quantization.py # Quantized model
│ ├── structured.py # Structured pruning architecture
│ └── unstructured.py # Unstructured pruning model
├── pipeline
│ └── compression_pipeline.py # Pipeline code
├── training
│ └── trained.py # Training code
└── utils
├── comparision.py
├── env.py
├── filters.py
├── logging.py
├── size.py
└── sparsity.pygit clone https://github.com/kja8586/Model_Optimization.git
cd Model_OptimizationWe recommend using Conda for maximum stability and reproducibility.
This ensures:
- Correct Python version
- Exact dependency versions
- Clean isolated environment
- Minimal dependency conflicts
conda env create -f environment.ymlconda activate mopython -m scripts.run_pipelinename: mo
channels:
- defaults
dependencies:
- python=3.10.14
- pip
- pip:
- tensorflow==2.19.0
- tf_keras==2.19.0
- tensorflow-model-optimization==0.8.0
- pandas==2.2.2
- numpy==1.26.0
- PyYAML==6.0.2Use this if you prefer standard Python environments.
python3.10 -m venv venvMac/Linux:
source venv/bin/activateWindows:
venv\Scripts\activatepip install -r requirements.txtpython -m scripts.run_pipelineFor this project (TensorFlow + TF-MOT + TFLite):
👉 Conda is strongly recommended for better reproducibility and fewer dependency conflicts.