This project implements Byte Pair Encoding (BPE) for image classification, demonstrating how BPE can be used to efficiently encode and classify images while maintaining classification accuracy.
The project implements a novel approach to image classification by applying Byte Pair Encoding (BPE) to image data. BPE, traditionally used in text compression and NLP tasks, is adapted here for image processing, offering several advantages:
- Efficient data compression
- Reduced memory usage
- Faster training and inference times
- Maintained classification accuracy
- BPE-based image encoding and decoding
- Support for both grayscale and color images
- Multiple classifier implementations (Random Forest, SVM, Neural Network)
- Comprehensive performance analysis and visualization
- Sample image encoding demonstrations
The above plot shows the comparison of different performance metrics across various classifiers and encoding methods:
- Accuracy comparison
- Training time comparison
- Prediction time comparison
- F1 score comparison
This visualization demonstrates the precision and recall metrics for different classifiers using both original and BPE-encoded data.
The efficiency comparison shows the trade-off between accuracy and computational resources for different approaches.
The project includes sample visualizations demonstrating the BPE encoding process:
These samples show:
- Original images
- BPE-encoded representations
- Reconstructed images
- Clone the repository:
git clone [repository-url]
cd [repository-name]- Install dependencies:
pip install -r requirements.txt- Run the analysis:
python src/comparative_analysis.py.
├── src/
│ ├── bpe_encoder.py # BPE implementation
│ ├── comparative_analysis.py # Analysis and visualization
│ └── results/ # Generated plots and results
├── data/ # Image dataset
└── app.py # Streamlit visualization app
- Prepare your image dataset in the
datadirectory, organized by class:
data/
├── 0/
│ ├── image1.jpg
│ └── image2.jpg
├── 1/
│ ├── image3.jpg
│ └── image4.jpg
└── 2/
├── image5.jpg
└── image6.jpg
- Run the analysis:
python src/comparative_analysis.py- View the interactive visualizations:
streamlit run app.py- Compression Efficiency: BPE encoding achieves significant compression ratios while maintaining image quality.
- Classification Performance: BPE-encoded images maintain comparable or better classification accuracy compared to original images.
- Computational Efficiency: Reduced training and inference times due to compressed representation.
- Memory Usage: Lower memory requirements for storing and processing encoded images.
- Integration with deep learning architectures
- Support for larger image datasets
- Optimization for real-time applications
- Extension to video processing
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.





