This project builds an object-detection style model to detect and classify Musnad script characters in an image.
The system includes:
- A TensorFlow/Keras multi-head CNN that predicts per-grid-cell:
- Objectness (is there a character?)
- Bounding box (x, y, w, h)
- Class (which Musnad character)
- A Flask web app (
app.py) that lets you upload an image and returns an annotated result. - Scripts to train, verify data, and run inference.
A pre-trained model is included:
musnad_detector_multi_head.keras(~76MB)
app.py- Flask UI for uploading an image and showing detection results.
train.py- Training entry point (multi-output losses + callbacks) and saves to
musnad_detector_multi_head.keras.
- Training entry point (multi-output losses + callbacks) and saves to
detect.py- Simple local inference script that runs detection on an image and saves
detection_result.jpg.
- Simple local inference script that runs detection on an image and saves
model.pybuild_musnad_detector()model architecture (CNN backbone + 3 detection heads).
dataset.py- Dataset pipeline (loads prepared dataset splits from
dataset/).
- Dataset pipeline (loads prepared dataset splits from
loss.py- Loss functions for each head: objectness / box / class.
generate_data.py,verify_data.py- Helpers for creating/verifying the dataset.
classes.txt- List of Musnad character classes (one character per line).
- Reports/docs:
walkthrough.mdacademic_technical_report.mdcomplete_project_report.mdfinal_academic_report.md
- Input size:
224x224 - Grid size:
S = 7(7x7 cells) - Outputs (per cell):
obj_output: shape(7, 7, 1)with sigmoidbox_output: shape(7, 7, 4)with sigmoid (relative offsets/sizes)cls_output: shape(7, 7, num_classes)with softmax
Defined in model.py:
- CNN backbone: stacked
Conv2D + BatchNorm + LeakyReLU + MaxPoolblocks - Final feature layer:
Conv2D(1024) - Heads: 1x1 conv layers for each output head
File: train.py
- Batch size:
32 - Epochs:
20 - Optimizer:
Adam(lr=1e-4) - Uses separate losses + loss weights:
obj_output: 1.0box_output: 5.0 (emphasize box quality)cls_output: 1.0
- Callbacks:
ModelCheckpoint(best onval_loss)ReduceLROnPlateauEarlyStopping
Expected dataset folder (relative to project root):
dataset/with splits liketrainandval(seedataset.py).
File: app.py
- Loads
musnad_detector_multi_head.keras. - Uploads are stored under:
static/uploads/. - Draws red bounding boxes and labels on the original image.
Run:
python app.pyThen open:
http://127.0.0.1:5000
File: detect.py
- Loads model and runs prediction.
- Saves output image as:
detection_result.jpg.
Note: detect.py loads CLASSES_FILE dynamically from the local project path (classes.txt).
- The project includes multiple report markdown files;
walkthrough.mdis a good quick overview. - The Keras model file is already included, so you can run inference without training.
musnad-character-detector-tf-flaskmusnad-script-object-detectionmusnad-multihead-detector-keras