harveymannering commited on
Commit
66730fc
·
verified ·
1 Parent(s): 9551bb8

Upload DINOv3 face-region classifier (finetuned, epoch 4, val_acc 98.0%)

Browse files
Files changed (3) hide show
  1. README.md +73 -0
  2. config.json +32 -0
  3. dinov3_face_region_classifier.pth +3 -0
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: dinov3-license
4
+ license_link: https://ai.meta.com/resources/models-and-libraries/dinov3-license
5
+ base_model: facebook/dinov3-vits16-pretrain-lvd1689m
6
+ tags:
7
+ - image-classification
8
+ - face-detection
9
+ - pytorch
10
+ - dinov3
11
+ ---
12
+
13
+ # DINOv3 Face-Region Classifier
14
+
15
+ A binary face / non-face classifier finetuned from
16
+ [`facebook/dinov3-vits16-pretrain-lvd1689m`](https://huggingface.co/facebook/dinov3-vits16-pretrain-lvd1689m)
17
+ (DINOv3 ViT-S/16) with a single linear head on the pooled embedding. Given a `224x224` crop, it predicts
18
+ whether that crop contains a face — including non-human, pareidolia-style "faces" (e.g. two dots and a line
19
+ in tree bark or rock formations) — making it useful as a guidance signal for steering image generation
20
+ toward face-like content in a specific image region.
21
+
22
+ ## Training data
23
+
24
+ - **ExpWild** and **iCartoonFace**: real human/cartoon face crops
25
+ - **FacesInThings**: pareidolia face crops (faces seen in inanimate objects/textures)
26
+ - Negatives: same-size random crops from the same images, sampled to not overlap any labeled face box
27
+
28
+ See [FacePareidolia/classifier](https://github.com/harveymannering/FacePareidolia/tree/main/classifier) for the
29
+ full training code (`train.py`, `face_dataset.py`).
30
+
31
+ ## Metrics
32
+
33
+ Best checkpoint (epoch 4/20): **val_loss = 0.061, val_acc = 98.0%** (10% image-level holdout).
34
+
35
+ ## Usage
36
+
37
+ The base DINOv3 checkpoint is gated on Hugging Face, so this repo ships its own `config.json`
38
+ (architecture metadata only — no gated weights) plus the finetuned weights, letting you rebuild the model
39
+ **without** requesting DINOv3 access:
40
+
41
+ ```python
42
+ import torch
43
+ import torch.nn as nn
44
+ from transformers import AutoConfig, AutoModel
45
+ from huggingface_hub import hf_hub_download
46
+
47
+ REPO_ID = "harveymannering/DINOv3_FaceRegionClassifier"
48
+
49
+ class Dinov3FaceRegionClassifier(nn.Module):
50
+ def __init__(self, config):
51
+ super().__init__()
52
+ self.backbone = AutoModel.from_config(config)
53
+ self.head = nn.Linear(config.hidden_size, 1)
54
+
55
+ def forward(self, pixel_values):
56
+ pooled = self.backbone(pixel_values=pixel_values).pooler_output
57
+ return self.head(pooled).squeeze(-1) # face logit; sigmoid -> p(face)
58
+
59
+ config = AutoConfig.from_pretrained(REPO_ID)
60
+ model = Dinov3FaceRegionClassifier(config)
61
+ weights_path = hf_hub_download(repo_id=REPO_ID, filename="dinov3_face_region_classifier.pth")
62
+ model.load_state_dict(torch.load(weights_path, map_location="cpu"))
63
+ model.eval()
64
+ ```
65
+
66
+ Input should be `224x224` RGB, normalized with ImageNet mean/std
67
+ (`mean=[0.485, 0.456, 0.406]`, `std=[0.229, 0.224, 0.225]`).
68
+
69
+ ## License
70
+
71
+ Derived from `facebook/dinov3-vits16-pretrain-lvd1689m`; usage is subject to the terms of that model's
72
+ license — see the [base model page](https://huggingface.co/facebook/dinov3-vits16-pretrain-lvd1689m) for
73
+ details.
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DINOv3ViTModel"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "drop_path_rate": 0.0,
7
+ "dtype": "float32",
8
+ "hidden_act": "gelu",
9
+ "hidden_size": 384,
10
+ "image_size": 224,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1536,
13
+ "key_bias": false,
14
+ "layer_norm_eps": 1e-05,
15
+ "layerscale_value": 1.0,
16
+ "mlp_bias": true,
17
+ "model_type": "dinov3_vit",
18
+ "num_attention_heads": 6,
19
+ "num_channels": 3,
20
+ "num_hidden_layers": 12,
21
+ "num_register_tokens": 4,
22
+ "patch_size": 16,
23
+ "pos_embed_jitter": null,
24
+ "pos_embed_rescale": 2.0,
25
+ "pos_embed_shift": null,
26
+ "proj_bias": true,
27
+ "query_bias": true,
28
+ "rope_theta": 100.0,
29
+ "transformers_version": "4.56.1",
30
+ "use_gated_mlp": false,
31
+ "value_bias": true
32
+ }
dinov3_face_region_classifier.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f5757efef4bf13d39227da22416b24d0bba03e9967e6715d9f07f9a746c47e3
3
+ size 86459431