File size: 10,697 Bytes
d5ec07c
0b9dad1
 
 
 
4b2e400
d5ec07c
 
 
d32e728
 
fbd6723
 
 
 
 
 
 
 
 
 
 
 
 
d32e728
 
 
fbd6723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d32e728
 
 
fbd6723
 
 
 
 
d32e728
fbd6723
d32e728
fbd6723
d32e728
fbd6723
d32e728
fbd6723
d32e728
 
fbd6723
d32e728
fbd6723
 
 
d32e728
 
 
 
fbd6723
 
 
 
 
d32e728
fbd6723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d32e728
 
 
fbd6723
d32e728
fbd6723
 
 
 
 
 
 
 
d32e728
 
 
fbd6723
d32e728
fbd6723
d32e728
fbd6723
 
 
 
 
 
 
 
d32e728
fbd6723
 
d32e728
fbd6723
 
 
 
 
 
 
d32e728
 
fbd6723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d32e728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
---
title: Intel Image Classifier
emoji: 🧠
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
---

# Intel Image Classifier

Full-stack application for classifying natural scene images using two CNN models (PyTorch & TensorFlow).

> **For deployment instructions and detailed setup, see [DEPLOYMENT.md](DEPLOYMENT.md)**

---

## What's New (Consolidated Version)**Unified Docker Deployment** - Single container for Hugging Face Spaces  
✅ **Production-Ready** - Gunicorn + WhiteNoise for static files  
✅ **AutoStart Scripts** - Automatic migrations and superuser setup  
✅ **Health Check Endpoint** - `/health/` for monitoring  
✅ **Optimized Build** - Multi-stage Docker with Node.js + Python  

---

## Quick Start

### 🐳 Docker (Recommended)

```bash
# Build the unified container
docker build -t intel-classifier .

# Run on port 7860 (Hugging Face compatible)
docker run -p 7860:7860 intel-classifier
```

Visit: `http://localhost:7860`

### 🚀 Hugging Face Spaces

1. Fork this repository to your Hugging Face account
2. Add your trained models to `backend/api/models/`
3. Push to your HF Space
4. Watch it deploy automatically!

```bash
git push hf main
```

---

## Project Structure

```
intel-classifier/
├── backend/                      # Django REST API
│   ├── api/notifications/        # Classification app
│   │   └── models/
│   │       ├── pytorch_model.pth
│   │       └── model_best.keras
│   ├── requirements.txt
│   └── api/entrypoint.sh

├── frontend/                     # React + Material-UI
│   ├── src/
│   └── package.json

├── ml/                           # Training code (optional)
│   ├── models/
│   ├── utils/
│   └── requirements.txt

├── Dockerfile                    # Unified deployment
├── docker-compose.yml            # Local development
└── DEPLOYMENT.md                 # Full deployment guide
```

---

## API Usage

### Classification Endpoint

**POST** `/api/classify/`

```bash
curl -X POST \
  -F "image=@photo.jpg" \
  -F "model=pytorch" \
  http://localhost:7860/api/classify/
```

**Response:**
```json
{
  "class": "mountain",
  "confidence": 0.95,
  "model_used": "pytorch",
  "probabilities": {
    "buildings": 0.02,
    "forest": 0.01,
    "glacier": 0.01,
    "mountain": 0.95,
    "sea": 0.01,
    "street": 0.00
  }
}
```

### Documentation

- 📚 Swagger: `http://localhost:7860/swagger/`
- 📖 ReDoc: `http://localhost:7860/redoc/`
- 🔐 Admin: `http://localhost:7860/admin/` (user: admin, pass: admin)
- ✅ Health: `http://localhost:7860/health/`

---

## Supported Classes

| English  | French     | Wolof          | Example              |
|----------|------------|----------------|----------------------|
| buildings| Bâtiments  | Kër yi         | Houses, offices      |
| forest   | Forêt      | Géej bu wees   | Trees, vegetation    |
| glacier  | Glacier    | Dëkk bu sedd   | Ice, snow            |
| mountain | Montagne   | Tund bi        | Hills, peaks         |
| sea      | Mer        | Géej bi        | Ocean, water         |
| street   | Rue        | Yoon bi        | Roads, urban areas   |

