farwew commited on
Commit
c5045dd
·
verified ·
1 Parent(s): 3d25d35

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +34 -33
README.md CHANGED
@@ -10,70 +10,71 @@ tags:
10
  pipeline_tag: video-classification
11
  ---
12
 
13
- # DAViD — ViFi-CLIP Encoder (ViT-B/16, K400-finetuned)
14
 
15
- Visual feature extractor for **[DAViD](https://huggingface.co/spaces/aitf-its-tim3-dfk/David)**,
16
- a deepfake & AI-generated video detector.
17
 
18
- This repo hosts a single checkpoint:
19
 
20
  | File | Size | Description |
21
  |---|---|---|
22
  | `k400_clip_complete_finetuned_30_epochs.pth` | ~1.6 GB | ViFi-CLIP (ViT-B/16) image encoder, fine-tuned on Kinetics-400 for 30 epochs |
 
23
 
24
- ## What it is
25
 
26
- A **ViFi-CLIP (ViT-B/16)** image encoder whose CLIP visual backbone has been
27
- fine-tuned on **Kinetics-400**. In the DAViD pipeline it acts as a frozen
28
- feature extractor: each frame is encoded into a **512-dim** embedding, frame
29
- embeddings are averaged per scene / per clip, and a lightweight MLP
30
- classification head predicts one of three classes — `real`, `deepfake`,
31
- `ai_gen`.
32
 
33
- The MLP classification head is a separate, much smaller checkpoint and is **not**
34
- in this repo.
35
 
36
- ## Why it lives on the Hub
37
-
38
- The DAViD Space downloads this checkpoint at Docker build time. It was
39
- previously hosted on Google Drive, but Drive throttles datacenter IPs and broke
40
- the Space build. Serving it from the HF Hub is reliable from HF's build
41
- infrastructure.
42
 
43
  ## Usage
44
 
45
- Download the checkpoint (no auth needed — public repo):
46
 
47
  ```python
48
  from huggingface_hub import hf_hub_download
49
 
50
- ckpt = hf_hub_download(
51
- repo_id="aitf-its-tim3-dfk/david-encoder",
52
- filename="k400_clip_complete_finetuned_30_epochs.pth",
53
- )
54
  ```
55
 
56
- Load it with the DAViD encoder loader (from the training repo
57
  [`aitf-its-tim3-dfk/david`](https://github.com/aitf-its-tim3-dfk/david)):
58
 
59
  ```python
 
60
  from encoder import load_feature_extractor
 
61
 
62
  feature_extractor = load_feature_extractor(
63
  arch="ViT-B/16",
64
  class_names=("real", "deepfake", "ai_gen"),
65
- checkpoint_path=ckpt,
66
  ).eval()
67
 
68
- # feature_extractor.image_encoder(frames) -> (N, 512) embeddings
 
 
 
 
 
69
  ```
70
 
71
  ## Training
72
 
73
- - **Backbone:** CLIP ViT-B/16 (ViFi-CLIP setup)
74
- - **Fine-tuning data:** Kinetics-400
75
- - **Schedule:** 30 epochs
76
- - **Output dim:** 512
77
 
78
  ## Related
79
 
@@ -82,5 +83,5 @@ feature_extractor = load_feature_extractor(
82
 
83
  ## License
84
 
85
- Set the appropriate license for these weights (currently `other`). Note that the
86
- CLIP backbone and Kinetics-400 carry their own upstream licenses/terms.
 
10
  pipeline_tag: video-classification
11
  ---
12
 
13
+ # DAViD — Checkpoints (ViFi-CLIP encoder + classification head)
14
 
15
+ Model weights for **[DAViD](https://huggingface.co/spaces/aitf-its-tim3-dfk/David)**,
16
+ a deepfake & AI-generated video/image detector.
17
 
18
+ This repo hosts two checkpoints:
19
 
20
  | File | Size | Description |
21
  |---|---|---|
22
  | `k400_clip_complete_finetuned_30_epochs.pth` | ~1.6 GB | ViFi-CLIP (ViT-B/16) image encoder, fine-tuned on Kinetics-400 for 30 epochs |
23
+ | `best_detector_model.pt` | ~3 MB | MLP classification head (`dense → dense1 → dense2`), trained on the DAViD dataset + CDDB |
24
 
25
+ ## How they fit together
26
 
27
+ 1. **Encoder** — a ViFi-CLIP (ViT-B/16) visual backbone fine-tuned on
28
+ Kinetics-400. Each frame (or image) is encoded into a **512-dim** embedding.
29
+ 2. **Classification head** — a lightweight MLP that maps the (averaged) 512-dim
30
+ embedding to 3 classes: `real`, `deepfake`, `ai_gen`. It was trained on a mix
31
+ of the DAViD video dataset and **CDDB** (an image-based deepfake benchmark),
32
+ so it supports both video and single-image input.
33
 
34
+ ## Why these live on the Hub
 
35
 
36
+ The DAViD Space downloads these at Docker build time. They were previously on
37
+ Google Drive, but Drive throttles datacenter IPs and broke the Space build.
38
+ Serving them from the HF Hub is reliable from HF's build infrastructure.
 
 
 
39
 
40
  ## Usage
41
 
42
+ Download (no auth needed — public repo):
43
 
44
  ```python
45
  from huggingface_hub import hf_hub_download
46
 
47
+ REPO = "aitf-its-tim3-dfk/david-encoder"
48
+ encoder_ckpt = hf_hub_download(REPO, "k400_clip_complete_finetuned_30_epochs.pth")
49
+ classifier_ckpt = hf_hub_download(REPO, "best_detector_model.pt")
 
50
  ```
51
 
52
+ Load with the DAViD modules (from the training repo
53
  [`aitf-its-tim3-dfk/david`](https://github.com/aitf-its-tim3-dfk/david)):
54
 
55
  ```python
56
+ import torch
57
  from encoder import load_feature_extractor
58
+ from model import ClassificationHead
59
 
60
  feature_extractor = load_feature_extractor(
61
  arch="ViT-B/16",
62
  class_names=("real", "deepfake", "ai_gen"),
63
+ checkpoint_path=encoder_ckpt,
64
  ).eval()
65
 
66
+ classifier = ClassificationHead(input_dim=512, num_classes=3)
67
+ classifier.load_state_dict(torch.load(classifier_ckpt, map_location="cpu", weights_only=False))
68
+ classifier.eval()
69
+
70
+ # feats = feature_extractor.image_encoder(frames) # (N, 512)
71
+ # logits = classifier(feats.mean(dim=0, keepdim=True)) # (1, 3)
72
  ```
73
 
74
  ## Training
75
 
76
+ - **Encoder:** CLIP ViT-B/16 (ViFi-CLIP), fine-tuned on Kinetics-400, 30 epochs, output dim 512.
77
+ - **Classification head:** MLP trained on DAViD video dataset + CDDB images (branch `feat-cddb`).
 
 
78
 
79
  ## Related
80
 
 
83
 
84
  ## License
85
 
86
+ Set the appropriate license for these weights (currently `other`). The CLIP
87
+ backbone, Kinetics-400, and CDDB carry their own upstream licenses/terms.