Anti-deepfake DINOv3 — ViT-S/16+ & ConvNeXt (đồ án coursework)
Bộ weight phục vụ đồ án phát hiện deepfake (ảnh): 2 backbone pretrained (chưa finetune), 2 model finetune (ViT-Plus A0, ConvNeXt) và 1 bản sampler-improve (ViT-Plus A1). Tất cả được huấn luyện / đánh giá với transform chuẩn Resize 256 → ImageNet mean/std, fp32. Code huấn luyện & đánh giá: github.com/QuangManhAI/deepfake-ViT.
Kiến trúc
| Checkpoint | Mô tả | Số params | File |
|---|---|---|---|
pretrained/dinov3-vits16plus/model-3.safetensors | DINOv3 ViT-S/16+ pretrained (LVD-1689M), không head | 28,69M | ~115 MB |
pretrained/dinov3-convnext/model-2.safetensors | DINOv3 ConvNeXt pretrained (LVD-1689M), không head | 27,82M | ~111 MB |
finetuned/vit-plus-a0/plus_v3_best.pt | ViT-Plus A0 finetune (sampler mặc định) | 28,69M | ~115 MB |
finetuned/vit-plus-a1-sampler/plus_v3_s1_best.pt | ViT-Plus A1 finetune, sampler weak-family (8 method yếu) | 28,69M | ~115 MB |
finetuned/convnext/convnext_weakfix_v3.pt | ConvNeXt finetuned | 28,12M (bb 27,82M + head 0,30M) | ~113 MB |
Head nhỏ: ViT head = Linear 384→2 (+770 tham số); ConvNeXt head ≈ 0,30M tham số.
Kết quả trên test cân bằng 21.446 (real 10.723 / fake 10.723, 44 method)
Cùng test, fp32 MPS. Dòng "pretrained (probe)" = backbone đông cứng + linear probe
LogisticRegression(class_weight='balanced') trên 123.582 ảnh train — dùng để định lượng
sức mạnh feature sẵn có.
| Model | acc% | prec | rec | f1 | AUC | real_acc | fake_rec |
|---|---|---|---|---|---|---|---|
| ViT-S/16+ pretrained (probe) | 89,47 | 88,86 | 90,25 | 89,55 | 0,9624 | 88,69 | 90,25 |
| ConvNeXt pretrained (probe) | 87,77 | 89,62 | 85,44 | 87,48 | 0,9553 | 90,11 | 85,44 |
| ViT-Plus A0 finetune | 97,91 | 98,05 | 97,77 | 97,91 | 0,9979 | 98,05 | 97,77 |
| ViT-Plus A1 finetune (sampler yếu) | 98,47 | 97,94 | 99,02 | 98,48 | 0,9986 | 97,92 | 99,02 |
| ConvNeXt finetuned | 99,22 | 99,79 | 98,64 | 99,21 | 0,9998 | 99,79 | 98,64 |
- A1 cải thiện có ý nghĩa thống kê so với A0 (McNemar p ≈ 3e-10) nhờ tăng exposure cho
8 method yếu:
faceswap, deepfake_faceswap, wav2lip, sadtalker, fsgan, facedancer, inswap, mobileswap. - Finetune đóng vai trò chính: backbone pretrained (probe) chỉ đạt ~88–89% dù AUC ~0,96; phần tăng ~10 điểm đến từ việc tinh chỉnh feature cho bài deepfake, không phải chỉ gắn head.
Cách dùng
Các file là weight thô của dự án (không phải chuẩn transformers). Load bằng loader
trong repo code:
import sys; sys.path.insert(0, "path/to/deepfake-ViT")
from src.models.dinov3_vit import load_dinov3 # backbone ViT
from src.models.dinov3_convnext import load_dinov3_convnext # backbone ConvNeXt
import torch, torch.nn as nn
# 1) Backbone pretrained (không head)
bb = load_dinov3("pretrained/dinov3-vits16plus/model-3.safetensors", img_size=256)
bb = load_dinov3_convnext("pretrained/dinov3-convnext/model-2.safetensors")
# 2) Model finetune: state_dict có khóa backbone.* / head.*
class Cls(nn.Module):
def __init__(self, backbone):
super().__init__()
self.backbone = backbone
self.head = nn.Linear(backbone.embed_dim, 2)
def forward(self, x):
return self.head(self.backbone(x))
model = Cls(load_dinov3("models/dinov3-vits16plus-pretrain-lvd1689m/model-3.safetensors",
img_size=256)) # ViT-S/16+ làm backbone nền
ck = torch.load("finetuned/vit-plus-a1-sampler/plus_v3_s1_best.pt",
map_location="cpu", weights_only=False)
model.load_state_dict(ck["state_dict"]) # A0 dùng cùng khóa này
Preprocessing khi eval/huấn luyện (khớp mọi số liệu trên): Resize((256, 256)),
ToTensor(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]).
Cấu trúc repo
README.md
pretrained/
dinov3-vits16plus/ model-3.safetensors · config-3.json · preprocessor_config.json
dinov3-convnext/ model-2.safetensors · config-2.json · preprocessor_config.json
finetuned/
vit-plus-a0/ plus_v3_best.pt # A0 (sampler mặc định)
vit-plus-a1-sampler/ plus_v3_s1_best.pt # A1 (sampler weak-family)
convnext/ convnext_weakfix_v3.pt # ConvNeXt finetuned
Ghi chú
- Data ảnh deepfake train/test không đóng gói ở đây (bản quyền + kích thước); xem README repo GitHub để tái dựng split 21.446 (44 method, zero-leakage theo identity).
- Các file
.ptdùngweights_only=Falseđể đọc (lưu từ torch 2.x); chúng chỉ chứa state_dict.