Run this model with HF Jobs
Run SnapOtter/deepsafe-services on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/SnapOtter/deepsafe-services. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/SnapOtter/deepsafe-services on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use SnapOtter/deepsafe-services with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use SnapOtter/deepsafe-services with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("SnapOtter/deepsafe-services", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
DeepSafe commited on
chore: remove non-weight files (batch 6)
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
Files changed (50)
- video/dfd-fcg/model_code/configs/robustness/CC(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CC(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CC(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CS(1).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CS(2).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CS(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CS(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/CS(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GB(1).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GB(2).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GB(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GB(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GB(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GNC(1).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GNC(2).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GNC(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GNC(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/GNC(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/JPEG(1).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/JPEG(2).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/JPEG(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/JPEG(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/JPEG(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/VC(1).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/VC(2).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/VC(3).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/VC(4).yamlDeleted-14
- video/dfd-fcg/model_code/configs/robustness/VC(5).yamlDeleted-14
- video/dfd-fcg/model_code/configs/scenario/LOO/DF.yamlDeleted-32
- video/dfd-fcg/model_code/configs/scenario/LOO/F2F.yamlDeleted-32
- video/dfd-fcg/model_code/configs/scenario/LOO/FS.yamlDeleted-32
- video/dfd-fcg/model_code/configs/scenario/LOO/NT.yamlDeleted-32
- video/dfd-fcg/model_code/configs/scenario/compression/c40.yamlDeleted-55
- video/dfd-fcg/model_code/configs/scenario/compression/raw.yamlDeleted-55
- video/dfd-fcg/model_code/configs/scenario/partial/10.yamlDeleted-56
- video/dfd-fcg/model_code/configs/scenario/partial/25.yamlDeleted-56
- video/dfd-fcg/model_code/configs/scenario/partial/50.yamlDeleted-56
- video/dfd-fcg/model_code/configs/scenario/partial/75.yamlDeleted-56
- video/dfd-fcg/model_code/configs/scenario/robust/robust.yamlDeleted-33
- video/dfd-fcg/model_code/configs/test.yamlDeleted-14
- video/dfd-fcg/model_code/demo.pyDeleted-192
- video/dfd-fcg/model_code/environment.ymlDeleted-129
- video/dfd-fcg/model_code/inference.pyDeleted-187
- video/dfd-fcg/model_code/main.pyDeleted-123
- video/dfd-fcg/model_code/misc/20words_mean_face.npyDeleted-3
- video/dfd-fcg/model_code/misc/L14_real_semantic_patches_v4_2000.pickleDeleted-3
- video/dfd-fcg/model_code/readme.mdDeleted-275
- video/dfd-fcg/model_code/resources/videos/000.mp4Deleted-3
- video/dfd-fcg/model_code/resources/videos/000_003.mp4Deleted-3
- video/dfd-fcg/model_code/scripts/ablation/ffg.shDeleted-6
1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CC/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CC/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CC/5/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CS/1/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CS/2/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CS/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CS/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/CS/5/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GB/1/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GB/2/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GB/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GB/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GB/5/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GNC/1/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GNC/2/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GNC/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GNC/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/GNC/5/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/JPEG/1/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/JPEG/2/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/JPEG/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/JPEG/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/JPEG/5/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/VC/1/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/VC/2/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/VC/3/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/VC/4/' vid_ext: .avi1234567891011121314data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: test_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE force_random_speed: null data_dir: 'datasets/robustness/VC/5/' vid_ext: .avi1234567891011121314151617181920212223242526272829303132data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','NT','FS','F2F'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c40'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c40'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['c40'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['raw'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['raw'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['raw'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false ratio: 0.1 max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['c23'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false ratio: 0.25 max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['c23'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false ratio: 0.50 max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['c23'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - NORMAL - VIDEO - VIDEO_RRC - FRAME force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false ratio: 0.75 max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.cdf.CDFDataModule init_args: data_dir: 'datasets/cdf/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.dfdc.DFDCDataModule init_args: data_dir: 'datasets/dfdc/' vid_ext: '.avi' pack: false max_clips: 1 - class_path: src.dataset.fsh.FShDataModule init_args: compressions: ['c23'] data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 1123456789101112131415161718192021222324252627282930313233data: class_path: src.dataset.base.ODDeepFakeDataModule init_args: batch_size: 20 num_workers: 4 clip_duration: 3 num_frames: 10 train_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: batch_size: 30 df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: FORCE_PAIR augmentations: - ROBUSTNESS force_random_speed: null data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 3 val_datamodules: - class_path: src.dataset.ffpp.FFPPDataModule init_args: df_types: ['REAL','DF','FS','F2F','NT'] compressions: ['c23'] strategy: NORMAL augmentations: - NONE data_dir: 'datasets/ffpp/' vid_ext: '.avi' pack: false max_clips: 11234567891011121314trainer: logger: init_args: offline: true limit_train_batches: 30 limit_val_batches: 30 accumulate_grad_batches: 1data: init_args: batch_size: 1 num_workers: 0 train_datamodules: - init_args: batch_size: 1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import osimport cv2import sysimport yamlimport jsonimport mathimport torchimport pickleimport shutilimport loggingimport warningsimport argparseimport numpy as np
from os import pathfrom datetime import datetimefrom torchvision.io import VideoReaderfrom src.utility.builtin import ODTrainer, ODLightningCLI
def parse_args(args=None): parser = argparse.ArgumentParser() parser.add_argument("model_cfg_path", type=str) parser.add_argument("model_ckpt_path", type=str) parser.add_argument("video_path", type=str) parser.add_argument("--out_path", type=str, default=None) parser.add_argument("--threshold", type=float, default=0.5) parser.add_argument("--precision", type=str, default="16") parser.add_argument("--batch_size", type=int, default=30) return parser.parse_args(args=args)
def configure_logging(): logging_fmt = "[%(levelname)s][%(filename)s:%(lineno)d]: %(message)s" logging.basicConfig(level="INFO", format=logging_fmt) warnings.filterwarnings(action="ignore")
@torch.inference_mode()def demo_driver(cli, ckpt_path, video_path, out_path, batch_size, threshold): # setup model model = cli.model
try: model = model.__class__.load_from_checkpoint(ckpt_path) except Exception as e: print(f"Unable to load model from checkpoint in strict mode: {e}") print(f"Loading model from checkpoint in non-strict mode.") model = model.__class__.load_from_checkpoint(ckpt_path, strict=False)
model.eval() transforms = model.transform
BATCH = batch_size stride = 0.333
# load original video vid_reader = VideoReader(video_path, "video", num_threads=1) vid_ext = os.path.splitext(video_path)[-1] vid_name = os.path.split(video_path)[1].replace(vid_ext, "") fps = vid_reader.get_metadata()["video"]["fps"][0]
frames = [] for frame_data in vid_reader: frames.append(frame_data["data"]) frames = torch.stack(frames) del vid_reader _, H, W = frames[0].shape
# load bboxes of original video with open(video_path.replace("videos", "frame_data").replace(vid_ext, ".pickle"), "rb") as f: fdata = pickle.load(f) bboxes = [] for data in fdata: data["bboxes"] = [ bbox.reshape(2, -1) if len(bbox.shape) == 1 else bbox for bbox in data["bboxes"] ] face_idx = np.argsort([ np.linalg.norm((bbox[0] - bbox[1])) for bbox in data["bboxes"] ])[-1] bboxes.append(data["bboxes"][face_idx])
# load face cropped video vid_reader = VideoReader( video_path.replace("/videos", "/cropped/videos").replace(vid_ext, ".avi"), "video", num_threads=1 ) cropped_frames = [] for frame_data in vid_reader: cropped_frames.append(frame_data["data"]) cropped_frames = torch.stack(cropped_frames) del vid_reader
# sample frames and inference indices = torch.tensor([int(math.floor(i * stride * fps)) for i in range(10)], dtype=torch.long) probs = [] i = 0 clip_count = len(cropped_frames) - indices[-1] while (i < clip_count): batch = min(clip_count - i, BATCH) clips = torch.stack([ transforms(cropped_frames[indices + i + j]) for j in range(batch) ]).to("cuda") results = model.evaluate(clips) probs.extend(results["logits"].softmax(dim=-1)[:, 1].flatten().cpu().tolist()) i += batch
# draw and write to video bbox_frames = [] for frame, bbox, prob in zip(frames[indices[-1]:], bboxes[indices[-1]:], probs): frame = frame.permute(1, 2, 0).numpy() frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) thickness = int(np.linalg.norm(bbox[0] - bbox[1]) * 0.01) color = (0, 255, 0) if prob < threshold else (0, 0, 255) category = "REAL" if prob < threshold else "FAKE" frame = cv2.rectangle( frame, bbox[0].astype(int), bbox[1].astype(int), color, thickness ) frame = cv2.putText( frame, f'{round(prob,2)}', [int(bbox[0][0]), int(bbox[1][1] - thickness)], cv2.FONT_HERSHEY_SIMPLEX, 1, color, thickness, cv2.LINE_AA )
frame = cv2.putText( frame, category, [int(bbox[0][0]), int(bbox[0][1] - thickness)], cv2.FONT_HERSHEY_SIMPLEX, 1, color, thickness, cv2.LINE_AA )
bbox_frames.append(frame)
out_path = (f'pred_{vid_name}.avi' if out_path is None else out_path)
writer = cv2.VideoWriter( out_path, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, (W, H) )
for frame in bbox_frames: writer.write(frame)
writer.release()
if __name__ == "__main__": configure_logging()
params = parse_args()
cli = ODLightningCLI( run=False, trainer_class=ODTrainer, save_config_callback=None, parser_kwargs={ "parser_mode": "omegaconf" }, auto_configure_optimizers=False, seed_everything_default=1019, args=[ '-c', params.model_cfg_path, '--trainer.logger=null', f'--trainer.devices=1', f'--trainer.precision={params.precision}', ], )
ckpt_path = params.model_ckpt_path video_path = params.video_path
demo_driver( cli=cli, ckpt_path=ckpt_path, video_path=video_path, batch_size=params.batch_size, threshold=params.threshold, out_path=params.out_path )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129name: dfd-fcgchannels: - defaultsdependencies: - _libgcc_mutex=0.1 - _openmp_mutex=5.1 - ca-certificates=2023.12.12 - ld_impl_linux-64=2.38 - libffi=3.4.4 - libgcc-ng=11.2.0 - libgomp=11.2.0 - libstdcxx-ng=11.2.0 - ncurses=6.4 - openssl=3.0.13 - pip=23.3.1 - python=3.8.18 - readline=8.2 - setuptools=68.2.2 - sqlite=3.41.2 - tk=8.6.12 - wheel=0.41.2 - xz=5.4.6 - zlib=1.2.13 - pip: - aiohttp==3.9.3 - aiosignal==1.3.1 - albumentations==1.4.0 - antlr4-python3-runtime==4.9.3 - appdirs==1.4.4 - async-timeout==4.0.3 - attrs==23.2.0 - av==11.0.0 - bitsandbytes==0.41.0 - certifi==2024.2.2 - charset-normalizer==3.3.2 - click==8.1.7 - contourpy==1.1.1 - cycler==0.12.1 - docker-pycreds==0.4.0 - docstring-parser==0.15 - face-alignment==1.4.1 - filelock==3.13.1 - fonttools==4.49.0 - frozenlist==1.4.1 - fsspec==2024.2.0 - ftfy==6.1.3 - gitdb==4.0.11 - gitpython==3.1.42 - huggingface-hub==0.21.3 - hydra-core==1.3.2 - idna==3.6 - imageio==2.34.0 - importlib-resources==6.1.2 - jinja2==3.1.3 - joblib==1.3.2 - jsonargparse==4.27.5 - kiwisolver==1.4.5 - lazy-loader==0.3 - lightning==2.2.0.post0 - lightning-utilities==0.10.1 - markdown-it-py==3.0.0 - markupsafe==2.1.5 - matplotlib==3.7.5 - mdurl==0.1.2 - mpmath==1.3.0 - multidict==6.0.5 - networkx==3.1 - numpy==1.24.4 - nvidia-cublas-cu12==12.1.3.1 - nvidia-cuda-cupti-cu12==12.1.105 - nvidia-cuda-nvrtc-cu12==12.1.105 - nvidia-cuda-runtime-cu12==12.1.105 - nvidia-cudnn-cu12==8.9.2.26 - nvidia-cufft-cu12==11.0.2.54 - nvidia-curand-cu12==10.3.2.106 - nvidia-cusolver-cu12==11.4.5.107 - nvidia-cusparse-cu12==12.1.0.106 - nvidia-nccl-cu12==2.19.3 - nvidia-nvjitlink-cu12==12.3.101 - nvidia-nvtx-cu12==12.1.105 - omegaconf==2.3.0 - open-clip-torch==2.24.0 - opencv-python==4.9.0.80 - opencv-python-headless==4.9.0.80 - packaging==23.2 - pandas==2.0.3 - pillow==10.2.0 - protobuf==4.25.3 - psutil==5.9.8 - pygments==2.17.2 - pyparsing==3.1.1 - python-dateutil==2.9.0.post0 - pytorch-lightning==2.2.0.post0 - pytz==2024.1 - pywavelets==1.4.1 - pyyaml==6.0.1 - qudida==0.0.4 - regex==2023.12.25 - requests==2.31.0 - rich==13.7.1 - safetensors==0.4.2 - scikit-image==0.21.0 - scikit-learn==1.3.2 - scipy==1.10.1 - sentencepiece==0.2.0 - sentry-sdk==1.40.6 - setproctitle==1.3.3 - six==1.16.0 - smmap==5.0.1 - sympy==1.12 - tensorboardx==2.6.2.2 - threadpoolctl==3.3.0 - tifffile==2023.7.10 - timm==0.9.16 - torch==2.2.1 - torchaudio==2.2.1 - torchmetrics==1.3.1 - torchvision==0.17.1 - tqdm==4.66.2 - triton==2.2.0 - typeshed-client==2.5.1 - typing-extensions==4.10.0 - tzdata==2024.1 - urllib3==2.2.1 - wandb==0.16.3 - wcwidth==0.2.13 - yarl==1.9.4 - zipp==3.17.0prefix: /home/od/miniconda3/envs/dfd-fcg123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187import osimport sysimport yamlimport jsonimport torchimport pickleimport shutilimport loggingimport warningsimport argparse
from os import pathfrom datetime import datetimefrom torchmetrics.classification import AUROC, Accuracyfrom src.utility.builtin import ODTrainer, ODLightningCLI
def parse_args(args=None): parser = argparse.ArgumentParser() parser.add_argument("model_cfg_path", type=str) parser.add_argument("data_cfg_path", type=str) parser.add_argument("model_ckpt_path", type=str) parser.add_argument("--precision", type=str, default="16") parser.add_argument("--devices", type=int, default=-1) parser.add_argument("--notes", type=str, default='') return parser.parse_args(args=args)
class StatsRecorder: def __init__(self, label): self.label = label self.prob = 0 self.count = 0
def update(self, prob, label): assert label == self.label self.prob += prob self.count += 1
def compute(self): return { "label": self.label, "prob": self.prob / self.count }
def configure_logging(): logging_fmt = "[%(levelname)s][%(filename)s:%(lineno)d]: %(message)s" logging.basicConfig(level="INFO", format=logging_fmt) warnings.filterwarnings(action="ignore")
@torch.inference_mode()def inference_driver(cli, cfg_dir, ckpt_path, notes=None):
timestamp = datetime.now().strftime("%m%dT%H%M%S")
trainer = cli.trainer
# setup model model = cli.model
try: model = model.__class__.load_from_checkpoint(ckpt_path) except Exception as e: print(f"Unable to load model from checkpoint in strict mode: {e}") print(f"Loading model from checkpoint in non-strict mode.") model = model.__class__.load_from_checkpoint(ckpt_path, strict=False)
model.eval()
# setup dataset datamodule = cli.datamodule datamodule.prepare_data() datamodule.affine_model(cli.model) datamodule.setup('test')
stats = {} report = {}
test_dataloaders = datamodule.test_dataloader()
for dts_name, dataloader in test_dataloaders.items(): # iterate all videos auc_calc = AUROC(task="BINARY", num_classes=2) acc_calc = Accuracy(task="BINARY", num_classes=2) dataset = dataloader.dataset dts_stats = {}
# perform ddp prediction batch_results = trainer.predict( model=model, dataloaders=[dataloader] )
gathered_results = [None] * torch.distributed.get_world_size() torch.distributed.all_gather_object(gathered_results, batch_results) torch.distributed.barrier()
if (trainer.is_global_zero): # fetch predict results and aggregate. for batch_results in gathered_results: for batch_result in batch_results: probs = batch_result["probs"] names = batch_result["names"] y = batch_result["y"] for prob, label, name in zip(probs, y, names): if (not name in dts_stats): dts_stats[name] = StatsRecorder(label) dts_stats[name].update(prob, label)
# compute the average probability. for k in dts_stats: dts_stats[k] = dts_stats[k].compute()
# add straying videos into metric calculation for k, v in dataset.stray_videos.items(): dts_stats[k] = dict( label=v, prob=0.5, stray=1 )
# compute the metric scores dataset_labels = [] dataset_probs = [] for v in dts_stats.values(): dataset_labels.append(v["label"]) dataset_probs.append(v["prob"]) dataset_labels = torch.tensor(dataset_labels) dataset_probs = torch.tensor(dataset_probs) accuracy = acc_calc(dataset_probs, dataset_labels).item() roc_auc = auc_calc(dataset_probs, dataset_labels).item() accuracy = round(accuracy, 3) roc_auc = round(roc_auc, 3) logging.info(f'[{dts_name}] accuracy: {accuracy}, roc_auc: {roc_auc}') stats[dts_name] = dts_stats report[dts_name] = { "accuracy": accuracy, "roc_auc": roc_auc }
if (trainer.is_global_zero): # save report and stats. with open(path.join(cfg_dir, f'report_{timestamp}.json'), "w") as f: json.dump(report, f, sort_keys=True, indent=4, separators=(',', ': '))
with open(path.join(cfg_dir, f'stats_{timestamp}.pickle'), "wb") as f: pickle.dump(stats, f)
return report
if __name__ == "__main__": configure_logging()
params = parse_args()
cli = ODLightningCLI( run=False, trainer_class=ODTrainer, save_config_callback=None, parser_kwargs={ "parser_mode": "omegaconf" }, auto_configure_optimizers=False, seed_everything_default=1019, args=[ '-c', params.model_cfg_path, '-c', params.data_cfg_path, '--trainer.logger=null', f'--trainer.devices={params.devices}', f'--trainer.precision={params.precision}', ], )
cfg_dir = os.path.split(params.model_cfg_path)[0] ckpt_path = params.model_ckpt_path notes = params.notes
inference_driver( cli=cli, cfg_dir=cfg_dir, ckpt_path=ckpt_path, notes=notes )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123import osimport gcimport jsonimport torchimport loggingimport warningsimport lightning.pytorch as pl
from lightning.pytorch.utilities import rank_zero_onlyfrom src.utility.builtin import ODTrainer, ODLightningCLIfrom inference import inference_drivertorch.set_float32_matmul_precision('high')
def configure_logging(): logging_fmt = "[%(levelname)s][%(filename)s:%(lineno)d]: %(message)s" logging.basicConfig(level="INFO", format=logging_fmt) warnings.filterwarnings(action="ignore")
# disable warnings from the xformers efficient attention module due to torch.user_deterministic_algorithms(True,warn_only=True) warnings.filterwarnings( action="ignore", message=".*efficient_attention_forward_cutlass.*", category=UserWarning )
# logging.basicConfig(level="DEBUG", format=logging_fmt)
def configure_cli(): return ODLightningCLI( run=False, trainer_class=ODTrainer, save_config_kwargs={ 'config_filename': 'setting.yaml' }, auto_configure_optimizers=True, seed_everything_default=1019 )
def inference(cli): # inference the best model cfg_dir = cli.trainer.log_dir ckpt_path = cli.trainer.checkpoint_callback.best_model_path
results = inference_driver( cli=cli, cfg_dir=cfg_dir, ckpt_path=ckpt_path, )
# log inference results cli.trainer.logger.experiment.log( { "/".join(["infer", dts_name, metric]): value for dts_name, metrics in results.items() for metric, value in metrics.items() }, commit=True )
return results
def cli_main(): # logging configuration configure_logging()
# initialize cli cli = configure_cli()
# update experiment notes cli.trainer.logger.experiment.notes = cli.config.notes cli.trainer.logger.experiment.save()
# monitor model gradient and parameter histograms # (this severely slow down the training speed) # cli.trainer.logger.experiment.watch(cli.model, log='all', log_graph=False)
# load & configure datasets cli.datamodule.affine_model(cli.model) cli.datamodule.affine_trainer(cli.trainer)
# determine the purpose of the given checkpoint cont_ckpt_path = None if not cli.config.ckpt_path is None: if cli.config.ckpt_mode == "cont": cont_ckpt_path = cli.config.ckpt_path elif cli.config.ckpt_mode == "tune": cli.model.load_state_dict(torch.load(cli.config.ckpt_path)["state_dict"]) else: raise NotImplementedError()
# run cli.trainer.fit( cli.model, datamodule=cli.datamodule, ckpt_path=cont_ckpt_path )
# after training: # 1. unwatch model # cli.trainer.logger.experiment.unwatch(cli.model) # 2. save the config cli.trainer.logger.experiment.save( glob_str=os.path.join(cli.trainer.log_dir, 'setting.yaml'), base_path=cli.trainer.log_dir, policy="now" )
gc.collect() torch.cuda.empty_cache()
# inference the best model. scores = inference(cli=cli)
# finally cli.trainer.logger.experiment.finish()
if __name__ == "__main__": cli_main()123version https://git-lfs.github.com/spec/v1oid sha256:dbf68b2044171e1160716df7c53e8bbfaa0ee8c61fb41171d04cb6092bb81422size 1168123version https://git-lfs.github.com/spec/v1oid sha256:438555d515700f0fdc4a1f2af2ca620d879fa7c91ca7018579e23aae94f0f72asize 2100301123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275<p align="center"> <h1 align="center">[CVPR'25] Towards More General Video-based Deepfake Detection through Facial Component Guided Adaptation for Foundation Model (DFD-FCG)</h1>
<p align="center"> <a href="https://github.com/ODD2"><strong>Yue-Hua Han</strong></a> <sup>1,3,4</sup> <a href="https://github.com/Teddy12155555"><strong>Tai-Ming Huang</strong></a> <sup>1,3,4</sup> <a href="https://scholar.google.com/citations?user=nnzQtDAAAAAJ&hl=zh-TW"><strong>Kai-Lung Hua</strong></a> <sup>2,4</sup> <a href="https://scholar.google.com.au/citations?user=3x9KITUAAAAJ&hl=en"><strong> Jun-Cheng Chen</strong></a> <sup>1</sup> <br> <!-- <sup>1</sup>Academia Sinica <sup>2</sup>Microsoft <sup>3</sup>National Taiwan University <br> <sup>4</sup>National Taiwan University of Science and Technology --> <sup>1</sup>Academia Sinica,</span> <sup>2</sup>Microsoft,</span> <sup>3</sup>National Taiwan University,</span> <br> <sup>4</sup>National Taiwan University of Science and Technology</span> <br> <a href='https://arxiv.org/abs/2404.05583'><img src='https://img.shields.io/badge/ArXiv-2404.05583-red'></a> <img src="assets/teaser.png"> </p></p>
## π₯Abstract<div style="text-align: justify"> Generative models have enabled the creation of highly realistic facial-synthetic images, raising significant concerns due to their potential for misuse. Despite rapid advancements in the field of deepfake detection, developing efficient approaches to leverage foundation models for improved generalizability to unseen forgery samples remains challenging. To address this challenge, we propose a novel side-network-based decoder that extracts spatial and temporal cues using the CLIP image encoder for generalized video-based Deepfake detection. Additionally, we introduce Facial Component Guidance (FCG) to enhance spatial learning generalizability by encouraging the model to focus on key facial regions. By leveraging the generic features of a vision-language foundation model, our approach demonstrates promising generalizability on challenging Deepfake datasets while also exhibiting superiority in training data efficiency, parameter efficiency, and model robustness.</div>
## πTODOs - [x] Training + Evaluation Code - [x] Model Weights - [x] Inference Code - [ ] HeyGen Evaluation Dataset
## πNews - June 08: We have released the [model checkpoint](https://drive.google.com/file/d/1ydD5rnaaF0i2zLE7NidLtAhjonHoVQOk/view?usp=sharing) and provided inference code for single videos! Checkout [this section](#inference---demo-video) for further details!
## πInstallation```shell# conda environmentconda env create -f environment.yml```
## πDataset StructureThe structure of the **pre-processed datasets** for our project, the video files (*.avi) have been processed to only retain the aligned face. We use soft-links **(ln -s)** to manage and link the folders containing pre-processed videos on different drives.```shelldatasetsβββ cdfβ βββ FAKEβ β βββ videosβ β βββ *.aviβ βββ REALβ β βββ videosβ β βββ *.aviβ βββ csv_filesβ βββ test_fake.csvβ βββ test_real.csvβββ dfdcβ βββ csv_filesβ β βββ test.csvβ βββ videosβββ dfoβ βββ FAKEβ β βββ videosβ β βββ *.aviβ βββ REALβ β βββ videosβ β βββ *.aviβ βββ csv_filesβ βββ test_fake.csvβ βββ test_real.csvβββ ffppβ βββ DFβ β βββ c23β β β βββ videosβ β β βββ *.aviβ β βββ c40β β β βββ videosβ β β βββ *.aviβ β βββ rawβ β βββ videosβ β β βββ *.aviβ βββ F2F ...β βββ FS ...β βββ FSh ...β βββ NT ...β βββ real ...β βββ csv_filesβ βββ test.jsonβ βββ train.jsonβ βββ val.json| βββ robustness βββ BW β βββ 1 β β βββ DF β β β βββ c23 β β β βββ videos β β β βββ *.avi β β βββ F2F ... β β βββ FS ... β β βββ FSh ... β β βββ NT ... β β βββ real ... β β β β β βββ csv_files β β βββ test.json β β βββ train.json β β βββ val.json β β β β β β . . . . . .```
## π§Dataset Pre-processing### Generic Pre-processingThis phase performs the required pre-processing for our method, this includes *facial alignment (using the mean face from LRW)* and *facial cropping*.```bash# First, fetch all the landmarks & bboxes of the video frames.python -m src.preprocess.fetch_landmark_bbox \ --root-dir="/storage/FaceForensicC23" \ # The root folder of the dataset--video-dir="videos" \ # The root folder of the videos--fdata-dir="frame_data" \ # The folder to save the extracted frame data--glob-exp="*/*" \ # The glob expression to search through the root video folder--split-num=1 \ # Split the dataset into several parts for parallel process.--part-num=1 \ # The part of dataset to process for parallel process.--batch=1 \ # The batch size for the 2D-FAN face data extraction. (suggestion: 1)--max-res=800 # The maximum resolution for either side of the image
# Then, crop all the faces from the original videos.python -m src.preprocess.crop_main_face \ --root-dir="/storage/FaceForensicC23/" \ # The root folder of the dataset--video-dir="videos" \ # The root folder of the videos--fdata-dir="frame_data" \ # The folder to fetch the frame data for landmarks and bboxes--glob-exp="*/*" \ # The glob expression to search through the root video folder--crop-dir="cropped" \ # The folder to save the cropped videos--crop-width=150 \ # The width for the cropped videos--crop-height=150 \ # The height for the cropped videos--mean-face="./misc/20words_mean_face.npy" # The mean face for face aligned cropping. --replace \ # Control whether to replace existing cropped videos--workers=1 # Number of works to perform parallel process (default: cpu / 2 )```
### Robustness Pre-processingThis phase requires the pre-processed facial landmarks to perform facial cropping, please refer to the **Generic Pre-processing** for further detail.```bash# First, we add perturbation to all the videos.python -m src.preprocess.phase1_apply_all_to_videos \ --dts-root="/storage/FaceForensicC23" \ # The root folder of the dataset--vid-dir="videos" \ # The root folder of the videos--rob-dir="robustness" \ # The folder to save the perturbed videos--glob-exp="*/*.mp4" \ # The glob expression to search through the root video folder--split=1 \ # Split the dataset into several parts for parallel process.--part=1 \ # The part of dataset to process for parallel process.--workers=1 # Number of works to perform parallel process (default: cpu / 2 )
# Then, crop all the faces from the perturbed videos.python -m src.preprocess.phase2_face_crop_all_videos \ (setup/run/clean) # the three phase operations--root-dir="/storage/FaceForensicC23/" \ # The root folder of the dataset--rob-dir="videos" \ # The root folder of the robustness videos--fd-dir="frame_data" \ # The folder to fetch the frame data for landmarks and bboxes--glob-exp="*/*/*/*.mp4" \ # The glob expression to search through the root video folder--crop-dir="cropped_robust" \ # The folder to save the cropped videos--mean-face="./misc/20words_mean_face.npy" \ # The mean face for face aligned cropping. --workers=1 # Number of works to perform parallel process (default: cpu / 2 )```
## π€Training & Evaluation### Training - Preset Settings In `./scripts`, scripts are provided to start the training process for the settings mentioned in our paper. These settings are configured to run on a cluster with `V100*4`.```bashbash ./scripts/model/ffg_l14.sh # begin training process```### Training - Custom SettingsOur project is built on `pytorch-lightning (2.2.0)`, please refer the [official manual](https://lightning.ai/docs/pytorch/2.2.0/common/trainer.html#trainer-class-api) and adjust the following files for advance configurations:```bash./configs/base.yaml # major training settings (e.g. epochs, optimizer, batch size, mixed-precision ...)./configs/data.yaml # settings for the training & validation dataset./configs/inference.yaml # settings for the evaluation dataset (extension of data.yaml)./configs/logger.yaml # settings for the WandB logger./configs/clip/L14/ffg.yaml # settings for the main model ./configs/test.yaml # settings for debugging (offline logging, small batch size, short epochs ...)```The following command starts the training process with the provided settings:```bash# For debugging, add '--config configs/test.yaml' after the '--config configs/clip/L14/ffg.yaml'.python main.py \--config configs/base.yaml \--config configs/clip/L14/ffg.yaml
# Fine-grained control is supported with the pytorch-lightning-cli.python main.py \--config configs/base.yaml \--config configs/clip/L14/ffg.yaml \--optimizer.lr=1e-5 \--trainer.max_epochs=10 \--data.init_args.train_datamodules.init_args.batch_size=5```### Evaluation - StandardTo perform evaluation on datasets, run the following command:```bashpython inference.py \"logs/fcg_l14/setting.yaml" \ # model settings"./configs/inference.yaml" \ # evaluation dataset settings"logs/fcg_l14/checkpoint.ckpt" \ # model checkpoint"--devices=4" # number of devices to compute in parallel```### Evaluation - RobustnessWe provide tools in `./scripts/tools/` to simplify the robustness evaluation task: `create-robust-config.sh` creates an evaluation config for each perturbation types and `inference-robust.sh` runs through all the datasets with the specified model.
## πInference - Demo VideoTo run inference on a single video with an indicator, please download our model checkpoint and execute the following commands:```bash# Pre-Processing: fetch facial landmark and bounding boxpython -m src.preprocess.fetch_landmark_bbox \--root-dir="./resources" \--video-dir="videos" \--fdata-dir="frame_data" \--glob-exp="*"# Pre-Processing: crop out the facial regionspython -m src.preprocess.crop_main_face \--root-dir="./resources" \--video-dir="videos" \--fdata-dir="frame_data" \--crop-dir="cropped" \--glob-exp="*"# Main Processpython -m demo \"checkpoint/setting.yaml" \ # the model setting of the checkpoint"checkpoint/weights.ckpt" \ # the model weights of the checkpoint"resources/videos/000_003.mp4" \ # the video to process--out_path="test.avi" \ # the output path of the processed video--threshold=0.5 \ # the threshold for the real/fake indicator--batch_size=30 # the input batch size of the model (~10G VRAM when batch_size=30 )```The following is a sample frame from the processed video:<p align="center"> <img src="assets/demo.png"></p>
<!-- ## π₯ Inference -->## π BibTeXIf you find our efforts helpful, please cite our paper and leave a star for further updates!```bibtex
@inproceedings{cvpr25_dfd_fcg, title={Towards More General Video-based Deepfake Detection through Facial Component Guided Adaptation for Foundation Model}, author={Yue-Hua Han, Tai-Ming Huang, Kai-Lung Hua, Jun-Cheng Chen}, booktitle={Proceedings of the Conference on Computer Vision and Pattern Recognition (CVPR)}, year={2025}}```
## π ContactThe provided code and weights are only available for research purpose only. If you have further questions (including commercial use), please contact [Dr. Jun-Cheng Chen](pullpull@citi.sinica.edu.tw).123version https://git-lfs.github.com/spec/v1oid sha256:0e51b9b46acc7eaeca62022e1b869541406d2ca887cd401dcc03cc5db28bc8edsize 894312123version https://git-lfs.github.com/spec/v1oid sha256:6e83d0e0c51a0f7cdf2db48f796617db43148b3390011555dfa758f2b7ab811bsize 891837123456python -m main \--config configs/base.yaml \--config configs/models/svl.yaml \--model.init_args.num_synos=4 \--config configs/generic/inference.yaml \--notes="no ffg guidance"video/dfd-fcg/model_code/configs/robustness/CC(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CC(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CC(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CS(1).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CS(2).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CS(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CS(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/CS(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GB(1).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GB(2).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GB(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GB(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GB(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GNC(1).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GNC(2).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GNC(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GNC(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/GNC(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/JPEG(1).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/JPEG(2).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/JPEG(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/JPEG(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/JPEG(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/VC(1).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/VC(2).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/VC(3).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/VC(4).yamlDeleted-14
video/dfd-fcg/model_code/configs/robustness/VC(5).yamlDeleted-14
video/dfd-fcg/model_code/configs/scenario/LOO/DF.yamlDeleted-32
video/dfd-fcg/model_code/configs/scenario/LOO/F2F.yamlDeleted-32
video/dfd-fcg/model_code/configs/scenario/LOO/FS.yamlDeleted-32
video/dfd-fcg/model_code/configs/scenario/LOO/NT.yamlDeleted-32
video/dfd-fcg/model_code/configs/scenario/compression/c40.yamlDeleted-55
video/dfd-fcg/model_code/configs/scenario/compression/raw.yamlDeleted-55
video/dfd-fcg/model_code/configs/scenario/partial/10.yamlDeleted-56
video/dfd-fcg/model_code/configs/scenario/partial/25.yamlDeleted-56
video/dfd-fcg/model_code/configs/scenario/partial/50.yamlDeleted-56
video/dfd-fcg/model_code/configs/scenario/partial/75.yamlDeleted-56
video/dfd-fcg/model_code/configs/scenario/robust/robust.yamlDeleted-33
video/dfd-fcg/model_code/configs/test.yamlDeleted-14
video/dfd-fcg/model_code/demo.pyDeleted-192
video/dfd-fcg/model_code/environment.ymlDeleted-129
video/dfd-fcg/model_code/inference.pyDeleted-187
video/dfd-fcg/model_code/main.pyDeleted-123
video/dfd-fcg/model_code/misc/20words_mean_face.npyDeleted-3
video/dfd-fcg/model_code/misc/L14_real_semantic_patches_v4_2000.pickleDeleted-3
video/dfd-fcg/model_code/readme.mdDeleted-275
video/dfd-fcg/model_code/resources/videos/000.mp4Deleted-3
video/dfd-fcg/model_code/resources/videos/000_003.mp4Deleted-3
video/dfd-fcg/model_code/scripts/ablation/ffg.shDeleted-6