Skip to content

About

Hand Paintings in Rock Art — Sex Classification: Deep learning pipeline that classifies hand silhouettes from prehistoric rock art paintings to predict the biological sex of the individuals who created them. Uses EfficientNet-B3 and MobileViT-S trained on X-ray hand images as a proxy dataset.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

84 Commits

Folders and files

Repository files navigation

Hand Paintings in Rock Art — Sex Classification

Deep learning pipeline that classifies hand silhouettes from prehistoric rock art paintings to predict the biological sex of the individuals who created them. Uses EfficientNet-B3 and MobileViT-S trained on X-ray hand images as a proxy dataset.

Dataset: Decoding the Past — Prehistoric Hand Stencils (Kaggle)


1. Environment Setup

Requires Miniconda or Anaconda.

conda create -n rock-art python=3.10.16
conda activate rock-art

# PyTorch with CUDA 11.8
pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cu118

# Remaining dependencies
pip install timm torchsummary "numpy<2.0" scikit-learn pyyaml munch \
            matplotlib torchmetrics opencv-python scikit-image

timm is required for MobileViT configs and is not listed in requeriments.txt.


2. Download the Dataset from Kaggle

The training data comes from the Kaggle dataset:
Decoding the Past — Prehistoric Hand Stencils

# Install Kaggle CLI if needed
pip install kaggle

# Download and extract (requires ~/.kaggle/kaggle.json with your API key)
kaggle datasets download -d karelbecerra/decoding-the-past-in-prehistoric-hand-stencils
unzip decoding-the-past-in-prehistoric-hand-stencils.zip -d datasets/

After extraction the datasets/ folder should contain:

datasets/
├── hand_silhouette/
│   ├── tra_hand_silhouette_400x300.npz   # training set
│   ├── val_hand_silhouette_400x300.npz   # validation set
│   └── tst_hand_silhouette_400x300.npz   # test set
└── cave/                                  # cave painting images

Each .npz file contains images (N, 400, 300, 3) and labels arrays.


3. Train a Model

Single run

python train.py --config hand_mask_b3_all

Override individual parameters without editing the YAML:

python train.py --config hand_mask_b3_all --batch 32 --epochs 50 --run run1

Available configs in configs/:

Config Architecture Dataset
hand_mask_b3_all EfficientNet-B3 Hand silhouette (all ages)
mobilevit_s_all MobileViT-S Hand silhouette (all ages)
cave_b3 EfficientNet-B3 Cave paintings
cave_mobilevit_s MobileViT-S Cave paintings

Checkpoints are saved to output/models/{config}_{run}.pth. Training curves are logged to output/trace/{config}_{run}.csv.

Ensemble training with multi_train.sh

The analysis notebooks expect 10 runs per config. Use multi_train.sh to train them sequentially:

# Train run1 through run10 for a given config
./multi_train.sh hand_mask_b3_all 1 10

# Shorter experiment: 3 runs only
./multi_train.sh mobilevit_s_all 1 3

Each run starts from a different random initialization (same seed logic but different epoch ordering due to DataLoader shuffling), producing 10 independently trained models for ensemble averaging.


4. Run All Experiments with run_all.sh

run_all.sh trains both main configs (EfficientNet-B3 and MobileViT-S) for 10 runs each, redirecting output to .out log files so they can run unattended:

./run_all.sh

This runs:

  • hand_mask_b3_all × 10 → hand_mask_b3_all.out
  • mobilevit_s_all × 10 → mobilevit_s_all.out

Commented-out lines in the script show additional configs (no_infants, teens, mobilevitv2_150) that can be enabled for ablation studies.

Full training (100 epochs × 10 runs × 2 configs) takes several hours on a GPU. Monitor progress via the .out log files or the CSV traces in output/trace/.


5. Notebooks

All notebooks live under notebooks/, grouped by purpose:

notebooks/
├── compute/        # Post-training computation: inference, ensembling, cave analysis
├── visualization/  # Embeddings, UMAP/kNN projections, Class Activation Maps (CAMs)
├── kaggle-ready/    # Self-contained notebooks that run end-to-end on Kaggle
└── misc/            # Exploratory / superseded notebooks kept for reference

