|
1 | | -# ✂️ PruneVision AI — Self-Pruning Neural Networks |
| 1 | +# ✂️ PruneVision AI — Short Project Report |
2 | 2 |
|
3 | | -[](https://www.python.org/downloads/) |
4 | | -[](https://www.docker.com/) |
5 | | -[](https://streamlit.io/) |
6 | | -[](LICENSE) |
7 | | -[](https://github.com/prunevision/ai/actions) |
| 3 | +PruneVision AI is a PyTorch-based self-pruning vision framework built around learnable sigmoid gates. The project trains compact classifiers on CIFAR-10, applies L1 regularization to encourage sparse gates, and exports pruned models for efficient inference. The implementation is organized under [Full Implementation](Full%20Implementation), while the repository root stays focused on this report. |
8 | 4 |
|
9 | | -**PruneVision AI** is a production-grade platform for self-pruning neural networks, enabling efficient edge deployment with minimal accuracy loss. Built with learnable gating mechanisms, it automates model compression during training. |
| 5 | +## Overview |
10 | 6 |
|
11 | | -### The Problem |
12 | | -Modern neural networks achieve exceptional accuracy but at significant computational cost: |
13 | | -- ❌ 100M-1B+ parameters require 4-12GB memory |
14 | | -- ❌ 100-500ms inference latency on CPU |
15 | | -- ❌ 10-50W power consumption |
16 | | -- ❌ Weeks of expert-driven post-training optimization |
| 7 | +The codebase is centered on three layers: |
17 | 8 |
|
18 | | -### Our Solution |
19 | | -PruneVision introduces **self-pruning architecture** with learnable gating mechanisms: |
20 | | -- ✅ **50-80% parameter reduction** during training |
21 | | -- ✅ **3-5× faster inference** on edge devices (ARM, NVIDIA Jetson) |
22 | | -- ✅ **≤2% accuracy loss** vs. baseline |
23 | | -- ✅ **Production-ready** without post-training optimization |
| 9 | +- **Modeling**: prunable MobileNetV3, ResNet-18, and EfficientNet-B0 backbones |
| 10 | +- **Training**: a staged sparsity schedule that balances accuracy and compression |
| 11 | +- **Deployment**: evaluation, pruning, ONNX export, and dashboard visualization |
24 | 12 |
|
25 | | -### Real-World Impact |
26 | | -Perfect for lightweight image classification and edge AI research: |
27 | | -- 🧠 **CIFAR-10 Benchmarking** - Compare pruning across compact vision models |
28 | | -- ⚡ **Edge Deployment** - Efficient inference on resource-constrained devices |
29 | | -- 📉 **Model Compression** - Reduce parameters with minimal accuracy loss |
30 | | -- 🔬 **Research Prototyping** - Study sparsity, gating, and transfer learning |
| 13 | +The best saved CIFAR-10 checkpoint in the repository is the MobileNetV3-Small run, which reports **92.37% test accuracy** and **45.3% sparsity**. |
31 | 14 |
|
32 | | -## ✨ Key Features |
| 15 | +## Answers |
33 | 16 |
|
34 | | -### 🧠 Advanced Architecture |
35 | | -```python |
36 | | -# Learnable gate parameters for automatic pruning |
37 | | -masked_weight = weight × sigmoid(gate) |
38 | | -loss = CrossEntropy + λ × L1(sigmoid(gates)) |
39 | | -``` |
| 17 | +### Why L1 on sigmoid gates encourages sparsity |
40 | 18 |
|
41 | | -### 🎯 3-Stage Training Pipeline |
42 | | -| Stage | Epochs | Lambda | Purpose | |
43 | | -|-------|--------|--------|---------| |
44 | | -| **Warm-up** | 1-10 | 0.0001 | Network learns representations | |
45 | | -| **Progressive** | 11-25 | 0.001→0.01 | Aggressive gate pruning | |
46 | | -| **Fine-tuning** | 26-30 | 0.0 | Accuracy recovery | |
| 19 | +Each gate is passed through a sigmoid, so its value stays in the range $[0, 1]$. Adding an L1 penalty on those gate values makes the optimizer pay a cost for keeping gates open. The easiest way to reduce that cost is to push unimportant gates toward 0, which shuts off channels and produces a sparse model. |
47 | 20 |
|
48 | | -### 📊 Interactive Dashboard |
49 | | -- Real-time training metrics and visualization |
50 | | -- Advanced model analysis and layer inspection |
51 | | -- Inference benchmarking and comparison |
52 | | -- One-click model export (ONNX, PyTorch) |
| 21 | +### Result summary by $\lambda$ |
53 | 22 |
|
54 | | -### 🐳 Production-Ready |
55 | | -- Docker support with multi-stage builds |
56 | | -- Kubernetes manifests included |
57 | | -- Cloud deployment templates (AWS, GCP, Azure) |
58 | | -- Comprehensive security hardening |
| 23 | +Only one completed run is stored in the current workspace, so the table below reflects the saved best MobileNetV3-Small checkpoint. |
59 | 24 |
|
60 | | -### 🔒 Security & Quality |
61 | | -- Type hints throughout (PEP 484) |
62 | | -- 80%+ test coverage with pytest |
63 | | -- Static analysis (mypy, pylint, flake8) |
64 | | -- Security scanning (Bandit, Dependabot) |
65 | | -- Pre-commit hooks for code quality |
| 25 | +| Lambda | Test Accuracy | Sparsity Level (%) | |
| 26 | +|-------:|--------------:|-------------------:| |
| 27 | +| 0.0001 | 92.37 | 45.3 | |
66 | 28 |
|
| 29 | +### Final gate distribution plot |
67 | 30 |
|
68 | | -## 📊 Quick Comparison |
69 | 31 |
|
70 | | -| Aspect | Baseline | PruneVision | Improvement | |
71 | | -|--------|----------|-------------|-------------| |
72 | | -| Parameters | 2.5M | 1.2M | **52% smaller** | |
73 | | -| Model Size | 9.8MB | 4.7MB | **52% reduction** | |
74 | | -| Inference Time | 124ms | 78ms | **37% faster** | |
75 | | -| Accuracy | 89.2% | 88.9% | **-0.3%** | |
76 | 32 |
|
77 | | -## 📊 Model Sparsity Comparison |
| 33 | +## Snapshots and Demo |
78 | 34 |
|
79 | | -PruneVision AI achieves significant parameter reduction across different architectures on CIFAR-10: |
| 35 | +### Dashboard snapshots |
80 | 36 |
|
81 | | -| Model | Baseline Params | Pruned Params | Sparsity | Accuracy Loss | Inference Speedup | |
82 | | -|-------|----------------|---------------|----------|---------------|-------------------| |
83 | | -| **MobileNetV3-Small** | 2.5M | 900K | **63.9%** | <1.5% | 2.8× | |
84 | | -| **ResNet-18** | 11.7M | 4.2M | 64.1% | <1.2% | 2.9× | |
85 | | -| **EfficientNet-B0** | 5.3M | 1.9M | 64.3% | <1.0% | 3.1× | |
| 37 | + |
86 | 38 |
|
87 | | -**Key Insights:** |
88 | | -- All models achieve **60%+ sparsity** with minimal accuracy loss |
89 | | -- **EfficientNet-B0** shows highest compression ratio (64.3%) |
90 | | -- **MobileNetV3-Small** provides best balance of sparsity and speed |
91 | | -- Self-pruning gates enable automatic parameter removal during training |
| 39 | + |
92 | 40 |
|
93 | | -*Benchmarks on CIFAR-10 dataset (50k training, 10k test images)* |
| 41 | + |
94 | 42 |
|
95 | | -## 🚀 Quick Start |
| 43 | + |
96 | 44 |
|
97 | | -### 1. Installation |
| 45 | + |
98 | 46 |
|
99 | | -```bash |
100 | | -# Clone repository |
101 | | -git clone https://github.com/yourusername/PruneVision-AI.git |
102 | | -cd PruneVision-AI |
103 | | - |
104 | | -# Create virtual environment |
105 | | -python -m venv venv |
106 | | -source venv/bin/activate # On Windows: venv\Scripts\activate |
107 | | - |
108 | | -# Install dependencies |
109 | | -pip install -r requirements.txt |
110 | | -``` |
111 | | - |
112 | | -### 2. Train a Model |
113 | | - |
114 | | -```bash |
115 | | -# MobileNetV3-Small (fastest, recommended for CPU) |
116 | | -python train_model.py --model mobilenetv3_small --epochs 30 |
117 | | - |
118 | | -# ResNet-18 |
119 | | -python train_model.py --model resnet18 --epochs 30 |
120 | | - |
121 | | -# EfficientNet-B0 |
122 | | -python train_model.py --model efficientnet_b0 --epochs 30 |
123 | | - |
124 | | -# With ONNX export |
125 | | -python train_model.py --model mobilenetv3_small --export-onnx |
126 | | -``` |
127 | | - |
128 | | -### Launch Dashboard |
129 | | -```bash |
130 | | -streamlit run app.py |
131 | | -``` |
132 | | - |
133 | | -## 📊 Dataset |
134 | | - |
135 | | -- **CIFAR-10 Dataset**: 10 object classification classes |
136 | | - - Airplane, Automobile, Bird, Cat, Deer, Dog, Frog, Horse, Ship, Truck |
137 | | -- **60,000 total images** (32×32 RGB, auto-downloaded from torchvision) |
138 | | - - Training: 50,000 images (5,000 per class) |
139 | | - - Test: 10,000 images (1,000 per class) |
140 | | -- Balanced dataset with equal samples per class |
141 | | -- Class-weighted sampling for optimal training convergence |
142 | | - |
143 | | -## 🏗️ Model Zoo |
144 | | - |
145 | | -| Model | Params | Size | Target Use | |
146 | | -|-------|--------|------|-----------| |
147 | | -| MobileNetV3-Small | ~2.5M | ~10 MB | Ultra-fast edge inference | |
148 | | -| ResNet-18 | ~11.7M | ~45 MB | Balanced accuracy/speed | |
149 | | -| EfficientNet-B0 | ~5.3M | ~20 MB | Best accuracy/efficiency | |
150 | | - |
151 | | -## 🔧 Configuration |
152 | | - |
153 | | -All hyperparameters are centralized in `config.py`: |
154 | | -- Image size, batch size, learning rate |
155 | | -- 3-stage sparsity schedule (λ values, epoch boundaries) |
156 | | -- Gate initialization bias, pruning threshold |
157 | | -- Data augmentation parameters |
158 | | - |
159 | | -## 📈 Dashboard Features |
160 | | - |
161 | | -1. **Overview** — Architecture explanation, pipeline visualization |
162 | | -2. **Dataset Explorer** — Class distribution, sample image browser |
163 | | -3. **Training Monitor** — Loss/accuracy/sparsity curves, λ schedule |
164 | | -4. **Model Analysis** — Layer-wise sparsity, gate distributions |
165 | | -5. **Deployment** — Model comparison, export commands |
166 | | -6. **Live Demo** — Upload image → real-time classification |
167 | | - |
168 | | - |
169 | | -## 🏗️ Architecture |
170 | | - |
171 | | -### System Design |
172 | | - |
173 | | -<img width="6531" height="3175" alt="image" src="https://github.com/user-attachments/assets/e44761a8-3663-4afb-863a-e9f44f786f31" /> |
174 | | - |
175 | | - |
176 | | -## 📈 Performance Metrics |
177 | | - |
178 | | -### Benchmark Results |
179 | | - |
180 | | -| Model | Baseline Params | Pruned Params | Reduction | Top-1 Acc | Latency (CPU) | Model Size | |
181 | | -|-------|-----------------|---------------|-----------|-----------|---------------|------------| |
182 | | -| **MobileNetV3-Small** | 2.5M | 1.2M | 52% ↓ | 84.2% | 45ms | 4.8MB | |
183 | | -| **ResNet-18** | 11.7M | 5.2M | 55% ↓ | 89.5% | 120ms | 20.1MB | |
184 | | -| **EfficientNet-B0** | 5.3M | 2.1M | 60% ↓ | 91.2% | 80ms | 8.4MB | |
185 | | - |
186 | | -### Edge Device Performance |
187 | | - |
188 | | -**Latency (ms) - Lower is Better** |
189 | | - |
190 | | -``` |
191 | | - Baseline Pruned Speedup |
192 | | -┌─────────────────────────────────────────────────┐ |
193 | | -│ Raspberry Pi 4 │ |
194 | | -│ ████████████████ 250ms ████ 45ms 5.5× │ |
195 | | -│ │ |
196 | | -│ NVIDIA Jetson Nano │ |
197 | | -│ ████████████ 180ms ██ 35ms 5.1× │ |
198 | | -│ │ |
199 | | -│ Intel Core i7 (CPU) │ |
200 | | -│ ████████ 120ms ██ 22ms 5.4× │ |
201 | | -└─────────────────────────────────────────────────┘ |
202 | | -``` |
203 | | - |
204 | | -### Memory Usage Comparison |
205 | | - |
206 | | -| Device | Baseline | Pruned | Reduction | |
207 | | -|--------|----------|--------|-----------| |
208 | | -| Raspberry Pi 4 (1GB RAM) | ✗ OOM | ✓ 312MB | 70% ↓ | |
209 | | -| Jetson Nano (4GB RAM) | 2.1GB | 0.6GB | 71% ↓ | |
210 | | -| Desktop (16GB RAM) | 4.2GB | 1.2GB | 71% ↓ | |
211 | | - |
212 | | -### Accuracy Preservation |
213 | | - |
214 | | -Models maintain competitive accuracy with minimal loss: |
215 | | - |
216 | | -``` |
217 | | -MobileNetV3-Small: 84.2% → 82.8% (-1.4%) |
218 | | -ResNet-18: 89.5% → 88.6% (-0.9%) |
219 | | -EfficientNet-B0: 91.2% → 90.4% (-0.8%) |
220 | | -``` |
221 | | ---- |
222 | | - |
223 | | - |
224 | | -## 📊 Dashboard |
225 | | - |
226 | | -### Interactive Web Interface |
227 | | - |
228 | | -Access comprehensive monitoring and analysis: |
229 | | - |
230 | | -```bash |
231 | | -streamlit run app.py |
232 | | -# Visit: http://localhost:8501 |
233 | | -``` |
234 | | - |
235 | | -### Dashboard Tabs |
236 | | -#### **Live Demo** |
237 | | -- Image upload and classification |
238 | | -- Real-time inference |
239 | | -- Prediction confidence scores |
240 | | -.gif) |
241 | | - |
242 | | -#### 1️⃣ **Overview** |
243 | | -- Architecture explanation |
244 | | -- Training pipeline visualization |
245 | | -- Performance comparison table |
246 | | -<img width="1915" height="787" alt="image" src="https://github.com/user-attachments/assets/81232db9-f76a-4e30-8c89-2215fd389ad2" /> |
247 | | - |
248 | | - |
249 | | - |
250 | | -#### 2️⃣ **Dataset Explorer** |
251 | | -- Class distribution histogram |
252 | | -- Sample image browser |
253 | | -- Dataset statistics |
254 | | -<img width="1914" height="788" alt="image" src="https://github.com/user-attachments/assets/186c029e-676f-4d43-9a99-36e89d09b737" /> |
255 | | - |
256 | | - |
257 | | - |
258 | | -#### 3️⃣ **Training Monitor** |
259 | | -- Real-time loss and accuracy curves |
260 | | -- Sparsity progression |
261 | | -- Lambda schedule visualization |
262 | | -<img width="1910" height="794" alt="image" src="https://github.com/user-attachments/assets/fda92861-cf99-46bf-a9bf-722bf758aa63" /> |
263 | | - |
264 | | - |
265 | | -#### 4️⃣ **Model Analysis** |
266 | | -- Layer-wise sparsity heatmap |
267 | | -- Gate value distribution |
268 | | -- Parameter reduction statistics |
269 | | -<img width="1895" height="792" alt="image" src="https://github.com/user-attachments/assets/c444d36f-0ae1-4ef1-97bc-0fb7859cb1ee" /> |
270 | | - |
271 | | - |
272 | | -#### 5️⃣ **Deployment** |
273 | | -- Model comparison table |
274 | | -- Export options (ONNX, PyTorch) |
275 | | -- Cloud deployment guides |
276 | | -<img width="1867" height="787" alt="image" src="https://github.com/user-attachments/assets/c6b0e285-7961-4d1e-a303-a541a6b983f8" /> |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | ---- |
282 | | -## 📜 License |
283 | | - |
284 | | -This project is licensed under the **Apache License 2.0**. |
285 | | - |
286 | | -### Third-party Licenses |
287 | | - |
288 | | -- PyTorch: BSD-3-Clause |
289 | | -- Streamlit: Apache 2.0 |
290 | | -- NumPy: BSD-3-Clause |
291 | | - |
292 | | ---- |
293 | | - |
294 | | -<div align="center"> |
295 | | - |
296 | | -**Made with ❤️ by M Harish Gautham** |
297 | | - |
298 | | -⭐ If you find this project helpful, please star it! ⭐ |
299 | | - |
300 | | -[Website](https://github.com/harishy0406/PruneVision-AI) • [Docs](https://github.com/harishy0406/PruneVision-AI) • [GitHub](https://github.com/harishy0406/PruneVision-AI) |
301 | | - |
302 | | -</div> |
| 47 | +### Project demo |
303 | 48 |
|
| 49 | +[Watch the demo GIF](Full%20Implementation/Work%20Demo(Prunvison%20AI).gif) |
0 commit comments