oc-p06-product-classification/README.md

251 lines
8.2 KiB
Markdown

**Source of truth** : https://git.gregoiremureau.com/openclassroom-ai/oc-p06-product-classification
```bash
git clone https://git.gregoiremureau.com/openclassroom-ai/oc-p06-product-classification.git
git clone https://git.gregoiremureau.com/openclassroom-ai/oc-p06-product-classification.git
```
Dataset: see `fetch-data.sh` (excluded from git if too large).
# Automatic Product Classification Project - Marketplace
📘 Ce projet est également disponible en [français 🇫🇷](./README.fr.md)
## 📋 Project Context
This project was carried out for **Place de marché**, a company that wants to launch an English-speaking e-commerce marketplace. The goal is to automate the classification of items sold on the platform in order to improve the user experience, both for sellers and buyers.
Currently, category assignment is done manually by sellers, which is unreliable and difficult to scale. This project aims to develop an automatic classification engine based on textual descriptions (in English) and product images.
## 🎯 Objectives
The project is divided into several main missions:
1. **Feasibility study**: Analyze the ability to automatically classify products from their textual descriptions and images
2. **Feature extraction**: Implement various feature extraction techniques for text and images
3. **Visual analysis**: Reduce the data to 2D and visualize the separability of categories
4. **Supervised classification**: Train a deep learning model to classify images with data augmentation
5. **Data collection**: Test the OpenFoodFacts API to enrich the product database
## 📊 Data
The project uses a dataset of items with:
- Textual descriptions in English
- Product images
- Product categories (7 main categories)
- About 150 products per category
**Note**: The data used does not present any intellectual property constraints.
## 📁 Project Structure
```
├── P6_01_NLP_Basic_methods.ipynb
├── P6_02_NLP_Doc2Vec.ipynb
├── P6_03_NLP_transfer_learning.ipynb
├── P6_04_IMAGES_SIFT_ORB.ipynb
├── P6_05_IMAGES_CNN_Transfer_learning.ipynb
├── P6_06_Classification_CNN_machine_learning.ipynb
├── P6_07_OpenFoodFacts_API.ipynb
├── P6_Classifiez_automatiquement_des_produits.pptx
└── test_images/
```
### 1. `P6_01_NLP_Basic_methods.ipynb`
**NLP processing notebook - Classical methods**
This notebook implements traditional text processing approaches:
- Text preprocessing (cleaning, lemmatization, stopword removal)
- Feature extraction with Bag-of-Words (CountVectorizer)
- Feature extraction with TF-IDF
- Dimensionality reduction (PCA)
- 2D T-SNE visualization
- K-means clustering and Adjusted Rand Index (ARI) computation
- Evaluation of automatic classification feasibility
### 2. `P6_02_NLP_Doc2Vec.ipynb`
**NLP processing notebook - Classical word/sentence embedding**
This notebook explores word embedding techniques:
- Implementation of Word2Vec or Doc2Vec
- Creation of sentence/document vectors
- Dimensionality reduction and T-SNE visualization
- Comparison with bag-of-words approaches
- Analysis of category separability
### 3. `P6_03_NLP_transfer_learning.ipynb`
**NLP processing notebook - Transfer Learning**
This notebook implements advanced NLP techniques:
- BERT (Bidirectional Encoder Representations from Transformers)
- USE (Universal Sentence Encoder)
- Contextual feature extraction
- Visualization and performance comparison
- Comparative evaluation of all NLP approaches
### 4. `P6_04_IMAGES_SIFT_ORB.ipynb`
**Image processing notebook - Classical descriptors**
This notebook covers traditional image feature extraction:
- Image preprocessing (grayscale, equalization, filtering)
- Feature extraction with SIFT
- Feature extraction with ORB (alternative to SURF)
- Creation of Bag of Visual Words
- Dimensionality reduction (PCA)
- T-SNE visualization and ARI evaluation
### 5. `P6_05_IMAGES_CNN_Transfer_learning.ipynb`
**Image processing notebook - CNN Transfer Learning**
This notebook uses pre-trained neural networks:
- Use of pre-trained CNNs (VGG16, ResNet, MobileNet, etc.)
- Feature extraction via Transfer Learning
- Comparison with SIFT/ORB approaches
- T-SNE visualization of embeddings
- Feasibility evaluation with CNN features
### 6. `P6_06_Classification_CNN_machine_learning.ipynb`
**Supervised image classification notebook**
This notebook implements supervised classification:
- Building a CNN classification model
- Train/validation/test split
- Data augmentation to improve performance
- Model training with Transfer Learning
- Performance evaluation (accuracy, confusion matrix)
- Comparison of different CNN architectures
### 7. `P6_07_OpenFoodFacts_API.ipynb`
**OpenFoodFacts API test notebook**
This notebook demonstrates data collection via API:
- OpenFoodFacts API configuration
- Query to extract champagne-based products
- Filtering of relevant data
- Extraction of fields: foodId, label, category, foodContentsLabel, image
- Export of the first 10 products in CSV format
- GDPR compliance
### 8. `P6_Classifiez_automatiquement_des_produits.pptx`
**Results presentation**
This presentation (max 30 slides) summarizes:
- The context and challenges of the project
- The methodology adopted for text and images
- The comparative results of the different approaches
- The feasibility analysis of automatic classification
- The results of supervised classification
- Recommendations for production deployment
- A demonstration of the data collection API
### 9. `test_images/`
**Test images folder**
Contains test images to validate the models:
- Anti-aging face cream
- 2-drawer cabinet
- Wired microphone
- Asus desktop PC
- Blackout curtain
- Coffee cup
## 🛠️ Technologies Used
- **Python**: Main language
- **NLP**:
- NLTK: Text preprocessing
- Scikit-learn: CountVectorizer, TF-IDF
- Gensim: Word2Vec, Doc2Vec
- Transformers: BERT
- TensorFlow Hub: Universal Sentence Encoder
- **Computer Vision**:
- OpenCV: Image processing, SIFT, ORB
- TensorFlow/Keras: CNN, Transfer Learning
- PIL: Image manipulation
- **Machine Learning**:
- Scikit-learn: PCA, K-means, metrics
- Yellowbrick: Visualization
- **Visualization**:
- Matplotlib, Seaborn: Charts
- t-SNE: Dimensionality reduction
- **API**:
- Requests: API calls
- Pandas: Data manipulation
## 📈 Methodology
### Phase 1: Feasibility analysis - Text
1. Preprocessing of textual descriptions
2. Feature extraction (Bag-of-Words, TF-IDF, Word2Vec, BERT, USE)
3. Dimensionality reduction (PCA)
4. 2D T-SNE visualization
5. K-means clustering and ARI computation
6. Analysis of category separability
### Phase 2: Feasibility analysis - Images
1. Image preprocessing
2. Feature extraction (SIFT/ORB and CNN Transfer Learning)
3. Creation of Bag of Visual Words (for SIFT/ORB)
4. Dimensionality reduction (PCA)
5. 2D T-SNE visualization
6. Evaluation and comparison of approaches
### Phase 3: Supervised classification
1. Dataset preparation (train/val/test)
2. Building CNN models with Transfer Learning
3. Implementing data augmentation
4. Training and optimization
5. Performance evaluation
### Phase 4: Extension - Data collection
1. Testing the OpenFoodFacts API
2. Query and filtering of products
3. Data export in CSV
4. GDPR compliance validation
## 📝 Deliverables
- ✅ 7 analysis and modeling notebooks
- ✅ Presentation of the approach and results (.pptx format)
- ✅ CSV file of product extraction via API
- ✅ Test images folder
## 🎓 Skills Developed
- Textual data preprocessing (NLP)
- Image data preprocessing (Computer Vision)
- Feature engineering for text and images
- Advanced embedding techniques (BERT, USE)
- Transfer Learning with pre-trained CNNs
- Dimensionality reduction (PCA, t-SNE)
- Unsupervised clustering (K-means)
- Supervised classification with deep learning
- Data augmentation for model optimization
- Data collection via API
- GDPR compliance
- Visualization and communication of results
## 🔍 Main Expected Results
- **ARI for text**: 0.4-0.5 (feasibility confirmed)
- **ARI for SIFT/ORB images**: 0.05-0.1 (inconclusive results)
- **ARI for CNN images**: 0.4-0.6 (feasibility confirmed)
- **Supervised classification**: Significant improvement with data augmentation
## 👤 Author
**Grégoire Mureau**
Completion date: 2025
---
*This project was carried out as part of the OpenClassrooms AI Engineer program*