CodeRafay commited on
Commit
6cca952
Β·
verified Β·
1 Parent(s): feff1f9

v0.1_clip-Linear-Probe

Browse files
LICENSE ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ Model weights in this folder are NOT covered by the repository's MIT license.
2
+
3
+ Every model here is trained on FaceForensics++ and is therefore limited by the
4
+ FaceForensics Terms of Use (https://github.com/ondyari/FaceForensics):
5
+
6
+ - research and non-commercial use only
7
+ - no commercial products, services or paid use
8
+ - cite FaceForensics++ (RΓΆssler et al., ICCV 2019) when you publish results
9
+
10
+ The code in the rest of this repository remains MIT-licensed.
README.md CHANGED
@@ -1,5 +1,25 @@
1
  ---
2
  license: other
3
- license_name: licence
4
- license_link: https://github.com/CodeRafay/deepfake-detect/blob/main/models/LICENSE
 
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: other
3
+ license_name: research-only
4
+ license_link: https://github.com/ondyari/FaceForensics
5
+ tags: [deepfake-detection, face-forensics, clip]
6
  ---
7
+
8
+ # deepfake-detect models
9
+
10
+ Trained heads for [deepfake-detect](https://github.com/CodeRafay/deepfake-detect): small classifiers that run on top of frozen `openai/clip-vit-large-patch14` face embeddings. Each version lives in its own folder and is never overwritten.
11
+
12
+ | version | what changed | FF++ test AUC | Celeb-DF v2 AUC (unseen) | size |
13
+ |---|---|---|---|---|
14
+ | [v0.1-clip-linear-probe](v0.1-clip-linear-probe) | baseline: frozen CLIP + logistic regression, 8 frames/video, FF++ c23 | 0.905 | 0.738 | 3.7 KB |
15
+
16
+ Every folder contains `head.safetensors`, the model, with its backbone, threshold and metrics stored inside the file, `head.metrics.json` with all numbers from the training run, and `training_run.ipynb`, the executed training notebook with its full log, so every result can be checked.
17
+
18
+ ```bash
19
+ pip install git+https://github.com/CodeRafay/deepfake-detect
20
+ deepfake-detect video.mp4 # latest version
21
+ deepfake-detect video.mp4 --head v0.1-clip-linear-probe # a specific version
22
+ ```
23
+
24
+ **License:** research and non-commercial use only. The heads are trained on FaceForensics++, whose terms apply.
25
+ **Use responsibly:** a score is evidence, not proof. Don't make decisions about people based on it alone.
v0.1-clip-linear-probe/head.metrics.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "val": {
3
+ "files": 699,
4
+ "auc": 0.8824942499361104,
5
+ "ap": 0.96779942494803,
6
+ "balanced_acc": 0.8096473294147712,
7
+ "frame_auc": 0.8529755912432087
8
+ },
9
+ "test": {
10
+ "files": 700,
11
+ "auc": 0.9049107142857142,
12
+ "ap": 0.9750890613384986,
13
+ "balanced_acc": 0.8196428571428571,
14
+ "frame_auc": 0.8657028434280611
15
+ },
16
+ "celebdf": {
17
+ "files": 518,
18
+ "auc": 0.7383674818241904,
19
+ "ap": 0.8472883643448944,
20
+ "balanced_acc": 0.6669035029742234,
21
+ "frame_auc": 0.7090380549682875
22
+ }
23
+ }
v0.1-clip-linear-probe/head.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9bf8c54fef68c3c6929ebe57d62525bba44e7122be65465e3c2e41c35057fe7
3
+ size 3788
v0.1-clip-linear-probe/training_run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells":[{"cell_type":"markdown","id":"324345c7","metadata":{"papermill":{"duration":0.001836,"end_time":"2026-10-16T15:51:10.622343+00:00","exception":false,"start_time":"2026-10-16T15:51:10.620507+00:00","status":"completed"},"tags":[]},"source":["# Train deepfake-detect on Kaggle\n","\n","Trains the linear head on **FaceForensics++ (c23)** using the official train/val/test splits, then tests on **Celeb-DF v2**, a dataset the model never sees during training. That second number is the honest one.\n","\n","**Before running**\n","1. Settings β†’ Accelerator β†’ **GPU T4 x2** (or P100). Turn **Internet on**.\n","2. Both datasets need an access request to their authors ([FaceForensics++](https://github.com/ondyari/FaceForensics), [Celeb-DF](https://github.com/yuezunli/celeb-deepfakeforensics)). Their licences forbid redistribution, so upload your copy as a **private** Kaggle dataset and attach it with *Add Input*.\n","3. Set the two paths in the next code cell to wherever your upload lands under `/kaggle/input/`.\n","\n","Expected runtime: ~1–2 h, mostly video decoding and face detection. Embeddings are cached, so re-runs take minutes."]},{"cell_type":"code","execution_count":1,"id":"6c2c60d3","metadata":{"execution":{"iopub.execute_input":"2026-10-16T15:51:10.62691Z","iopub.status.busy":"2026-10-16T15:51:10.626147Z","iopub.status.idle":"2026-10-16T15:51:33.907031Z","shell.execute_reply":"2026-10-16T15:51:33.905944Z"},"papermill":{"duration":23.28577,"end_time":"2026-10-16T15:51:33.909467+00:00","exception":false,"start_time":"2026-10-16T15:51:10.623697+00:00","status":"completed"},"tags":[]},"outputs":[{"name":"stdout","output_type":"stream","text":[" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\r\n"," Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\r\n"," Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\r\n"," Building wheel for deepfake-detect (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\r\n","\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\r\n","\u001b[32m\u001b[32m\u001b[1m3 passed\u001b[0m\u001b[32m in 5.68s\u001b[0m\u001b[0m\r\n"]}],"source":["REPO = \"https://github.com/CodeRafay/deepfake-detect\"\n","BRANCH = \"redesign\"\n","!rm -rf /kaggle/working/deepfake-detect\n","!git clone -q -b $BRANCH $REPO /kaggle/working/deepfake-detect\n","!pip install -q /kaggle/working/deepfake-detect pytest\n","!python -m pytest -q /kaggle/working/deepfake-detect/tests\n"]},{"cell_type":"code","execution_count":2,"id":"ab291fd1","metadata":{"execution":{"iopub.execute_input":"2026-10-16T15:51:33.915147Z","iopub.status.busy":"2026-10-16T15:51:33.914152Z","iopub.status.idle":"2026-10-16T15:51:51.714553Z","shell.execute_reply":"2026-10-16T15:51:51.713462Z"},"papermill":{"duration":17.80525,"end_time":"2026-10-16T15:51:51.71647+00:00","exception":false,"start_time":"2026-10-16T15:51:33.91122+00:00","status":"completed"},"tags":[]},"outputs":[{"name":"stdout","output_type":"stream","text":["/kaggle/working/data/train/real: 720 videos\n","/kaggle/working/data/train/fake: 2880 videos\n","/kaggle/working/data/val/real: 140 videos\n","/kaggle/working/data/val/fake: 560 videos\n","/kaggle/working/data/test/real: 140 videos\n","/kaggle/working/data/test/fake: 560 videos\n","/kaggle/working/celebdf/real: 178 videos\n","/kaggle/working/celebdf/fake: 340 videos\n"]}],"source":["import json, urllib.request\n","from pathlib import Path\n","\n","\n","FFPP = Path(\"/kaggle/input/notebooks/rafayadeel/ffpp-c23-download/ffpp\")\n","CELEBDF = Path(\"/kaggle/input/datasets/rafayadeel/celeb-df-v2\")\n","\n","# FFPP = Path(\"/kaggle/input/YOUR-FFPP-UPLOAD\") # contains original_sequences/ and manipulated_sequences/\n","# CELEBDF = Path(\"/kaggle/input/YOUR-CELEBDF-UPLOAD\") # contains Celeb-real/, Celeb-synthesis/, YouTube-real/, List_of_testing_videos.txt\n","METHODS = [\"Deepfakes\", \"Face2Face\", \"FaceSwap\", \"NeuralTextures\"]\n","DATA, CDF = Path(\"/kaggle/working/data\"), Path(\"/kaggle/working/celebdf\")\n","\n","def link(src, dst):\n"," if src.exists() and not dst.exists():\n"," dst.parent.mkdir(parents=True, exist_ok=True)\n"," dst.symlink_to(src)\n","\n","# Official FF++ splits are by source-video pair, so no identity appears in two splits.\n","for split in [\"train\", \"val\", \"test\"]:\n"," url = f\"https://raw.githubusercontent.com/ondyari/FaceForensics/master/dataset/splits/{split}.json\"\n"," for a, b in json.load(urllib.request.urlopen(url)):\n"," for v in (a, b):\n"," link(FFPP / f\"original_sequences/youtube/c23/videos/{v}.mp4\", DATA / split / \"real\" / f\"{v}.mp4\")\n"," for m in METHODS:\n"," for x, y in ((a, b), (b, a)):\n"," link(FFPP / f\"manipulated_sequences/{m}/c23/videos/{x}_{y}.mp4\", DATA / split / \"fake\" / f\"{m}_{x}_{y}.mp4\")\n","\n","# Celeb-DF official test list: \"1 path\" = real, \"0 path\" = fake.\n","for line in (CELEBDF / \"List_of_testing_videos.txt\").read_text().splitlines():\n"," if line.strip():\n"," lab, rel = line.split()\n"," link(CELEBDF / rel, CDF / (\"real\" if lab == \"1\" else \"fake\") / rel.replace(\"/\", \"_\"))\n","\n","for d in [DATA / s / c for s in [\"train\", \"val\", \"test\"] for c in [\"real\", \"fake\"]] + [CDF / \"real\", CDF / \"fake\"]:\n"," print(f\"{d}: {len(list(d.glob('*')))} videos\")"]},{"cell_type":"code","execution_count":3,"id":"4a53412b","metadata":{"execution":{"iopub.execute_input":"2026-10-16T15:51:51.720918Z","iopub.status.busy":"2026-10-16T15:51:51.720637Z","iopub.status.idle":"2026-10-16T18:57:21.113699Z","shell.execute_reply":"2026-10-16T18:57:21.112637Z"},"papermill":{"duration":11129.397716,"end_time":"2026-10-16T18:57:21.115798+00:00","exception":false,"start_time":"2026-10-16T15:51:51.718082+00:00","status":"completed"},"tags":[]},"outputs":[{"name":"stdout","output_type":"stream","text":["Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.\r\n","preprocessor_config.json: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 316/316 [00:00<00:00, 1.41MB/s]\r\n","config.json: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 4.52k/4.52k [00:00<00:00, 9.17MB/s]\r\n","\r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ– | 323MB, 26.4MB/s \r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ–‰ | 386MB, 33.3MB/s \r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ | 1.06GB, 88.3MB/s \r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž | 1.11GB, 90.4MB/s \r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ | 1.17GB, 90.8MB/s \r\n","model.safetensors: downloading bytes: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.18GB, 88.6MB/s \r\n","model.safetensors: reconstructing file: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.71GB / 1.71GB, 137MB/s \r\n","Loading weights: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 392/392 [00:00<00:00, 1061.09it/s]\r\n","[transformers] \u001b[1mCLIPVisionModelWithProjection LOAD REPORT\u001b[0m from: openai/clip-vit-large-patch14\r\n","Key | Status | | \r\n","-------------------------------------------------------------+------------+--+-\r\n","text_model.encoder.layers.{0...11}.mlp.fc2.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.layer_norm1.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.layer_norm1.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.q_proj.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.mlp.fc2.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.mlp.fc1.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.q_proj.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.k_proj.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.k_proj.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.v_proj.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.out_proj.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.mlp.fc1.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.out_proj.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.layer_norm2.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.embeddings.token_embedding.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.final_layer_norm.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.layer_norm2.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.encoder.layers.{0...11}.self_attn.v_proj.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","logit_scale | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.final_layer_norm.bias | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_projection.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","text_model.embeddings.position_embedding.weight | \u001b[38;5;208mUNEXPECTED\u001b[0m | | \r\n","\r\n","Notes:\r\n","- \u001b[38;5;208mUNEXPECTED:\u001b[0m\t\u001b[3mcan be ignored when loading from different task/architecture; not ok if you expect identical arch.\u001b[0m\r\n","train/real: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 720/720 [27:27<00:00, 2.29s/it]\r\n","train/fake: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2880/2880 [1:46:56<00:00, 2.23s/it]\r\n","data/train: 28752 faces from 3599 files (23003 fake)\r\n","val/real: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 140/140 [04:36<00:00, 1.97s/it]\r\n","val/fake: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 560/560 [18:19<00:00, 1.96s/it]\r\n","data/val: 5590 faces from 699 files (4470 fake)\r\n","C=0.01 val AUC=0.7941\r\n","C=0.1 val AUC=0.8484\r\n","C=1.0 val AUC=0.8813\r\n","C=10.0 val AUC=0.8825\r\n","test/real: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 140/140 [04:43<00:00, 2.02s/it]\r\n","test/fake: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 560/560 [18:45<00:00, 2.01s/it]\r\n","data/test: 5599 faces from 700 files (4479 fake)\r\n","celebdf/real: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 178/178 [01:06<00:00, 2.68it/s]\r\n","celebdf/fake: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 340/340 [02:09<00:00, 2.63it/s]\r\n","celebdf: 4139 faces from 518 files (2720 fake)\r\n","\r\n","threshold = 0.4651 (chosen on val)\r\n","\r\n","| set | files | AUC | AP | balanced acc | frame AUC |\r\n","|---|---|---|---|---|---|\r\n","| val | 699 | 0.882 | 0.968 | 0.810 | 0.853 |\r\n","| test | 700 | 0.905 | 0.975 | 0.820 | 0.866 |\r\n","| celebdf | 518 | 0.738 | 0.847 | 0.667 | 0.709 |\r\n","\r\n","saved head.safetensors\r\n"]}],"source":["!cd /kaggle/working && python -m deepfake_detect.train --data data --eval celebdf=celebdf --out head.safetensors"]},{"cell_type":"markdown","id":"996de92b","metadata":{"papermill":{"duration":0.165989,"end_time":"2026-10-16T18:57:21.449254+00:00","exception":false,"start_time":"2026-10-16T18:57:21.283265+00:00","status":"completed"},"tags":[]},"source":["Paste the table above into the README's **Results** section. Report it as is, even if the Celeb-DF number is unflattering. Next, sanity-check a few test videos:"]},{"cell_type":"code","execution_count":4,"id":"bb3b979f","metadata":{"execution":{"iopub.execute_input":"2026-10-16T18:57:21.787033Z","iopub.status.busy":"2026-10-16T18:57:21.786562Z","iopub.status.idle":"2026-10-16T18:57:37.256871Z","shell.execute_reply":"2026-10-16T18:57:37.255835Z"},"papermill":{"duration":15.641365,"end_time":"2026-10-16T18:57:37.258822+00:00","exception":false,"start_time":"2026-10-16T18:57:21.617457+00:00","status":"completed"},"tags":[]},"outputs":[{"name":"stderr","output_type":"stream","text":["Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.\n"]},{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"29dc5490043647d1954025f2b9c1c04e","version_major":2,"version_minor":0},"text/plain":["Loading weights: 0%| | 0/392 [00:00<?, ?it/s]"]},"metadata":{},"output_type":"display_data"},{"name":"stderr","output_type":"stream","text":["[transformers] \u001b[1mCLIPVisionModelWithProjection LOAD REPORT\u001b[0m from: openai/clip-vit-large-patch14\n","Key | Status | | \n","-------------------------------------------------------------+------------+--+-\n","text_model.encoder.layers.{0...11}.self_attn.k_proj.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.mlp.fc1.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.layer_norm2.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.k_proj.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.mlp.fc2.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.q_proj.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.out_proj.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.v_proj.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.mlp.fc1.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.layer_norm2.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.v_proj.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.mlp.fc2.bias | UNEXPECTED | | \n","logit_scale | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.layer_norm1.weight | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.layer_norm1.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.q_proj.bias | UNEXPECTED | | \n","text_model.encoder.layers.{0...11}.self_attn.out_proj.weight | UNEXPECTED | | \n","text_model.final_layer_norm.bias | UNEXPECTED | | \n","text_model.embeddings.token_embedding.weight | UNEXPECTED | | \n","text_model.final_layer_norm.weight | UNEXPECTED | | \n","text_projection.weight | UNEXPECTED | | \n","text_model.embeddings.position_embedding.weight | UNEXPECTED | | \n","\n","Notes:\n","- UNEXPECTED:\tcan be ignored when loading from different task/architecture; not ok if you expect identical arch.\n"]},{"name":"stdout","output_type":"stream","text":["real real 0.2108\n","real fake 0.6914\n","real real 0.4204\n","fake fake 0.8935\n","fake fake 0.7728\n","fake fake 0.9848\n"]}],"source":["from deepfake_detect import Detector\n","det = Detector(\"/kaggle/working/head.safetensors\")\n","for p in sorted((CDF / \"real\").glob(\"*\"))[:3] + sorted((CDF / \"fake\").glob(\"*\"))[:3]:\n"," r = det.predict(p)\n"," print(p.parent.name, r[\"label\"], r[\"score\"])"]},{"cell_type":"markdown","id":"ba53a052","metadata":{"papermill":{"duration":0.164878,"end_time":"2026-10-16T18:57:37.592731+00:00","exception":false,"start_time":"2026-10-16T18:57:37.427853+00:00","status":"completed"},"tags":[]},"source":["## Publish the head (optional)\n","Add a Kaggle secret `HF_TOKEN` (write access), then upload. Users get it automatically with `Detector()` once `DEFAULT_HEAD` in `model.py` points to your repo."]},{"cell_type":"code","execution_count":5,"id":"a6e1f1b8","metadata":{"execution":{"iopub.execute_input":"2026-10-16T18:57:37.926504Z","iopub.status.busy":"2026-10-16T18:57:37.925738Z","iopub.status.idle":"2026-10-16T18:57:37.998839Z","shell.execute_reply":"2026-10-16T18:57:37.997689Z"},"papermill":{"duration":0.242606,"end_time":"2026-10-16T18:57:38.000219+00:00","exception":true,"start_time":"2026-10-16T18:57:37.757613+00:00","status":"failed"},"tags":[]},"outputs":[{"ename":"BackendError","evalue":"Unexpected response from the service. Response: {'errors': ['No user secrets exist for kernel id 139036765 and label HF_TOKEN.'], 'error': {'code': 5}, 'wasSuccessful': False}.","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mBackendError\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_23/3622066028.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mhuggingface_hub\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mHfApi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mkaggle_secrets\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mUserSecretsClient\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mapi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mHfApi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtoken\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mUserSecretsClient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_secret\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"HF_TOKEN\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mrepo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"CodeRafay/deepfake-detect\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mapi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_repo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexist_ok\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.13/dist-packages/kaggle_secrets.py\u001b[0m in \u001b[0;36mget_secret\u001b[0;34m(self, label)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0;34m'Label'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m }\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0mresponse_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweb_client\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmake_post_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrequest_body\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGET_USER_SECRET_BY_LABEL_ENDPOINT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 65\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'secret'\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m raise BackendError(\n","\u001b[0;32m/usr/local/lib/python3.13/dist-packages/kaggle_web_client.py\u001b[0m in \u001b[0;36mmake_post_request\u001b[0;34m(self, data, endpoint, timeout)\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0mresponse_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'wasSuccessful'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m'result'\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m raise BackendError(\n\u001b[0m\u001b[1;32m 50\u001b[0m f'Unexpected response from the service. Response: {response_json}.')\n\u001b[1;32m 51\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'result'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mBackendError\u001b[0m: Unexpected response from the service. Response: {'errors': ['No user secrets exist for kernel id 139036765 and label HF_TOKEN.'], 'error': {'code': 5}, 'wasSuccessful': False}."]}],"source":["from huggingface_hub import HfApi\n","from kaggle_secrets import UserSecretsClient\n","api = HfApi(token=UserSecretsClient().get_secret(\"HF_TOKEN\"))\n","repo = \"CodeRafay/deepfake-detect\"\n","api.create_repo(repo, exist_ok=True)\n","for f in [\"head.safetensors\", \"head.metrics.json\"]:\n"," api.upload_file(path_or_fileobj=f\"/kaggle/working/{f}\", path_in_repo=f, repo_id=repo)"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.13.15"},"papermill":{"default_parameters":{},"duration":11194.586242,"end_time":"2026-10-16T18:57:41.088938+00:00","environment_variables":{},"exception":true,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2026-10-16T15:51:06.502696+00:00","version":"2.7.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"0e21050fa656420699c900362adce318":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_d113a889e4ed4dd1a9e9c8f463fcfe40","placeholder":"​","style":"IPY_MODEL_1d3b14a3c0654fa58256d8557cfec4ea","tabbable":null,"tooltip":null,"value":" 392/392 [00:00&lt;00:00, 1024.57it/s]"}},"1d3b14a3c0654fa58256d8557cfec4ea":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"29dc5490043647d1954025f2b9c1c04e":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_30df5a94a958431ba4929840a0afbb8d","IPY_MODEL_90261395e1604aabb0fe148107a4dd14","IPY_MODEL_0e21050fa656420699c900362adce318"],"layout":"IPY_MODEL_40f9b2fdb3514872bbb6666ef4ee72d8","tabbable":null,"tooltip":null}},"30df5a94a958431ba4929840a0afbb8d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_d086f91ed7d244799b2b6694d9598586","placeholder":"​","style":"IPY_MODEL_f3e75588e62c48b884ddb60cbd380857","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"40f9b2fdb3514872bbb6666ef4ee72d8":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"89fc814219a3405a95b7423408e4675b":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"90261395e1604aabb0fe148107a4dd14":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_89fc814219a3405a95b7423408e4675b","max":392.0,"min":0.0,"orientation":"horizontal","style":"IPY_MODEL_9967c81fe99b450096f277b7df0324c8","tabbable":null,"tooltip":null,"value":392.0}},"9967c81fe99b450096f277b7df0324c8":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"d086f91ed7d244799b2b6694d9598586":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d113a889e4ed4dd1a9e9c8f463fcfe40":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f3e75588e62c48b884ddb60cbd380857":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}}},"version_major":2,"version_minor":0}},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"datasetVersion","sourceId":20818539},{"sourceType":"kernelVersion","sourceId":359024685}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat":4,"nbformat_minor":5}