---

## Local Development

### Setup Backend

```bash
cd backend/api
python -m venv venv
source venv/bin/activate
pip install -r ../requirements.txt

# Run migrations
python manage.py migrate

# Start server
python manage.py runserver 8000
```

### Setup Frontend

```bash
cd frontend
npm install
npm start
```

Access at:
- Frontend: `http://localhost:3000`
- Backend: `http://localhost:8000`

---

## Adding Your Models

1. Train your models using scripts in `/ml/`
2. Place trained models in `backend/api/models/`:
   ```
   backend/api/models/
   ├── pytorch_model.pth
   └── model_best.keras
   ```
3. Deploy or restart the application

---

## Deployment Checklist

- [ ] Clone repository
- [ ] Add trained models
- [ ] Test locally with Docker
- [ ] Push to Hugging Face Spaces
- [ ] Test on live URL
- [ ] Update README with your username

---

## Technologies

### Backend
- Django REST Framework
- PyTorch
- TensorFlow
- Gunicorn

### Frontend
- React 19
- Material-UI (MUI)
- Redux Toolkit
- Axios

### DevOps
- Docker & Docker Compose
- Hugging Face Spaces
- WhiteNoise (static files)

---

## Configuration

Create `backend/.env` for custom settings:

```env
DEBUG=False
DJANGO_SECRET_KEY=your-secret-here
ALLOWED_HOSTS=localhost,.hf.space
```

For full configuration details, see [DEPLOYMENT.md](DEPLOYMENT.md)

---

## Troubleshooting

### Models not loading?
Ensure files exist in `backend/api/models/`:
- `pytorch_model.pth` (PyTorch)
- `model_best.keras` (TensorFlow)

### Port conflicts?
Change port in Docker command:
```bash
docker run -p 8080:7860 intel-classifier
# Access at localhost:8080
```

### CORS errors?
Check that frontend and backend share same origin. HF Spaces handles this automatically.

