Ageis: Image Safety Classifier for Content Moderation (DINOv3 ViT-H+/16)
Ageis is a binary image classifier that works as a safety guardrail in image pipelines. It scores each image with the probability that it contains NSFW (Not Safe for Work) content, so that such images can be filtered out, blocked, or sent to human review. It is a classifier only and does not generate images.
It is a partial fine-tune of DINOv3 ViT-H+/16: the last 16 of 32 transformer blocks are trained, with a linear head on the concatenation of the CLS token and the mean of the patch tokens, using a BCE loss.
Built with DINOv3. The backbone weights are Meta's and are distributed under the DINOv3 License. This fine-tune is a derivative work of the DINO Materials and ships under the same terms.
Intended Uses & Limitations
Intended uses
- Dataset cleaning: removing NSFW images from large web-scraped corpora at a chosen recall / false-positive operating point.
- Automated content moderation: a first-pass filter in trust-and-safety pipelines, ahead of human review.
- Upload screening: blocking sensitive images before they are stored or shown.
Limitations
- Domain specificity: the model is specialised for NSFW vs. clean classification. It is not a general-purpose image classifier.
- Cultural context: what counts as NSFW varies between communities. Calibrate the threshold to your own content policy.
- Not a final decision-maker: use human review for high-stakes decisions.
- BF16 saturation / calibration: the head is scaled by 1/6 (see "Post-release head scaling") and the final backbone LayerNorm is scaled by the reliability edit (see "Post-release backbone edit"). The current weights use 0.9959 for 95% recall and 0.7892 for 99% recall on the benchmark below; calibrate on your own data if the domain differs.
Evaluation
Ageis was compared with Falconsai/nsfw_image_detection_26 on about 100,000 held-out images. Training and validation shards were chosen with a fixed random seed (train 42, bench 43); the benchmark rebuilds those selections and uses only shards never seen in training or validation.
Test set composition:
| slice | content | label | images |
|---|---|---|---|
| explicit photos | explicit photographic content | NSFW | 20,000 |
| suggestive photos | suggestive print scans | NSFW | 20,000 |
| explicit illustrations | explicit illustrated content | NSFW | 10,000 |
| LAION humans | photos of people, filtered clean | clean | 20,000 |
| ImageNet-21k | general photographs | clean | 15,000 |
| Safebooru | safe illustration and anime artwork | clean | 15,000 |
FPR at a given recall is the fraction of clean images wrongly flagged when the threshold is set to catch that fraction of NSFW images. The table below is the original release benchmark; see "Post-release head scaling" for the current weights.
| metric | Ageis | Falconsai-26 |
|---|---|---|
| ROC-AUC | 0.9985 | 0.9646 |
| PR-AUC | 0.9974 | 0.9671 |
| FPR at 95% recall | 0.23% | 20.40% |
| FPR at 99% recall | 0.51% | 42.01% |
At 95% recall Falconsai-26 wrongly flags about 1 in 5 clean images and Ageis about 1 in 443. At 99% recall the original Ageis threshold was 0.859; the head-only scaled weights use 0.570 (see below), and the current backbone-edited weights use 0.7892 (see "Post-release backbone edit").
Per-slice results, each model at its own 95%-recall threshold (1.0 for Ageis, 0.0154 for Falconsai-26). For NSFW slices the number is recall (higher is better); for clean slices it is the false-positive rate (lower is better):
| slice | type | Ageis | Falconsai-26 |
|---|---|---|---|
| ImageNet-21k | clean, FPR | 0.007% | 3.73% |
| LAION humans | clean, FPR | 0.11% | 4.76% |
| Safebooru | clean, FPR | 0.60% | 57.92% |
| explicit photos | recall | 99.40% | 97.30% |
| suggestive photos | recall | 98.96% | 92.98% |
| explicit illustrations | recall | 94.82% | 94.48% |
Post-release head scaling (BF16 fix)
The original head produced logits large enough that the BF16 sigmoid saturated
at 1.0. At the benchmark's 95%-recall target the ROC therefore jumped from
91.6% to 98.3% recall at threshold 1.0, so the "FPR@95" point actually operated
at 98.3% recall and threshold tuning below 1.0 was impossible. The current
weights divide head.weight and head.bias by 6 and round to BF16. No
retraining was performed.
On the current benchmark snapshot:
| metric | original head (BF16 path) | scaled head |
|---|---|---|
| ROC-AUC | 0.9987 | 0.9996 |
| PR-AUC | 0.9979 | 0.9996 |
| FPR @ 95% recall | 0.180% | 0.034% |
| actual recall at that point | 98.30% | 95.16% |
| FPR @ 98.3% recall | 0.180% | 0.184% |
| FPR @ 99% recall | 0.410% | 0.410% |
The scaled head gives a true 95% operating point (0.034% FPR) instead of a 98.3% point. At equal recall the two heads are effectively tied (0.180% vs 0.184% at 98.3%; both 0.410% at 99%); the practical gain is that the scaled head can actually hit 95% recall instead of jumping from 91.6% to 98.3%. The AUC gain comes from breaking BF16 score ties. The recommended thresholds for the head-only weights are 0.914 at 95% recall and 0.570 at 99% recall. The backbone edit below changes the logit scale; for the current weights use 0.9959 at 95% recall and 0.7892 at 99% recall. The 1/6 factor was selected on a 25% validation split; the held-out 25% test split gives AUC 0.9995 and FPR@95 0.032% (its FPR@99 is 0.608%, based on only 12.5k clean images and therefore noisy). The full benchmark is the headline above.
The benchmark's earlier saved numbers (AUC 0.9985, PR 0.9974, FPR@95 0.23%, FPR@99 0.51%) were produced with the original head and a slightly different LAION shard snapshot. The five non-LAION slices reproduce to four decimals on the current snapshot; the current LAION slice has no false positives at the 95% point. Do not attribute the 0.51% to 0.41% change to the head scaling: on the current snapshot the original head also scores 0.41% at 99% recall.
Per-slice rates on the current snapshot at 99% recall are essentially unchanged by the edit (explicit photos 99.7%, suggestive photos 99.4%, explicit illustrations 96.8%, Safebooru FPR 1.33%, ImageNet-21k FPR 0.03%, LAION humans FPR 0.00%). At 95% recall the scaled head reports the actual 95% operating point: explicit photos 97.1%, suggestive photos 97.2%, explicit illustrations 87.1%, Safebooru FPR 0.11%, ImageNet-21k 0.00%, LAION humans 0.00%.
A note on label noise. Visual audit of the tail errors shows that many
lowest-scoring nsfw_cartoon/ns_slight_nsfw images are safe images labelled
NSFW, and many highest-scoring clean_cartoon images are explicit or highly
suggestive. Rank-one and sparse head-edit directions selected on a validation
split did not improve FPR@99 robustly across five random splits. The remaining
benchmark errors are therefore dominated by label noise, not by an obvious
linear head deficiency. Audit the top-scoring "clean" images before quoting
FPR to four digits.
Artifacts: bench_results.json (summary, per-slice rates, notes),
bench_scores.csv (the earlier head-only per-image scores), norm_edit.npz
(the fitted a), edit.json (edit metadata), and
backbone_seed_robustness.json (five-seed split check).
Post-release backbone edit (final LayerNorm reliability scaling)
The current weights also contain a backbone-only edit. For each of the 1,280 hidden dimensions, the 50% edit split gives
e_j = (mu1_j - mu0_j) / sd_j
a_j = 1 + (e_j - mean(e)) / rms(e)
where mu1_j and mu0_j are the mean per-dimension contributions to the head
logit for the NSFW and clean halves, and sd_j is the pooled within-class
standard deviation. backbone.norm.weight and backbone.norm.bias are
multiplied by a_j and rounded to BF16. No gradients were used and no
retraining was performed.
Centering e makes mean(a) = 1, so the edit changes relative per-dimension
reliability rather than applying a global feature scale. On this fit,
rms(e) = 1.03 and a ranges from -3.26 to 4.08 (mean 1.0). The final
LayerNorm is the only backbone parameter changed; all transformer blocks,
embeddings, and the head are untouched.
On the same 100,683-image benchmark snapshot:
| metric | head edit only | + backbone edit |
|---|---|---|
| ROC-AUC | 0.999557 | 0.999615 |
| PR-AUC | 0.999592 | 0.999650 |
| FPR @ 95% recall | 0.0335% | 0.0237% |
| FPR @ 99% recall | 0.4104% | 0.3709% |
| test ROC-AUC | 0.999461 | 0.999543 |
| test FPR @ 99% recall | 0.6235% | 0.5840% |
Per-slice rates on the full snapshot. For NSFW slices the number is recall; for clean slices it is false-positive rate.
| slice | type | base @95 | edit @95 | base @99 | edit @99 |
|---|---|---|---|---|---|
| explicit photos | recall | 97.01% | 97.17% | 99.705% | 99.690% |
| suggestive photos | recall | 97.17% | 97.39% | 99.400% | 99.485% |
| explicit illustrations | recall | 86.86% | 86.05% | 96.800% | 96.650% |
| Safebooru | FPR | 0.112% | 0.079% | 1.343% | 1.224% |
| ImageNet-21k | FPR | 0.000% | 0.000% | 0.033% | 0.020% |
| LAION humans | FPR | 0.000% | 0.000% | 0.000% | 0.000% |
The overall trade is lower false positives at both operating points and lower
explicit-illustration recall: 86.86% -> 86.05% at 95% and 96.80% -> 96.65% at
99% on the full snapshot. On the held-out 25% test split, illustration recall
at 95% is unchanged (87.64%), at 99% falls from 96.72% to 96.60%, and
Safebooru FPR at 99% falls from 2.04% to 1.90%. The illustration drop is the
main cost of the edit. A non-centered variant (mean(a) = 1.73) preserved more
illustration recall but had worse overall AUC/FPR, so it was not released.
The edit was checked on five split seeds (42-45 and 2026): test ROC-AUC
improves on all five (+4.5e-5 to +8.1e-5), FPR@95 improves by 0.8-1.6 basis
points, and FPR@99 improves on four of five (the fifth is 0.8 basis points
worse). Full-snapshot AUC is stable at about +5.8e-5. The edit is stored in
norm_edit.npz (a, e, mu1, mu0, sd), with a summary in edit.json.
Training Details
- Backbone: facebook/dinov3-vith16plus-pretrain-lvd1689m with RoPE train-time jitter disabled. Blocks 0-15 and the embeddings are frozen (stored in bf16). Blocks 16-31, the final norm, and the head are trained.
- Head: Linear(2 x hidden -> 1) on [CLS; mean of patch tokens], BCE-with-logits.
- Data: each batch is half positive, half clean (batch 300 at 224px). The clean half is 30% ImageNet-21k, 30% clean illustrations, 40% filtered LAION humans. The positive half mixes photographic and illustrated sources.
- Optimizer: Lion. Backbone LR 8e-6 with layer-wise decay 0.75, head LR 2e-4, weight decay 0.1 on 2D parameters only, betas (0.9, 0.99), gradient clipping 1.0.
- Schedule: 1k warmup steps, then cosine decay.
- Augmentations: RandomResizedCrop (scale 0.65-1.0), horizontal flip, random downscale-upscale (p=0.25), JPEG re-encode at quality 30-90 (p=0.35). No colour jitter, because skin tone is part of the signal.
- bf16 autocast and torch.compile on a single RTX 6000 Pro (96 GB).
Hardware Requirements
0.84B parameters, 1.68 GB of weights in bf16. At 224x224 it runs on a single T4 (16 GB) in fp16 with batch size 768. Use bf16 on Ampere and newer; the T4 (Turing) has no bf16 tensor cores, so use fp16 there.
How to Use
The repo contains the full model: the frozen DINOv3 backbone merged with the fine-tuned blocks, the head, and the normalisation constants. One download; no separate backbone access is needed.
import torch, torch.nn as nn
from huggingface_hub import PyTorchModelHubMixin
from transformers import AutoConfig, AutoModel
class NSFWClassifier(nn.Module, PyTorchModelHubMixin):
def __init__(self, backbone_config: dict):
super().__init__()
self.backbone = AutoModel.from_config(AutoConfig.for_model(**backbone_config))
self.n_reg = self.backbone.config.num_register_tokens
self.register_buffer("mean", torch.zeros(1, 3, 1, 1))
self.register_buffer("std", torch.ones(1, 3, 1, 1))
self.head = nn.Linear(self.backbone.config.hidden_size * 2, 1)
def forward(self, x): # x: (B,3,224,224) uint8 RGB
x = (x.to(self.mean.dtype) / 255 - self.mean) / self.std
h = self.backbone(pixel_values=x).last_hidden_state
feat = torch.cat([h[:, 0], h[:, 1 + self.n_reg:].mean(1)], dim=1)
return torch.sigmoid(self.head(feat).squeeze(1).float()) # p(nsfw)
# current weights: p >= 0.9959 -> 95% recall; p >= 0.7892 -> 99% recall
# on a T4 or other Turing GPU use .to(torch.float16) instead of bfloat16.
model = NSFWClassifier.from_pretrained("masterofaudio2077/Ageis-image-safety-classifier-dinov3").to("cuda").to(torch.bfloat16).eval()
Preprocessing is a resize of the short side to 256 followed by a 224 center crop, RGB uint8. Normalisation happens inside the model:
from PIL import Image
import numpy as np
def preprocess(path, size=224):
im = Image.open(path).convert("RGB")
s = 256 / min(im.size)
im = im.resize((round(im.width * s), round(im.height * s)), Image.BILINEAR)
l, t = (im.width - size) // 2, (im.height - size) // 2
a = np.asarray(im.crop((l, t, l + size, t + size)), dtype=np.uint8)
return torch.from_numpy(a).permute(2, 0, 1)
with torch.no_grad():
p = model(preprocess("image.jpg").unsqueeze(0).to("cuda"))
print(f"p(nsfw) = {p.item():.4f}")
Sufficiency heatmap (interpretability)
heatmap.py
shows where in an image the classifier finds enough evidence on its own. It
shows one small window at a time on a blank gray canvas, reads the logit, and
averages the logit per pixel over sliding windows. Red means that region alone
is enough to flag the image; blue means it looks clean on its own.
python heatmap.py image.jpg
python heatmap.py https://example.com/image.jpg --win 48 --stride 16 --out out.png
Requires matplotlib. The README preprocessing and this script use the same
short-side-256 resize and 224 center crop, so the heatmap matches the scores
above. Read the colors as relative evidence, not calibrated logits; logit 0
(p = 0.5) is only the blue/red display boundary, not the production threshold.