A computer vision project that classifies memes as harmful or safe using YOLOv8 object detection. Built and trained on Google Colab with GPU acceleration, supporting both English and Arabic meme datasets.
Social media platforms host millions of memes daily — some harmless, others potentially harmful to individuals or communities. This project trains YOLOv8 models to automatically detect and classify memes into distinct categories, enabling content moderation at scale.
Two separate models are trained:
- English Memes Model — general meme classification
- Arabic Memes Model — Arabic-language meme classification
| Label | Description |
|---|---|
normal |
Neutral, harmless meme content |
harmful-to-individual |
Content that targets or harms individuals |
community-society-organization |
Safe community/social content |
| Model | mAP50 | mAP50-95 | Precision | Recall |
|---|---|---|---|---|
| English Memes | 0.685 | 0.661 | 0.456 | 0.851 |
| Arabic Memes | 0.992 | 0.992 | 0.957 | 0.973 |
The Arabic model was trained on a more balanced and curated dataset, yielding significantly higher performance.
Memes/
├── MemesData.ipynb # Training pipeline for English memes
├── ArabicMemesData.ipynb # Training pipeline for Arabic memes
└── README.md
- Model: YOLOv8 nano (
yolov8n.pt) — Ultralytics - Training: Google Colab (Tesla T4 GPU, CUDA 12.2)
- Optimizer: AdamW
- Framework: Python, PyTorch
| Hyperparameter | Value |
|---|---|
| Epochs | 300 |
| Batch Size | 16 |
| Image Size | 640 × 640 |
| Optimizer | AdamW |
| Early Stopping Patience | 200 |
| Confidence Threshold (inference) | 0.25 |
pip install ultralyticsgit clone https://github.com/Afzal632/Memes.git
cd MemesUpload either notebook to Google Colab and mount your Google Drive:
from google.colab import drive
drive.mount('/content/drive')Place your dataset in Google Drive following this structure:
/content/drive/MyDrive/
└── your-dataset/
├── data.yaml
├── train/
│ ├── images/
│ └── labels/
├── valid/
│ ├── images/
│ └── labels/
└── test/
├── images/
└── labels/
Run all cells in the notebook. The pipeline will:
- Check GPU availability
- Install dependencies
- Train the model (resumes from checkpoint if
last.ptexists) - Validate on the test set
- Run inference and display predictions
# Train
!yolo task=detect mode=train model=yolov8n.pt \
data=data.yaml \
epochs=300 \
batch=16 \
imgsz=640 \
optimizer=AdamW \
patience=200 \
plots=True
# Validate
!yolo task=detect mode=val model=runs/detect/train/weights/best.pt data=data.yaml
# Predict
!yolo task=detect mode=predict model=runs/detect/train/weights/best.pt \
conf=0.25 source=datasets/test/images- The English model has high recall (0.851) but lower precision (0.456), meaning it catches most harmful memes but produces some false positives.
- The Arabic model achieves near-perfect scores, though results should be interpreted carefully given the smaller test set size.
- Models are saved as
best.ptandlast.ptand can be reused for inference without retraining.
- Social media content moderation
- Automated flagging of harmful meme content
- Research on Arabic and English online harmful content
- Dataset labeling assistance
This project is intended for academic and research purposes.