Skip to content

EngAdhamTamer/hieroglyph-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›๏ธ Ancient Egyptian Hieroglyph Detection & Segmentation

Python YOLOv8 License OpenCV

An AI-powered computer vision system for detecting and segmenting ancient Egyptian hieroglyphs from archaeological images using YOLOv8 instance segmentation.

๐Ÿ“‹ Table of Contents

๐ŸŽฏ Overview

This project implements a deep learning solution for automatically detecting and segmenting individual hieroglyphs from images of ancient Egyptian inscriptions, temple walls, and artifacts. The system uses YOLOv8's instance segmentation architecture to identify hieroglyphs with pixel-level precision.

Key Highlights

  • 235,436 hieroglyph instances in training dataset
  • 70.9% mAP@0.5 on validation set
  • Real-time inference with user-friendly GUI
  • Advanced preprocessing pipeline for archaeological images

โœจ Features

  • Instance Segmentation: Precise pixel-level masks for each hieroglyph
  • Multi-scale Detection: Works on hieroglyphs of varying sizes
  • Preprocessing Pipeline:
    • CLAHE contrast enhancement
    • Non-local means denoising
    • Image normalization and resizing
  • Interactive GUI: Tkinter-based interface for easy inference
  • Visualization: Confidence scores and bounding boxes overlay

๐Ÿ“Š Model Performance

Metrics (Validation Set)

Metric Score
mAP@0.5 70.9%
mAP@0.5:0.95 42.5%
Precision 100% @ conf=1.0
Recall 62% @ conf=0.0
F1-Score 75% @ conf=0.398

Training Configuration

  • Model: YOLOv8n-seg (nano variant)
  • Epochs: 25
  • Batch Size: 8
  • Image Size: 640ร—640
  • Optimizer: SGD (lr=0.01)
  • Device: CUDA (GPU accelerated)

Performance Curves

F1 Curve BoxF1 Curve

Precision-Recall Curve MaskF1 Curve

Confusion Matrix

Confusion Matrix Confusion Matrix Normalized

Training Metrics

Training Loss Training Results

๐Ÿ“ Dataset

The dataset consists of annotated images from various Egyptian archaeological sites including:

  • Temple wall inscriptions
  • Obelisk carvings
  • Papyrus documents
  • Stone tablets and stelae

Dataset Statistics:

  • Total Instances: 235,436 hieroglyphs
  • Train/Val/Test Split: Standard YOLO format
  • Annotation Format: YOLO segmentation (polygon coordinates)
  • Single Class: "hieroglyph" (unified approach)

๐Ÿš€ Installation

Prerequisites

  • Python 3.8+
  • CUDA-compatible GPU (recommended)
  • 8GB+ RAM

Setup

  1. Clone the repository
git clone https://github.com/EngAdhamTamer/hieroglyph-detection.git
cd hieroglyph-detection
  1. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Download pre-trained weights
# Download from releases
# Place best.pt in runs/segment/hieroglyph_seg/weights/

See DOWNLOAD_MODELS.md for detailed instructions.

๐Ÿ’ป Usage

GUI Application

Run the interactive GUI for easy image inference:

python gui2.py

Steps:

  1. Click "Load Image"
  2. Select an image with hieroglyphs
  3. View detection results with masks and bounding boxes

Training from Scratch

python train_yolo.py

Modify train_yolo.py to adjust:

  • Number of epochs
  • Batch size
  • Learning rate
  • Data augmentation parameters

Data Preprocessing

Preprocess your dataset before training:

python preprocessing.py

This applies:

  • Resizing to 640ร—640
  • CLAHE contrast enhancement
  • Denoising
  • Normalization

Label Conversion

Convert multi-class labels to single class:

python preprocessing_labels.py

๐Ÿ“‚ Project Structure

hieroglyph-detection/
โ”œโ”€โ”€ dataset/
โ”‚   โ”œโ”€โ”€ train/
โ”‚   โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”‚   โ””โ”€โ”€ labels/
โ”‚   โ”œโ”€โ”€ valid/
โ”‚   โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”‚   โ””โ”€โ”€ labels/
โ”‚   โ”œโ”€โ”€ test/
โ”‚   โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”‚   โ””โ”€โ”€ labels/
โ”‚   โ””โ”€โ”€ data.yaml
โ”œโ”€โ”€ runs/
โ”‚   โ””โ”€โ”€ segment/
โ”‚       โ””โ”€โ”€ hieroglyph_seg/
โ”‚           โ”œโ”€โ”€ weights/
โ”‚           โ”‚   โ””โ”€โ”€ best.pt
โ”‚           โ””โ”€โ”€ results/
โ”œโ”€โ”€ preprocessing.py
โ”œโ”€โ”€ preprocessing_labels.py
โ”œโ”€โ”€ train_yolo.py
โ”œโ”€โ”€ gui2.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ args.yaml
โ””โ”€โ”€ README.md

๐ŸŽจ Results

Detection Example

Hieroglyph Detection Results

The model successfully detects and segments 235K+ hieroglyph instances with precise pixel-level masks. Each detected hieroglyph is highlighted with a green segmentation mask and red bounding box, demonstrating the system's ability to identify individual symbols even in dense inscriptions.

Training Performance

Training Metrics

The training curves show consistent improvement across all metrics over 25 epochs:

  • Loss curves (top row): Steady decrease in box, segmentation, classification, and DFL losses for both training and validation sets
  • Precision & Recall (middle row): High precision (~95%) and recall (~59%) on both bounding boxes and masks
  • mAP scores (right columns): Achieved 70.9% mAP@0.5 and 42.5% mAP@0.5:0.95, indicating robust detection performance

The validation metrics closely track training metrics, demonstrating good generalization without overfitting.

Additional Visual Examples

Validation Predictions Validation Labels Detection 2 More Predictions

Confusion Matrix Analysis

  • True Positives: 59,608 hieroglyphs correctly detected
  • False Positives: 1,532 (2.5% error rate)
  • Strong background discrimination

๐Ÿ”ฎ Future Work

  • Multi-class classification (different hieroglyph types)
  • Hieroglyph recognition and translation
  • Mobile app deployment
  • Sequence analysis for reading order
  • Integration with archaeological databases
  • 3D surface reconstruction support
  • Real-time video processing

๐Ÿ‘ฅ Contributors

This project was developed as a university Computer Vision course project by:

๐Ÿ™ Acknowledgments

  • Ultralytics for the YOLOv8 framework
  • Computer Vision Course instructors and teaching assistants
  • Egyptian archaeology community for domain expertise
  • Open-source computer vision community

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ง Contact

Adham Tamer

๐ŸŒŸ Star History

If you find this project useful, please consider giving it a star! โญ


Built with โค๏ธ for preserving ancient Egyptian heritage through AI

About

AI-powered detection and segmentation of ancient Egyptian hieroglyphs using YOLOv8 instance segmentation | 70.9% mAP@0.5 | 235K instances

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages