Hieroglyph classifier (Gardiner sign codes)

A CNN that names a photographed Egyptian hieroglyph by its Gardiner code. Trained on 3,674 manually labelled glyph crops (50×75 px) from the Pyramid Texts of Unas (GlyphDataset, Franken & van Gemert, ACM Multimedia 2013, MIT), covering the 59 signs with at least ten examples.

Metric (held-out test glyphs, 735) Value
Top-1 accuracy 0.969
Top-5 accuracy 0.997
Macro F1 0.939
Confidence gate ≥ 0.95 answers 90% of glyphs at 99.5% accuracy

Code, figures and the failed first run: GitHub · demo · Kaggle notebook · write-up: Teaching a CNN to read hieroglyphs · omaressam.web.app

Use

import json, numpy as np, tensorflow as tf
from PIL import Image
from huggingface_hub import hf_hub_download

model = tf.keras.models.load_model(hf_hub_download("omaressamrme/hieroglyph-classifier", "model.keras"))
labels = json.load(open(hf_hub_download("omaressamrme/hieroglyph-classifier", "labels.json")))["labels"]
img = Image.open("glyph.png").convert("L").resize((50, 75))          # width 50, height 75
x = (np.asarray(img, dtype="float32") / 255.0)[None, ..., None]      # (1, 75, 50, 1), values in [0, 1]
p = model.predict(x)[0]
print([(labels[i], round(float(p[i]), 3)) for i in p.argsort()[::-1][:5]])

Input: a single, already-cropped sign, dark strokes on a light background. The model does not detect signs in a wall photograph and does not translate.

Architecture and training

Three blocks of two 3×3 convolutions (32, 64, 128 filters) with BatchNorm, max-pooling and dropout, a Flatten layer, a 256-unit dense layer with BatchNorm and dropout 0.5, and a 59-way softmax (2.1 M parameters). Adam 1e-3 with ReduceLROnPlateau, batch 32, square-root-damped class weights, light translation/zoom augmentation with white fill, early stopping on validation accuracy (patience 20). 54 epochs, best at 34, 14 minutes on CPU. train_v2.py in this repo is the exact script; metrics.json and results/ hold every number.

Limitations

One monument, one carving style, one lighting; rare signs (fewer than 20 training glyphs) are the weak ones; 113 of the dataset's 172 codes have too few examples to be covered.

Dataset citation: M. Franken and J. C. van Gemert, "Automatic Egyptian Hieroglyph Recognition by Retrieving Images as Texts", ACM Multimedia 2013.

Downloads last month
41
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Space using omaressamrme/hieroglyph-classifier 1

Evaluation results

  • Top-1 accuracy on GlyphDataset (Franken & van Gemert 2013), manual annotations
    self-reported
    0.969
  • Top-5 accuracy on GlyphDataset (Franken & van Gemert 2013), manual annotations
    self-reported
    0.997
  • Macro F1 on GlyphDataset (Franken & van Gemert 2013), manual annotations
    self-reported
    0.939