compute/ — run in order after training is complete

Notebook 1 — Model Inference (1-data_outputs_model_inference.ipynb)

Loads all 10 trained model checkpoints and runs inference on the train, validation, and test splits. Saves raw logits as .npy files used by the next notebook.

output/data/hand_mask_b3_all_train.npy       # shape (10, N_train, 2)
output/data/hand_mask_b3_all_validation.npy  # shape (10, N_val, 2)
output/data/hand_mask_b3_all_test.npy        # shape (10, N_test, 2)

Set the choice variable at the top of the notebook to switch between configs (b3_all, vit_all, cave_b3, cave_vit). Run it once per config.

Notebook 2 — Ensemble & Segment Analysis (2-data_outputs_ensamble_segments_fixed.ipynb)

Loads the .npy predictions and computes accuracy statistics broken down by age group:

Age segment EfficientNet-B3 (ensemble) MobileViT-S (ensemble)
All ages (test) 84.7% 83.2%
0–6 years 76.2% 61.9%
6–12 years 84.3% 83.1%
12–19 years 87.2% 88.4%

The notebook also outputs:

  • Mean ± SEM across individual runs (shows model stability)
  • Ensemble accuracy using both Sum and Max aggregation strategies
  • Confusion matrices per age segment showing Female/Male classification breakdown
  • A LaTeX table ready for paper inclusion

Key finding: classification accuracy improves with age. Young children (0–6 yrs) are harder to classify, likely because sex-linked hand morphology differences are less pronounced before puberty.

Notebook 3 — Cave Painting Analysis (3-data_cave_outputs_analysis.ipynb)

Applies the trained ensembles to actual cave hand paintings. Outputs a CSV with Female/Male predictions and a confidence margin for each image:

combined_model_results_softmax.csv

Each row contains the image name, the margin (positive = Female prediction, negative = Male), and the predicted label from both Sum and Max aggregation for each model config (cave_b3, cave_mobilevit_s).

visualization/

Notebook Purpose
1-compute_embeddings.ipynb Runs the trained EfficientNet ensemble over the cave hand images and their augmented views to extract feature embeddings.
2-fast_smooth_class_prediction_umap_knn_only.ipynb Projects the cached embeddings with UMAP and classifies with a k-NN classifier, without recomputing embeddings — for fast iteration on the visualization itself.
3-cams_only.ipynb Generates Class Activation Maps (CAMs) over the cave hand images to visualize which regions drive each model's prediction.

kaggle-ready/

Self-contained notebooks that clone this repository and pull the dataset directly from Kaggle, meant to be run as Kaggle Code notebooks rather than locally:

Notebook Kaggle
1-data_visualization.ipynb Open in Kaggle
2-training_model.ipynb Open in Kaggle
3-plot_training_loss_accuracy_history.ipynb Open in Kaggle
4-inference_enhanced_hand_data.ipynb Open in Kaggle

misc/

Earlier and exploratory notebooks (ensembling on the 11k Hands dataset, CAM prototyping, superseded ensemble/trace-plot versions, etc.). Kept for reference only — no need to look here unless investigating history.


Data Preprocessing (optional)

If you need to rebuild the NPZ datasets from raw images, the cave/ directory contains the preprocessing pipeline as Jupyter notebooks (v1_ through v5_): silhouette extraction → geometric transformations → augmentation → NPZ export.


Citation

Citation is TBD — the paper is currently under preparation and the venue/journal has not been finalized.

@article{kbecerra2026,
  title={Decoding the Past: An Uncertainty-Aware Deep Learning Framework for Sex Attribution in Prehistoric Hand Stencil},
  author={Karel Becerra, Boris Mederos, Dean Snow, and Ramon A. Mollineda},
  journal={TBD},
  booktitle={TBD},
  year={2026 TBD}
}

About

Hand Paintings in Rock Art — Sex Classification: Deep learning pipeline that classifies hand silhouettes from prehistoric rock art paintings to predict the biological sex of the individuals who created them. Uses EfficientNet-B3 and MobileViT-S trained on X-ray hand images as a proxy dataset.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages