← Back
research /

Estimating age and sex from dental X-rays with a single shared network

I trained a single model to estimate age and predict biological sex from the same panoramic radiograph. It gets sex right 96% of the time and age within 3 years on average, and the two tasks turn out to fail at opposite ends of life.

A dim panoramic dental X-ray on a black background. An orange line runs from one of the front teeth to an orange probability bar, and a white line runs from a lower tooth to a small age ruler.

When someone has to be identified from remains, after a disaster or in a criminal case, two of the first questions are how old the person was and whether they were male or female. Teeth are often what’s left to answer them. They’re the hardest tissue in the body, they survive fire and water, and they carry a surprising amount of information about the person they belonged to.

Dentists answer those questions from a panoramic radiograph, or OPG, a single X-ray that unrolls both jaws into one flat picture. In a child, age is written in which teeth have come in and how far their roots have grown. In an adult, it shows up more slowly, as wear, fillings, lost teeth and changes in the bone. Sex is written in the shape and size of the jaw, which only really starts to differ after puberty.

This project came before my thesis. It’s a collaboration between the Faculty of Computer Science at UPN “Veteran” Jawa Timur, where I study, and the School of Dental Medicine at Universitas Ciputra in Surabaya, who brought the dental side of the problem. The question I started with was simple. Both answers come from the same picture, so why train two networks? I trained one network with two outputs on 5,203 radiographs, and it got sex right 96.0% of the time and age within 3.05 years on average. The more interesting part was where it fails, because the two tasks break down at opposite ends of life.

The data

The radiographs come from two healthcare centres in Indonesia. The youngest person is 4 years old and the oldest is 88. About 40% of the set is between 18 and 30, which is common for dental data, since that’s who gets panoramic X-rays for wisdom teeth and orthodontics. There are also almost twice as many women as men.

Histogram of ages in 4-year bins, split into 3,383 women and 1,820 men. The bars peak sharply between 20 and 24 years, with a median of 25, and thin out steadily after 40, with very few people over 70.
The age range is wide, but most of the data sits in young adults. Older people are rare, and that matters later.

Every image is resized to 384 by 768 pixels, keeping the wide shape of the panoramic. During training the images get flipped left to right at random and have a few small patches blanked out (cutout), so the model can’t lean too hard on any single tooth.

The model

The model is one ResNeXt-50 backbone, pretrained with semi-weakly supervised learning on almost a billion Instagram images. It reads the radiograph and squeezes it down into 2,048 numbers. Two small heads sit on top of those numbers. The sex head is one hidden layer that outputs the probability that the person is male. The age head is three hidden layers that output a single number, squashed into 0 to 100 years with a sigmoid.

The model. A 384 by 768 radiograph goes through a shared ResNeXt-50 backbone into one vector of 2,048 numbers. A small sex head turns it into P(male), and a deeper age head turns it into an age from 0 to 100. During training, a BCE loss and a Smooth L1 loss are combined with learned task weights.
Both heads read the same 2,048 numbers. Only the two small heads and the loss weighting differ per task.

The age head is bigger on purpose. Age is the harder task, and I wanted it to match the head of my age-only model, so I could compare the two fairly later on.

Sharing the backbone could go either way. The tasks look at the same teeth and the same jaws, so features learned for one might help the other. They might also fight over what those 2,048 numbers should encode, and over which task gets to steer training. That second problem turned out to be very real.

Two losses on different scales

Each head has its own loss. The sex head uses binary cross entropy, and the age head uses Smooth L1 on age divided by 100. Training needs one number to minimize, so the two have to be added together somehow, and that’s where it gets awkward.

Raw training losses on a log scale over 80 epochs. The sex loss falls from 0.78 to 0.28 and the age loss from 0.021 to 0.0002, so they start 37 times apart and end about 1,500 times apart.
The two raw losses start 37 times apart, and the gap grows past a thousand as the age loss keeps shrinking.

If you add them as they are, the sex loss is so much bigger that the age head barely gets a say in how the backbone learns. You can multiply each loss by a hand-picked weight, and I tried that first. In an earlier sweep on a smaller held-out split, the run that pushed hardest on age got one of the best age errors, and its sex accuracy dropped to 47%. That’s worse than flipping a coin, on a task the same network otherwise gets 96% right.

So instead of picking weights by hand, I let the model learn them, using the uncertainty weighting from Kendall, Gal and Cipolla. Each task tt gets a learnable number sts_t, and the total loss is

L=12e−ssexLsex+12e−sageLage+12(ssex+sage)\mathcal{L} = \tfrac{1}{2} e^{-s_{\text{sex}}} \mathcal{L}_{\text{sex}} + \tfrac{1}{2} e^{-s_{\text{age}}} \mathcal{L}_{\text{age}} + \tfrac{1}{2}\left(s_{\text{sex}} + s_{\text{age}}\right)

The first two terms scale each loss down by este^{s_t}. The last term stops the model from cheating by making every sts_t huge. At the optimum, este^{s_t} ends up equal to the loss itself, so each task enters training at roughly the same scale no matter how big its raw loss is.

The sex labels also get label smoothing of 0.05. Instead of training toward exactly 0 or 1, the target becomes 0.05 or 0.95. That keeps the sex head from becoming wildly overconfident, and it has a side effect I’ll come back to.

How I evaluated it

With 5,203 images, a single test split of a few hundred is noisy, especially once you start slicing it by age. So I used 5-fold out-of-fold evaluation. The data is split into five parts, balanced by sex and age. Five models are trained, each one on four parts, and each is tested on the part it never saw. In the end every radiograph has exactly one prediction from a model that didn’t train on it, so all 5,203 count toward the results.

One honest caveat. The held-out fold was also used to pick which epoch to keep, so these numbers are a little optimistic. My age-only model used a separate inner validation set for that, which makes the comparison later on conservative rather than flattering.

Training ran on Kaggle with two free T4 GPUs. The five folds took 7.8 hours of training in total, up to 80 epochs each with early stopping.

How well it does

5,203 radiographs, out of fold Result 95% interval Spread across folds
Age, mean absolute error 3.05 years 2.97 to 3.14 0.13
Age, within 5 years 81%
Age, R² 0.936 0.005
Sex, accuracy 96.0% 95.5 to 96.5 0.4 points
Sex, AUC 0.975 0.970 to 0.980 0.002
Sex, right on men / on women 94.5% / 96.8%

The intervals come from resampling the radiographs 1,000 times. The fold spread is small, so no single lucky fold is carrying the result.

Predicted against true age for 5,203 radiographs, drawn as a density grid. Predictions hug the diagonal for children, spread out from about age 30, and fall below the diagonal for people over 60.
Each cell counts radiographs in a 2 by 2 year box. Tight for children, loose for adults, and too young for the elderly.

That picture already tells most of the age story. For children the predictions sit right on the line. From about 30 they fan out. Past 60 they bend below the line, and the model guesses people over 60 to be 4.5 years younger than they are on average. There are only 415 of them in the data, and an elderly mouth can look a lot like a middle-aged one with bad luck.

Opposite ends of life

Splitting both tasks by age is where it gets interesting.

Age MAE by age group. Under 10 0.9 years, 10 to 15 1.6, 15 to 20 2.3, 20 to 30 2.2, 30 to 40 4.3, 40 to 50 4.7, 50 to 60 4.4, 60 and over 6.1. Sex accuracy by age group. Under 10 85.5%, 10 to 15 90.2%, 15 to 20 97.6%, 20 to 30 98.5%, 30 to 40 98.5%, 40 to 50 97.7%, 50 to 60 97.8%, 60 and over 94.9%. The overall accuracy is 96.0%.
Age error grows about 7 times from the youngest group to the oldest. Sex accuracy does the reverse, weakest in children and almost perfect in adults.

Age is easiest in children. Under 10, the model is off by 0.9 years on average, because developing teeth follow a fairly fixed schedule. By 60 and over the error is 6.1 years, since adult teeth mostly change through wear and treatment, which depend as much on the person’s life as on their age.

Sex is the mirror image. Under 10 it’s right only 85.5% of the time, and from 15 to 60 it never drops below 97.6%. Before puberty, boys’ and girls’ jaws just aren’t very different. Of the 208 radiographs where the model got sex wrong, 117 belong to children under 15, a group that makes up only 18% of the data. Every study I found that splits sex accuracy by age reports the same thing, so it doesn’t look like a quirk of my data.

The nice consequence is that the two kinds of mistakes rarely land on the same person. Below 60, the radiographs where sex was wrong don’t have noticeably worse age errors than the rest of their age group. Over 60 they do, 8.2 years against 6.0, though that’s only 21 radiographs.

Some tested radiographs

Here’s what that looks like on single cases, all predicted by a model that never saw them.

Four held-out radiographs. A 5-year-old boy, age predicted 7.0 and P(male) 0.93, right. A 44-year-old woman, age predicted 44.8 and P(male) 0.09, right. A 44-year-old man, age predicted 24.8, almost 20 years too young, with sex right. A 75-year-old man with no teeth, age predicted 56.0 and P(male) 0.26, wrong on both.
The triangle marks the true age and the orange dot the prediction. The bar is the predicted probability of male, and the dashed line is the 0.5 cutoff.

The first two are the normal case. The 5-year-old still has baby teeth with adult teeth forming underneath, and the model lands within two years. The 44-year-old woman is nearly exact.

The third one I find hard to blame the model for. This man is 44, but his teeth are all there and in good shape, and the model guessed 25. Some people’s mouths simply look young.

The last one is the worst case in the figure. A 75-year-old man with no teeth left at all. Most of the age clues are gone, and so is a lot of what the model uses for sex, so it guessed a 56-year-old woman. That’s the over-60 problem in one picture.

What sharing costs

The question I cared most about was whether sharing the backbone costs the age task anything. My age-only model has the same backbone, input size, age head, optimizer and schedule. Comparing the two on the same 5,202 radiographs, one image at a time, the multi-task model is worse at age by 0.32 years on average (0.26 to 0.38).

Extra age error of the multi-task model compared with the age-only model on the same images. Under 20 plus 0.43 years, 20 to 30 plus 0.20, 30 to 40 plus 0.57, 40 to 50 plus 0.29, 50 to 60 plus 0.42, 60 and over 0.00, all plus 0.32. In every fold the kept checkpoint has a higher age MAE than the best age epoch. Fold 1 kept 3.12, best 3.00. Fold 2 kept 3.00, best 2.96. Fold 3 kept 3.24, best 3.13. Fold 4 kept 2.88, best 2.84. Fold 5 kept 3.12, best 2.97.
Left, how much worse the multi-task model is at age than the age-only model, per age group. Right, each fold kept the epoch with the best sex accuracy, which is never the one with the best age error.

The cost shows up in every age group except the oldest, where both models are equally bad. It’s not a controlled comparison, though. The two runs differ in how they pick the final checkpoint, in the exact fold split, in one extra image in the dataset release and in the cutout size. So 0.32 is what this multi-task model costs against this age-only model, not a clean measurement of what sharing costs in general.

I could find one piece of the gap. The rule for keeping a checkpoint was sex accuracy minus 0.2 times the age error divided by 100. That sounded balanced when I wrote it. Worked out, one whole year of age error is worth 0.002 accuracy, about two radiographs in a fold of 1,041. So in practice, the rule picks the epoch with the best sex accuracy, and it did in all five folds. Keeping the best age epoch instead would have gained 0.09 years, at a cost of half a point of sex accuracy. That’s less than a third of the 0.32 gap, so most of the cost comes from somewhere else, but it’s a cheap fix for next time.

The label smoothing left a mark too. Because the training targets were 0.05 and 0.95, the model’s probability of male never goes below 0.08 or above 0.97, even when it’s sure. For women it’s actually underconfident, 91.0% confident on average while being right 96.8% of the time. A single temperature of about 0.84, fit on four folds and tested on the fifth, brings the calibration error from 0.054 down to 0.041. That matters if anyone wants to read the output as an actual probability rather than just a yes or no.

What I’d change

The checkpoint rule needs real weight on age, or two checkpoints, one per task. The comparison with the age-only model needs both runs on the same folds with the same selection rule, so the 0.32 years can be read as the cost of sharing and nothing else. And the oldest group needs more data. With 415 people over 60, the model never really learned what an 80-year-old mouth looks like.

Under the hood

Every fold’s predictions, training history and the full evaluation report are saved with the run, and all the charts in this post are redrawn straight from those files.

Setting Value
Backbone ResNeXt-50 32×4d, SWSL pretrained
Input 384 × 768, random flip, cutout up to 3 patches
Sex head 1 hidden layer of 256, LayerNorm, GELU, dropout 0.25
Age head 3 hidden layers of 512, LayerNorm, GELU, dropout 0.25, sigmoid × 100
Losses BCE with label smoothing 0.05, Smooth L1 on age / 100
Task weighting learned uncertainty weights
Optimizer AdamW, learning rate 7.5e-5 backbone and 1e-3 heads, cosine schedule
Batch 16 per GPU × 2 GPUs × 2 accumulation steps = 64
Epochs up to 80, early stopping after 20 without improvement
Evaluation 5-fold out of fold, stratified by sex and age, 1,000 bootstrap resamples
Hardware 2 × T4 on Kaggle, 7.8 hours of training for all five folds

Takeaways

One network can do both jobs well. 96% on sex and about 3 years on age from a single forward pass is a useful starting point for forensic triage.

The tasks are good at different people. Age is sharp in children and blurry in the elderly, and sex is the other way round. That makes them complementary, but it also means a single headline number hides most of what matters. Anyone using a model like this on a child should trust the age far more than the sex, and on an older adult the reverse.

Sharing wasn’t free here. On the same radiographs, age got about a third of a year worse than my age-only model, and part of that came from a checkpoint rule that quietly cared only about sex.

And small choices leak into everything. A label smoothing of 0.05 capped every probability the model will ever output, and a weight of 0.2 decided which task the final model was good at. Neither looked important when I typed it.

Keep reading

All posts ↗
ESC
↑↓ navigate ↵ open