For more issues, see [DEPLOYMENT.md#troubleshooting](DEPLOYMENT.md#troubleshooting)

---

## Resources

- 📚 [Intel Image Classification Dataset](https://www.kaggle.com/datasets/puneet6060/intel-image-classification)
- 🤖 [PyTorch Documentation](https://pytorch.org/)
- 🎓 [TensorFlow Documentation](https://tensorflow.org/)
- 🤗 [Hugging Face Spaces Guide](https://huggingface.co/docs/hub/spaces)
- 🚀 [Django Deployment Guide](https://docs.djangoproject.com/en/5.0/howto/deployment/)

---

## License

MIT License - See LICENSE file

## Support

- 🐛 [Issues](https://github.com/danielle2035/Intel_classification/issues)
- 💬 [Discussions](https://huggingface.co/spaces/danielle2035/Intel_classification/discussions)
- 📧 Email: contact@example.com

---

## Citation

```bibtex
@misc{intel_classifier,
  title={Intel Image Classifier},
  author={Your Name},
  year={2024},
  publisher={Hugging Face Spaces},
  url={https://huggingface.co/spaces/YOUR_USERNAME/Intel_classification}
}
```

---

**Made with ❤️ for the Hugging Face Community**

---

### 2. Backend (Django)

```bash
# Aller dans le dossier backend
cd backend

# Créer un environnement virtuel
python -m venv venv

# Activer l'environnement virtuel
# Windows :
venv\Scripts\activate
# Mac/Linux :
source venv/bin/activate

# Installer les dépendances
pip install -r requirements.txt

# Aller dans le dossier Django
cd api

# Appliquer les migrations
python manage.py migrate

# Lancer le serveur
python manage.py runserver
```

Le backend sera disponible sur : **http://127.0.0.1:8000**

API Swagger disponible sur : **http://127.0.0.1:8000/swagger/**

---

### 3. Frontend (React)

Ouvre un **nouveau terminal** :

```bash
# Aller dans le dossier frontend
cd frontend

# Installer les dépendances
npm install

# Lancer l'application  
npm start
```

Le frontend sera disponible sur : **http://localhost:3000**

---

## Installation et lancement (avec Docker)

```bash
# À la racine du projet
docker-compose up --build
```

- Frontend : http://localhost:3000
- Backend  : http://localhost:8000
- Swagger  : http://localhost:8000/swagger/

---

## Entraînement des modèles

### Sur Kaggle (recommandé)

1. Upload `ml/train_kaggle.py` dans un notebook Kaggle
2. Active le GPU (Settings → Accelerator → GPU T4)
3. Ajoute le dataset `puneet6060/intel-image-classification`
4. Exécute le notebook
5. Télécharge `danielle_model.pth` et `danielle_model.keras`
6. Place-les dans `backend/api/models/`

### En local

```bash
cd ml

# Installer les dépendances ML
pip install torch torchvision tensorflow numpy matplotlib seaborn scikit-learn tqdm pillow

# Entraîner le modèle PyTorch
python -m models.train --model pytorch --epochs 25 --data data

# Entraîner le modèle TensorFlow
python -m models.train --model tensorflow --epochs 25 --data data
```

Structure du dataset attendue :
```
ml/data/
├── seg_train/
│   └── seg_train/
│       ├── buildings/
│       ├── forest/
│       ├── glacier/
│       ├── mountain/
│       ├── sea/
│       └── street/
└── seg_test/
    └── seg_test/
        ├── buildings/
        ├── forest/
        ...
```

---

## API — Endpoint de classification

### `POST /api/classify/`

**Paramètres (form-data) :**

| Paramètre  | Type   | Requis | Description                        |
|------------|--------|--------|------------------------------------|
| image      | file   | Non*   | Fichier image (jpg, png...)        |
| image_url  | string | Non*   | URL d'une image en ligne           |
| model      | string | Non    | `pytorch` (défaut) ou `tensorflow` |

*Au moins `image` ou `image_url` est requis.

**Réponse (200 OK) :**

```json
{
  "predicted_class": "forest",
  "confidence": 0.97,
  "model_used": "pytorch",
  "all_probabilities": [
    { "class": "forest",    "probability": 0.97 },
    { "class": "mountain",  "probability": 0.01 },
    { "class": "glacier",   "probability": 0.01 },
    { "class": "sea",       "probability": 0.01 },
    { "class": "buildings", "probability": 0.00 },
    { "class": "street",    "probability": 0.00 }
  ]
}
```

---

## Fonctionnalités de l'interface

- Upload d'image depuis le disque
- Chargement d'image depuis une URL
- Sélection du modèle (PyTorch CNN / TensorFlow CNN)
- Affichage du résultat avec barre de confiance
- Affichage de toutes les probabilités par classe
- Interface multilingue : **Anglais / Français / Wolof**
- Design responsive avec Material UI

---

## Technologies utilisées

| Couche     | Technologies                                    |
|------------|-------------------------------------------------|
| Frontend   | React 19, Material UI 6, Axios                  |
| Backend    | Django 5, Django REST Framework, drf-yasg       |
| ML         | PyTorch 2.2, TensorFlow 2.16, torchvision, timm |
| Données    | Intel Image Classification (Kaggle)             |
| DevOps     | Docker, Docker Compose                          |

---

## Problèmes fréquents

**Erreur CORS au démarrage du frontend**
→ Vérifie que le backend tourne sur `http://127.0.0.1:8000`

**`Model file not found`**
→ Vérifie que `danielle_model.pth` et/ou `danielle_model.keras` sont bien dans `backend/api/models/`

**`ModuleNotFoundError: No module named 'notifications'`**
→ Lance `manage.py` depuis le dossier `backend/api/` et non depuis `backend/`

**TensorFlow lent au premier chargement**
→ Normal, le modèle est chargé en mémoire à la première requête (lazy loading)

---

## Auteurs

Projet universitaire — Classification d'images Intel — 2026
>>>>>>> b102039 (Initial commit - Intel Image Classifier)