Upload 78 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- configs/.DS_Store +0 -0
- configs/.ipynb_checkpoints/__init__-checkpoint.py +7 -0
- configs/__init__.py +7 -0
- configs/__pycache__/__init__.cpython-310.pyc +0 -0
- configs/__pycache__/__init__.cpython-311.pyc +0 -0
- configs/__pycache__/__init__.cpython-312.pyc +0 -0
- configs/__pycache__/get_config.cpython-310.pyc +0 -0
- configs/__pycache__/get_config.cpython-311.pyc +0 -0
- configs/__pycache__/get_config.cpython-312.pyc +0 -0
- configs/detector/.DS_Store +0 -0
- configs/detector/.ipynb_checkpoints/detector-checkpoint.yaml +86 -0
- configs/detector/.ipynb_checkpoints/detector2-checkpoint.yaml +140 -0
- configs/detector/.ipynb_checkpoints/efn4_fpn_hm_adv-checkpoint.yaml +159 -0
- configs/detector/detector.yaml +86 -0
- configs/detector/detector2 copie.yaml +142 -0
- configs/detector/detector2.yaml +142 -0
- configs/detector/efn4_fpn_hm_adv.yaml +159 -0
- configs/get_config.py +16 -0
- configs/test_config.yaml +38 -0
- configs/train_config copie.yaml +43 -0
- configs/train_config.yaml +46 -0
- loss/__init__.py +11 -0
- loss/__pycache__/__init__.cpython-312.pyc +0 -0
- loss/__pycache__/abstract_loss_func.cpython-312.pyc +0 -0
- loss/__pycache__/cross_entropy_loss.cpython-312.pyc +0 -0
- loss/abstract_loss_func.py +17 -0
- loss/cross_entropy_loss.py +26 -0
- metrics/__init__.py +7 -0
- metrics/__pycache__/__init__.cpython-312.pyc +0 -0
- metrics/__pycache__/base_metrics_class.cpython-312.pyc +0 -0
- metrics/__pycache__/registry.cpython-312.pyc +0 -0
- metrics/__pycache__/utils.cpython-312.pyc +0 -0
- metrics/base_metrics_class.py +204 -0
- metrics/registry.py +19 -0
- metrics/utils.py +92 -0
- models/.DS_Store +0 -0
- models/__init__.py +29 -0
- models/__pycache__/__init__.cpython-310.pyc +0 -0
- models/__pycache__/__init__.cpython-312.pyc +0 -0
- models/__pycache__/builder.cpython-310.pyc +0 -0
- models/__pycache__/builder.cpython-312.pyc +0 -0
- models/__pycache__/utils.cpython-310.pyc +0 -0
- models/__pycache__/utils.cpython-312.pyc +0 -0
- models/builder.py +45 -0
- models/networks/__pycache__/arcface.cpython-310.pyc +0 -0
- models/networks/__pycache__/arcface.cpython-312.pyc +0 -0
- models/networks/__pycache__/common.cpython-310.pyc +0 -0
- models/networks/__pycache__/common.cpython-312.pyc +0 -0
- models/networks/__pycache__/efficientNet.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
test3.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
test5.png filter=lfs diff=lfs merge=lfs -text
|
configs/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
configs/.ipynb_checkpoints/__init__-checkpoint.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
current_file_path = os.path.abspath(__file__)
|
| 4 |
+
parent_dir = os.path.dirname(os.path.dirname(current_file_path))
|
| 5 |
+
project_root_dir = os.path.dirname(parent_dir)
|
| 6 |
+
sys.path.append(parent_dir)
|
| 7 |
+
sys.path.append(project_root_dir)
|
configs/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
current_file_path = os.path.abspath(__file__)
|
| 4 |
+
parent_dir = os.path.dirname(os.path.dirname(current_file_path))
|
| 5 |
+
project_root_dir = os.path.dirname(parent_dir)
|
| 6 |
+
sys.path.append(parent_dir)
|
| 7 |
+
sys.path.append(project_root_dir)
|
configs/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (341 Bytes). View file
|
|
|
configs/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (707 Bytes). View file
|
|
|
configs/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (725 Bytes). View file
|
|
|
configs/__pycache__/get_config.cpython-310.pyc
ADDED
|
Binary file (598 Bytes). View file
|
|
|
configs/__pycache__/get_config.cpython-311.pyc
ADDED
|
Binary file (974 Bytes). View file
|
|
|
configs/__pycache__/get_config.cpython-312.pyc
ADDED
|
Binary file (809 Bytes). View file
|
|
|
configs/detector/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
configs/detector/.ipynb_checkpoints/detector-checkpoint.yaml
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# log dir
|
| 2 |
+
log_dir: ./logs_debug/clip_wavelet
|
| 3 |
+
|
| 4 |
+
# model setting
|
| 5 |
+
pretrained: ./training/weights/clip_wavelet_best.pth # path to a pre-trained model, if using one
|
| 6 |
+
model_name: clip_wavelet # model name
|
| 7 |
+
backbone_name: vit # backbone name
|
| 8 |
+
|
| 9 |
+
#backbone setting
|
| 10 |
+
backbone_config:
|
| 11 |
+
mode: original
|
| 12 |
+
num_classes: 2
|
| 13 |
+
inc: 3
|
| 14 |
+
dropout: false
|
| 15 |
+
|
| 16 |
+
# dataset
|
| 17 |
+
all_dataset: [FaceShifter, Celeb-DF-v1, Celeb-DF-v2]
|
| 18 |
+
train_dataset: [iFakeFaceDB]
|
| 19 |
+
test_dataset: [Celeb-DF-v1, Celeb-DF-v2, FaceShifter]
|
| 20 |
+
|
| 21 |
+
compression: c23 # compression-level for videos
|
| 22 |
+
train_batchSize: 64 # training batch size
|
| 23 |
+
test_batchSize: 64 # test batch size
|
| 24 |
+
workers: 8 # number of data loading workers
|
| 25 |
+
frame_num: {'train': 300, 'test': 300} # number of frames to use per video in training and testing
|
| 26 |
+
resolution: 224 # resolution of output image to network
|
| 27 |
+
with_mask: false # whether to include mask information in the input
|
| 28 |
+
with_landmark: false # whether to include facial landmark information in the input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# data augmentation
|
| 32 |
+
use_data_augmentation: true # Add this flag to enable/disable data augmentation
|
| 33 |
+
data_aug:
|
| 34 |
+
flip_prob: 0.5
|
| 35 |
+
rotate_prob: 0.5
|
| 36 |
+
rotate_limit: [-10, 10]
|
| 37 |
+
blur_prob: 0.5
|
| 38 |
+
blur_limit: [3, 7]
|
| 39 |
+
brightness_prob: 0.5
|
| 40 |
+
brightness_limit: [-0.1, 0.1]
|
| 41 |
+
contrast_limit: [-0.1, 0.1]
|
| 42 |
+
quality_lower: 40
|
| 43 |
+
quality_upper: 100
|
| 44 |
+
|
| 45 |
+
# mean and std for normalization
|
| 46 |
+
mean: [0.5, 0.5, 0.5]
|
| 47 |
+
std: [0.5, 0.5, 0.5]
|
| 48 |
+
|
| 49 |
+
# optimizer config
|
| 50 |
+
optimizer:
|
| 51 |
+
# choose between 'adam' and 'sgd'
|
| 52 |
+
type: adam
|
| 53 |
+
adam:
|
| 54 |
+
lr: 0.00001 # learning rate
|
| 55 |
+
beta1: 0.9 # beta1 for Adam optimizer
|
| 56 |
+
beta2: 0.999 # beta2 for Adam optimizer
|
| 57 |
+
eps: 0.00000001 # epsilon for Adam optimizer
|
| 58 |
+
weight_decay: 0.0005 # weight decay for regularization
|
| 59 |
+
amsgrad: false
|
| 60 |
+
sgd:
|
| 61 |
+
lr: 0.0002 # learning rate
|
| 62 |
+
momentum: 0.9 # momentum for SGD optimizer
|
| 63 |
+
weight_decay: 0.0005 # weight decay for regularization
|
| 64 |
+
|
| 65 |
+
# training config
|
| 66 |
+
lr_scheduler: null # learning rate scheduler
|
| 67 |
+
nEpochs: 50 # number of epochs to train for
|
| 68 |
+
start_epoch: 0 # manual epoch number (useful for restarts)
|
| 69 |
+
save_epoch: 1 # interval epochs for saving models
|
| 70 |
+
rec_iter: 100 # interval iterations for recording
|
| 71 |
+
logdir: ./logs # folder to output images and logs
|
| 72 |
+
manualSeed: 1024 # manual seed for random number generation
|
| 73 |
+
save_ckpt: true # whether to save checkpoint
|
| 74 |
+
save_feat: true # whether to save features
|
| 75 |
+
|
| 76 |
+
# loss function
|
| 77 |
+
loss_func: cross_entropy # loss function to use
|
| 78 |
+
losstype: null
|
| 79 |
+
|
| 80 |
+
# metric
|
| 81 |
+
metric_scoring: auc # metric for evaluation (auc, acc, eer, ap)
|
| 82 |
+
|
| 83 |
+
# cuda
|
| 84 |
+
|
| 85 |
+
cuda: true # whether to use CUDA acceleration
|
| 86 |
+
cudnn: true # whether to use CuDNN for convolution operations
|
configs/detector/.ipynb_checkpoints/detector2-checkpoint.yaml
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TASK: custom_laanet
|
| 2 |
+
PRECISION: float64
|
| 3 |
+
METRICS_BASE: binary
|
| 4 |
+
SEED: 317
|
| 5 |
+
DATA_RELOAD: False
|
| 6 |
+
|
| 7 |
+
MODEL:
|
| 8 |
+
# PRETRAINED_PATH: ''
|
| 9 |
+
type: PoseEfficientNet
|
| 10 |
+
model_name: efficientnet-b4
|
| 11 |
+
num_layers: B4
|
| 12 |
+
include_top: False
|
| 13 |
+
include_hm_decoder: True
|
| 14 |
+
head_conv: 64
|
| 15 |
+
use_c2: False
|
| 16 |
+
use_c3: True
|
| 17 |
+
use_c4: True
|
| 18 |
+
use_c51: True
|
| 19 |
+
efpn: True
|
| 20 |
+
tfpn: False
|
| 21 |
+
se_layer: False
|
| 22 |
+
heads:
|
| 23 |
+
hm: 1
|
| 24 |
+
cls: 1
|
| 25 |
+
cstency: 256
|
| 26 |
+
INIT_WEIGHTS:
|
| 27 |
+
pretrained: True
|
| 28 |
+
advprop: True
|
| 29 |
+
|
| 30 |
+
DATASET:
|
| 31 |
+
type: BinaryFaceForensic
|
| 32 |
+
FROM_FILE: False
|
| 33 |
+
PIN_MEMORY: True
|
| 34 |
+
NUM_WORKERS: 7
|
| 35 |
+
COLOR_NORM: 'simple'
|
| 36 |
+
mean: [0.485, 0.456, 0.406]
|
| 37 |
+
std: [0.229, 0.224, 0.225]
|
| 38 |
+
IMAGE_SUFFIX: png
|
| 39 |
+
COMPRESSION: c0
|
| 40 |
+
IMAGE_SUFFIX: png
|
| 41 |
+
IMAGE_SIZE: [384, 384]
|
| 42 |
+
HEATMAP_SIZE: [96, 96] #[IMAGE_SIZE//4, IMAGE_SIZE//4]
|
| 43 |
+
SIGMA: 2
|
| 44 |
+
ADAPTIVE_SIGMA: True
|
| 45 |
+
HEATMAP_TYPE: gaussian
|
| 46 |
+
SPLIT_IMAGE: False
|
| 47 |
+
DATA:
|
| 48 |
+
TYPE: frames
|
| 49 |
+
SAMPLES_PER_VIDEO:
|
| 50 |
+
ACTIVE: True
|
| 51 |
+
TRAIN: 8
|
| 52 |
+
VAL: 8
|
| 53 |
+
TEST: 32
|
| 54 |
+
TRAIN:
|
| 55 |
+
NAME: custom_dataset
|
| 56 |
+
ROOT: ./datasets/train/
|
| 57 |
+
FROM_FILE: False
|
| 58 |
+
FAKETYPE: [fake]
|
| 59 |
+
LABEL_FOLDER: [real, fake]
|
| 60 |
+
|
| 61 |
+
VAL:
|
| 62 |
+
NAME: custom_dataset
|
| 63 |
+
ROOT: ./datasets/test/
|
| 64 |
+
FROM_FILE: False
|
| 65 |
+
FAKETYPE: [fake]
|
| 66 |
+
LABEL_FOLDER: [real, fake]
|
| 67 |
+
TEST:
|
| 68 |
+
NAME: custom_dataset
|
| 69 |
+
ROOT: ./datasets/test/
|
| 70 |
+
FROM_FILE: False
|
| 71 |
+
FAKETYPE: [fake]
|
| 72 |
+
LABEL_FOLDER: [real, fake]
|
| 73 |
+
TRANSFORM:
|
| 74 |
+
geometry:
|
| 75 |
+
type: GeometryTransform
|
| 76 |
+
resize: [384, 384, 0] #h, w, p=probability. If no affine transform, set p=1
|
| 77 |
+
normalize: 0
|
| 78 |
+
horizontal_flip: 0.5
|
| 79 |
+
cropping: [0.15, 0.5] #Format: [crop_limit, prob]
|
| 80 |
+
scale: [0.15, 0.5] #Format: [scale_limit, prob]
|
| 81 |
+
rand_erasing: [0.5, 1] #Format: [p, max_count]
|
| 82 |
+
color:
|
| 83 |
+
type: ColorJitterTransform
|
| 84 |
+
clahe: 0.0
|
| 85 |
+
colorjitter: 0.3
|
| 86 |
+
gaussianblur: 0.3
|
| 87 |
+
gaussnoise: 0.3
|
| 88 |
+
jpegcompression: [0.5, 40, 100] # prob, lower and upper quality respectively
|
| 89 |
+
rgbshift: 0.3
|
| 90 |
+
randomcontrast: 0.0
|
| 91 |
+
randomgamma: 0.5
|
| 92 |
+
randombrightness: 1
|
| 93 |
+
huesat: 1
|
| 94 |
+
normalize:
|
| 95 |
+
mean: [0.5, 0.5, 0.5]
|
| 96 |
+
std: [0.5, 0.5, 0.5]
|
| 97 |
+
|
| 98 |
+
TRAIN:
|
| 99 |
+
resume: True
|
| 100 |
+
gpus: [0]
|
| 101 |
+
pretrained_model: './training/weights/final_model.pth'
|
| 102 |
+
batch_size: 8
|
| 103 |
+
lr: 0.00005
|
| 104 |
+
epochs: 100
|
| 105 |
+
begin_epoch: 48
|
| 106 |
+
warm_up: 6
|
| 107 |
+
every_val_epochs: 1
|
| 108 |
+
loss:
|
| 109 |
+
type: CombinedFocalLoss
|
| 110 |
+
use_target_weight: False
|
| 111 |
+
cls_lmda: 1
|
| 112 |
+
dst_hm_cls_lmda: 0
|
| 113 |
+
offset_lmda: 0
|
| 114 |
+
hm_lmda: 100
|
| 115 |
+
cstency_lmda: 100
|
| 116 |
+
mse_reduction: sum
|
| 117 |
+
ce_reduction: mean
|
| 118 |
+
optimizer: SAM
|
| 119 |
+
distributed: False
|
| 120 |
+
tensorboard: False
|
| 121 |
+
resume: True
|
| 122 |
+
lr_scheduler:
|
| 123 |
+
# type: MultiStepLR
|
| 124 |
+
milestones: [5, 15, 20, 25]
|
| 125 |
+
gamma: 0.5
|
| 126 |
+
freeze_backbone: True
|
| 127 |
+
debug:
|
| 128 |
+
active: False
|
| 129 |
+
save_hm_gt: True
|
| 130 |
+
save_hm_pred: True
|
| 131 |
+
|
| 132 |
+
TEST:
|
| 133 |
+
gpus: [0]
|
| 134 |
+
subtask: 'eval'
|
| 135 |
+
test_file: ''
|
| 136 |
+
vis_hm: True
|
| 137 |
+
threshold: 0.5
|
| 138 |
+
flip_test: True
|
| 139 |
+
video_level: True
|
| 140 |
+
pretrained: './training/weights/final_model.pth'
|
configs/detector/.ipynb_checkpoints/efn4_fpn_hm_adv-checkpoint.yaml
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TASK: EFN_hm10_EFPN_NoBasedCLS_Focal_C2_256Cst100_32FXRayv2_SAM(Adam)_ADV_Era3_OutSoftMax_5e5_div4_FZ
|
| 2 |
+
PRECISION: float64
|
| 3 |
+
METRICS_BASE: binary
|
| 4 |
+
SEED: 317
|
| 5 |
+
DATA_RELOAD: True
|
| 6 |
+
DATASET:
|
| 7 |
+
type: HeatmapFaceForensic
|
| 8 |
+
TRAIN: True #Switch to True for training mode, False for testing mode
|
| 9 |
+
COMPRESSION: c0
|
| 10 |
+
IMAGE_SUFFIX: png
|
| 11 |
+
NUM_WORKERS: 7
|
| 12 |
+
PIN_MEMORY: True
|
| 13 |
+
IMAGE_SIZE: [384, 384]
|
| 14 |
+
HEATMAP_SIZE: [96, 96] #[IMAGE_SIZE//4, IMAGE_SIZE//4]
|
| 15 |
+
SIGMA: 2
|
| 16 |
+
ADAPTIVE_SIGMA: True
|
| 17 |
+
HEATMAP_TYPE: gaussian
|
| 18 |
+
SPLIT_IMAGE: False
|
| 19 |
+
DATA:
|
| 20 |
+
TYPE: frames
|
| 21 |
+
SAMPLES_PER_VIDEO:
|
| 22 |
+
ACTIVE: True
|
| 23 |
+
TRAIN: 32 # Dynamically random number of frames in each epoch
|
| 24 |
+
VAL: 32
|
| 25 |
+
TEST: 32
|
| 26 |
+
TRAIN:
|
| 27 |
+
NAME: FF++ # This field to define datasets that can be used to train/in-dataset/cross-dataset evaluation
|
| 28 |
+
ROOT: /home/users/<user>/data/FaceForensics++/c0/
|
| 29 |
+
# ROOT: /data/deepfake_cluster/datasets_df/FaceForensics++/c0/
|
| 30 |
+
FROM_FILE: True
|
| 31 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 32 |
+
# ANNO_FILE: train/frames/FaceXRay/train_FF_FaceXRay.json
|
| 33 |
+
ANNO_FILE: processed_data/c0/dynamic_trainBI_FFv2.json
|
| 34 |
+
LABEL_FOLDER: [real, fake]
|
| 35 |
+
VAL:
|
| 36 |
+
NAME: FF++ # This field to define datasets that can be used to train/in-dataset/cross-dataset evaluation
|
| 37 |
+
ROOT: /Deep/datasets/
|
| 38 |
+
FROM_FILE: True
|
| 39 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures] # Choosing Deepfake techniques to be loaded for dataloader
|
| 40 |
+
# ANNO_FILE: val/frames/FaceXRay/val_FF_FaceXRay.json
|
| 41 |
+
ANNO_FILE: processed_data/c0/dynamic_valBI_FFv2.json
|
| 42 |
+
LABEL_FOLDER: [real, fake]
|
| 43 |
+
TEST:
|
| 44 |
+
NAME: DFW
|
| 45 |
+
# ROOT: /home/users/<user>/data/FaceForensics++/c0/
|
| 46 |
+
# ROOT: /home/users/<user>/data/Celeb-DFv1/
|
| 47 |
+
# ROOT: /data/deepfake_cluster/datasets_df/Celeb-DFv1/
|
| 48 |
+
# ROOT: /home/users/<user>/data/Celeb-DFv2/
|
| 49 |
+
# ROOT: /home/users/<user>/data/DFDCP/
|
| 50 |
+
# ROOT: /home/users/<user>/data/DFDC/
|
| 51 |
+
# ROOT: /home/users/<user>/data/DFD/
|
| 52 |
+
ROOT: /home/users/<user>/data/DFW/
|
| 53 |
+
FROM_FILE: False
|
| 54 |
+
# FAKETYPE: [original, Deepfakes]
|
| 55 |
+
# FAKETYPE: [original, Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 56 |
+
# FAKETYPE: [Celeb-real, Celeb-synthesis, YouTube-real]
|
| 57 |
+
# FAKETYPE: [method_A, method_B, original_videos]
|
| 58 |
+
# FAKETYPE: [fake, real]
|
| 59 |
+
# FAKETYPE: [DeepFakeDetection_original, DeepFakeDetection]
|
| 60 |
+
FAKETYPE: [real_test, fake_test]
|
| 61 |
+
ANNO_FILE: FaceXRay/test/test_FF_Xray.json
|
| 62 |
+
LABEL_FOLDER: [real, fake]
|
| 63 |
+
TRANSFORM:
|
| 64 |
+
geometry:
|
| 65 |
+
type: GeometryTransform
|
| 66 |
+
resize: [384, 384, 0] #h, w, p=probability. If no affine transform, set p=1
|
| 67 |
+
normalize: 0
|
| 68 |
+
horizontal_flip: 0.5
|
| 69 |
+
cropping: [0.15, 0.5] #Format: [crop_limit, prob]
|
| 70 |
+
scale: [0.15, 0.5] #Format: [scale_limit, prob]
|
| 71 |
+
rand_erasing: [0.5, 1] #Format: [p, max_count]
|
| 72 |
+
color:
|
| 73 |
+
type: ColorJitterTransform
|
| 74 |
+
clahe: 0.0
|
| 75 |
+
colorjitter: 0.3
|
| 76 |
+
gaussianblur: 0.3
|
| 77 |
+
gaussnoise: 0.3
|
| 78 |
+
jpegcompression: [0.5, 40, 100] # prob, lower and upper quality respectively
|
| 79 |
+
rgbshift: 0.3
|
| 80 |
+
randomcontrast: 0.0
|
| 81 |
+
randomgamma: 0.5
|
| 82 |
+
randombrightness: 1
|
| 83 |
+
huesat: 1
|
| 84 |
+
normalize:
|
| 85 |
+
mean: [0.5, 0.5, 0.5]
|
| 86 |
+
std: [0.5, 0.5, 0.5]
|
| 87 |
+
DEBUG: False
|
| 88 |
+
DYNAMIC_FXRAY: True
|
| 89 |
+
MODEL:
|
| 90 |
+
type: PoseEfficientNet
|
| 91 |
+
model_name: efficientnet-b4
|
| 92 |
+
num_layers: B4
|
| 93 |
+
include_top: False
|
| 94 |
+
include_hm_decoder: True
|
| 95 |
+
head_conv: 64
|
| 96 |
+
use_c2: False
|
| 97 |
+
use_c3: True
|
| 98 |
+
use_c4: True
|
| 99 |
+
use_c51: True
|
| 100 |
+
efpn: True
|
| 101 |
+
tfpn: False
|
| 102 |
+
se_layer: False
|
| 103 |
+
heads:
|
| 104 |
+
hm: 1
|
| 105 |
+
cls: 1
|
| 106 |
+
cstency: 256
|
| 107 |
+
INIT_WEIGHTS:
|
| 108 |
+
pretrained: True
|
| 109 |
+
advprop: True
|
| 110 |
+
TRAIN:
|
| 111 |
+
gpus: [0]
|
| 112 |
+
batch_size: 16
|
| 113 |
+
lr: 0.00005
|
| 114 |
+
epochs: 100
|
| 115 |
+
begin_epoch: -1
|
| 116 |
+
warm_up: 6
|
| 117 |
+
every_val_epochs: 1
|
| 118 |
+
loss:
|
| 119 |
+
type: CombinedFocalLoss
|
| 120 |
+
use_target_weight: False
|
| 121 |
+
cls_lmda: 1
|
| 122 |
+
dst_hm_cls_lmda: 0
|
| 123 |
+
offset_lmda: 0
|
| 124 |
+
hm_lmda: 10
|
| 125 |
+
cstency_lmda: 100
|
| 126 |
+
mse_reduction: sum
|
| 127 |
+
ce_reduction: mean
|
| 128 |
+
optimizer: SAM
|
| 129 |
+
distributed: False
|
| 130 |
+
pretrained: '~/Deep/training/weights/LALALAND1.pth'
|
| 131 |
+
tensorboard: True
|
| 132 |
+
resume: True
|
| 133 |
+
lr_scheduler:
|
| 134 |
+
# type: MultiStepLR
|
| 135 |
+
milestones: [5, 15, 20, 25]
|
| 136 |
+
gamma: 0.5
|
| 137 |
+
freeze_backbone: True
|
| 138 |
+
debug:
|
| 139 |
+
active: False
|
| 140 |
+
save_hm_gt: True
|
| 141 |
+
save_hm_pred: True
|
| 142 |
+
TEST:
|
| 143 |
+
gpus: [0]
|
| 144 |
+
subtask: 'eval'
|
| 145 |
+
test_file: ''
|
| 146 |
+
vis_hm: True
|
| 147 |
+
threshold: 0.5
|
| 148 |
+
flip_test: True
|
| 149 |
+
video_level: True
|
| 150 |
+
pretrained: '~/Deep/training/weights/LALALAND1.pth'
|
| 151 |
+
PREPROCESSING:
|
| 152 |
+
DATASET: FaceForensics
|
| 153 |
+
SPLIT: train
|
| 154 |
+
ROOT: ~/Deep/datasets/
|
| 155 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 156 |
+
IMAGE_SUFFIX: jpg
|
| 157 |
+
DATA_TYPE: images
|
| 158 |
+
LABEL: [real, fake]
|
| 159 |
+
DEBUG: False
|
configs/detector/detector.yaml
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# log dir
|
| 2 |
+
log_dir: ./logs_debug/clip_wavelet
|
| 3 |
+
|
| 4 |
+
# model setting
|
| 5 |
+
pretrained: ./training/weights/clip_wavelet_best.pth # path to a pre-trained model, if using one
|
| 6 |
+
model_name: clip_wavelet # model name
|
| 7 |
+
backbone_name: vit # backbone name
|
| 8 |
+
|
| 9 |
+
#backbone setting
|
| 10 |
+
backbone_config:
|
| 11 |
+
mode: original
|
| 12 |
+
num_classes: 2
|
| 13 |
+
inc: 3
|
| 14 |
+
dropout: false
|
| 15 |
+
|
| 16 |
+
# dataset
|
| 17 |
+
all_dataset: [FaceShifter, Celeb-DF-v1, Celeb-DF-v2]
|
| 18 |
+
train_dataset: [iFakeFaceDB]
|
| 19 |
+
test_dataset: [Celeb-DF-v1, Celeb-DF-v2, FaceShifter]
|
| 20 |
+
|
| 21 |
+
compression: c23 # compression-level for videos
|
| 22 |
+
train_batchSize: 64 # training batch size
|
| 23 |
+
test_batchSize: 64 # test batch size
|
| 24 |
+
workers: 8 # number of data loading workers
|
| 25 |
+
frame_num: {'train': 300, 'test': 300} # number of frames to use per video in training and testing
|
| 26 |
+
resolution: 224 # resolution of output image to network
|
| 27 |
+
with_mask: false # whether to include mask information in the input
|
| 28 |
+
with_landmark: false # whether to include facial landmark information in the input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# data augmentation
|
| 32 |
+
use_data_augmentation: true # Add this flag to enable/disable data augmentation
|
| 33 |
+
data_aug:
|
| 34 |
+
flip_prob: 0.5
|
| 35 |
+
rotate_prob: 0.5
|
| 36 |
+
rotate_limit: [-10, 10]
|
| 37 |
+
blur_prob: 0.5
|
| 38 |
+
blur_limit: [3, 7]
|
| 39 |
+
brightness_prob: 0.5
|
| 40 |
+
brightness_limit: [-0.1, 0.1]
|
| 41 |
+
contrast_limit: [-0.1, 0.1]
|
| 42 |
+
quality_lower: 40
|
| 43 |
+
quality_upper: 100
|
| 44 |
+
|
| 45 |
+
# mean and std for normalization
|
| 46 |
+
mean: [0.5, 0.5, 0.5]
|
| 47 |
+
std: [0.5, 0.5, 0.5]
|
| 48 |
+
|
| 49 |
+
# optimizer config
|
| 50 |
+
optimizer:
|
| 51 |
+
# choose between 'adam' and 'sgd'
|
| 52 |
+
type: adam
|
| 53 |
+
adam:
|
| 54 |
+
lr: 0.00001 # learning rate
|
| 55 |
+
beta1: 0.9 # beta1 for Adam optimizer
|
| 56 |
+
beta2: 0.999 # beta2 for Adam optimizer
|
| 57 |
+
eps: 0.00000001 # epsilon for Adam optimizer
|
| 58 |
+
weight_decay: 0.0005 # weight decay for regularization
|
| 59 |
+
amsgrad: false
|
| 60 |
+
sgd:
|
| 61 |
+
lr: 0.0002 # learning rate
|
| 62 |
+
momentum: 0.9 # momentum for SGD optimizer
|
| 63 |
+
weight_decay: 0.0005 # weight decay for regularization
|
| 64 |
+
|
| 65 |
+
# training config
|
| 66 |
+
lr_scheduler: null # learning rate scheduler
|
| 67 |
+
nEpochs: 50 # number of epochs to train for
|
| 68 |
+
start_epoch: 0 # manual epoch number (useful for restarts)
|
| 69 |
+
save_epoch: 1 # interval epochs for saving models
|
| 70 |
+
rec_iter: 100 # interval iterations for recording
|
| 71 |
+
logdir: ./logs # folder to output images and logs
|
| 72 |
+
manualSeed: 1024 # manual seed for random number generation
|
| 73 |
+
save_ckpt: true # whether to save checkpoint
|
| 74 |
+
save_feat: true # whether to save features
|
| 75 |
+
|
| 76 |
+
# loss function
|
| 77 |
+
loss_func: cross_entropy # loss function to use
|
| 78 |
+
losstype: null
|
| 79 |
+
|
| 80 |
+
# metric
|
| 81 |
+
metric_scoring: auc # metric for evaluation (auc, acc, eer, ap)
|
| 82 |
+
|
| 83 |
+
# cuda
|
| 84 |
+
|
| 85 |
+
cuda: true # whether to use CUDA acceleration
|
| 86 |
+
cudnn: true # whether to use CuDNN for convolution operations
|
configs/detector/detector2 copie.yaml
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TASK: custom_laanet
|
| 2 |
+
PRECISION: float32
|
| 3 |
+
METRICS_BASE: binary
|
| 4 |
+
SEED: 317
|
| 5 |
+
DATA_RELOAD: False
|
| 6 |
+
Resume: True
|
| 7 |
+
begin_epoch: 100
|
| 8 |
+
|
| 9 |
+
MODEL:
|
| 10 |
+
# PRETRAINED_PATH: ''
|
| 11 |
+
type: PoseEfficientNet
|
| 12 |
+
model_name: efficientnet-b4
|
| 13 |
+
num_layers: B4
|
| 14 |
+
include_top: False
|
| 15 |
+
include_hm_decoder: True
|
| 16 |
+
head_conv: 64
|
| 17 |
+
use_c2: False
|
| 18 |
+
use_c3: True
|
| 19 |
+
use_c4: True
|
| 20 |
+
use_c51: True
|
| 21 |
+
efpn: True
|
| 22 |
+
tfpn: False
|
| 23 |
+
se_layer: False
|
| 24 |
+
heads:
|
| 25 |
+
hm: 1
|
| 26 |
+
cls: 1
|
| 27 |
+
cstency: 256
|
| 28 |
+
INIT_WEIGHTS:
|
| 29 |
+
pretrained: True
|
| 30 |
+
advprop: True
|
| 31 |
+
|
| 32 |
+
DATASET:
|
| 33 |
+
type: BinaryFaceForensic
|
| 34 |
+
FROM_FILE: False
|
| 35 |
+
PIN_MEMORY: True
|
| 36 |
+
NUM_WORKERS: 7
|
| 37 |
+
COLOR_NORM: 'simple'
|
| 38 |
+
mean: [0.485, 0.456, 0.406]
|
| 39 |
+
std: [0.229, 0.224, 0.225]
|
| 40 |
+
IMAGE_SUFFIX: png
|
| 41 |
+
COMPRESSION: c0
|
| 42 |
+
IMAGE_SUFFIX: png
|
| 43 |
+
IMAGE_SIZE: [384, 384]
|
| 44 |
+
HEATMAP_SIZE: [96, 96] #[IMAGE_SIZE//4, IMAGE_SIZE//4]
|
| 45 |
+
SIGMA: 2
|
| 46 |
+
ADAPTIVE_SIGMA: True
|
| 47 |
+
HEATMAP_TYPE: gaussian
|
| 48 |
+
SPLIT_IMAGE: False
|
| 49 |
+
DATA:
|
| 50 |
+
TYPE: frames
|
| 51 |
+
SAMPLES_PER_VIDEO:
|
| 52 |
+
ACTIVE: True
|
| 53 |
+
TRAIN: 8
|
| 54 |
+
VAL: 8
|
| 55 |
+
TEST: 32
|
| 56 |
+
TRAIN:
|
| 57 |
+
NAME: custom_dataset
|
| 58 |
+
ROOT: ./datasets/train/
|
| 59 |
+
FROM_FILE: False
|
| 60 |
+
FAKETYPE: [fake]
|
| 61 |
+
LABEL_FOLDER: [real, fake]
|
| 62 |
+
|
| 63 |
+
VAL:
|
| 64 |
+
NAME: custom_dataset
|
| 65 |
+
ROOT: ./datasets/test/
|
| 66 |
+
FROM_FILE: False
|
| 67 |
+
FAKETYPE: [fake]
|
| 68 |
+
LABEL_FOLDER: [real, fake]
|
| 69 |
+
TEST:
|
| 70 |
+
NAME: custom_dataset
|
| 71 |
+
ROOT: ./datasets/test/
|
| 72 |
+
FROM_FILE: False
|
| 73 |
+
FAKETYPE: [fake]
|
| 74 |
+
LABEL_FOLDER: [real, fake]
|
| 75 |
+
TRANSFORM:
|
| 76 |
+
geometry:
|
| 77 |
+
type: GeometryTransform
|
| 78 |
+
resize: [384, 384, 0] #h, w, p=probability. If no affine transform, set p=1
|
| 79 |
+
normalize: 0
|
| 80 |
+
horizontal_flip: 0.5
|
| 81 |
+
cropping: [0.15, 0.5] #Format: [crop_limit, prob]
|
| 82 |
+
scale: [0.15, 0.5] #Format: [scale_limit, prob]
|
| 83 |
+
rand_erasing: [0.5, 1] #Format: [p, max_count]
|
| 84 |
+
color:
|
| 85 |
+
type: ColorJitterTransform
|
| 86 |
+
clahe: 0.0
|
| 87 |
+
colorjitter: 0.3
|
| 88 |
+
gaussianblur: 0.3
|
| 89 |
+
gaussnoise: 0.3
|
| 90 |
+
jpegcompression: [0.5, 40, 100] # prob, lower and upper quality respectively
|
| 91 |
+
rgbshift: 0.3
|
| 92 |
+
randomcontrast: 0.0
|
| 93 |
+
randomgamma: 0.5
|
| 94 |
+
randombrightness: 1
|
| 95 |
+
huesat: 1
|
| 96 |
+
normalize:
|
| 97 |
+
mean: [0.5, 0.5, 0.5]
|
| 98 |
+
std: [0.5, 0.5, 0.5]
|
| 99 |
+
|
| 100 |
+
TRAIN:
|
| 101 |
+
resume: True
|
| 102 |
+
gpus: [0]
|
| 103 |
+
pretrained_model: './logs/27-03-2025/PoseEfficientNet_custom_laanet_model_final.pth'
|
| 104 |
+
batch_size: 32
|
| 105 |
+
lr: 0.00005
|
| 106 |
+
epochs: 150
|
| 107 |
+
begin_epoch: 100
|
| 108 |
+
warm_up: 6
|
| 109 |
+
every_val_epochs: 1
|
| 110 |
+
loss:
|
| 111 |
+
type: CombinedFocalLoss
|
| 112 |
+
use_target_weight: False
|
| 113 |
+
cls_lmda: 1
|
| 114 |
+
dst_hm_cls_lmda: 0
|
| 115 |
+
offset_lmda: 0
|
| 116 |
+
hm_lmda: 100
|
| 117 |
+
cstency_lmda: 100
|
| 118 |
+
mse_reduction: sum
|
| 119 |
+
ce_reduction: mean
|
| 120 |
+
optimizer: SAM
|
| 121 |
+
distributed: False
|
| 122 |
+
tensorboard: False
|
| 123 |
+
resume: True
|
| 124 |
+
lr_scheduler:
|
| 125 |
+
# type: MultiStepLR
|
| 126 |
+
milestones: [5, 15, 20, 25]
|
| 127 |
+
gamma: 0.5
|
| 128 |
+
freeze_backbone: True
|
| 129 |
+
debug:
|
| 130 |
+
active: False
|
| 131 |
+
save_hm_gt: True
|
| 132 |
+
save_hm_pred: True
|
| 133 |
+
|
| 134 |
+
TEST:
|
| 135 |
+
gpus: [0]
|
| 136 |
+
subtask: 'eval'
|
| 137 |
+
test_file: ''
|
| 138 |
+
vis_hm: True
|
| 139 |
+
threshold: 0.5
|
| 140 |
+
flip_test: True
|
| 141 |
+
video_level: True
|
| 142 |
+
pretrained: './training/weights/final_model.pth'
|
configs/detector/detector2.yaml
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TASK: custom_laanet
|
| 2 |
+
PRECISION: float32
|
| 3 |
+
METRICS_BASE: binary
|
| 4 |
+
SEED: 317
|
| 5 |
+
DATA_RELOAD: False
|
| 6 |
+
Resume: True
|
| 7 |
+
begin_epoch: 100
|
| 8 |
+
|
| 9 |
+
MODEL:
|
| 10 |
+
# PRETRAINED_PATH: ''
|
| 11 |
+
type: PoseEfficientNet
|
| 12 |
+
model_name: efficientnet-b4
|
| 13 |
+
num_layers: B4
|
| 14 |
+
include_top: False
|
| 15 |
+
include_hm_decoder: True
|
| 16 |
+
head_conv: 64
|
| 17 |
+
use_c2: False
|
| 18 |
+
use_c3: True
|
| 19 |
+
use_c4: True
|
| 20 |
+
use_c51: True
|
| 21 |
+
efpn: True
|
| 22 |
+
tfpn: False
|
| 23 |
+
se_layer: False
|
| 24 |
+
heads:
|
| 25 |
+
hm: 1
|
| 26 |
+
cls: 1
|
| 27 |
+
cstency: 256
|
| 28 |
+
INIT_WEIGHTS:
|
| 29 |
+
pretrained: True
|
| 30 |
+
advprop: True
|
| 31 |
+
|
| 32 |
+
DATASET:
|
| 33 |
+
type: BinaryFaceForensic
|
| 34 |
+
FROM_FILE: False
|
| 35 |
+
PIN_MEMORY: True
|
| 36 |
+
NUM_WORKERS: 7
|
| 37 |
+
COLOR_NORM: 'simple'
|
| 38 |
+
mean: [0.485, 0.456, 0.406]
|
| 39 |
+
std: [0.229, 0.224, 0.225]
|
| 40 |
+
IMAGE_SUFFIX: png
|
| 41 |
+
COMPRESSION: c0
|
| 42 |
+
IMAGE_SUFFIX: png
|
| 43 |
+
IMAGE_SIZE: [384, 384]
|
| 44 |
+
HEATMAP_SIZE: [96, 96] #[IMAGE_SIZE//4, IMAGE_SIZE//4]
|
| 45 |
+
SIGMA: 2
|
| 46 |
+
ADAPTIVE_SIGMA: True
|
| 47 |
+
HEATMAP_TYPE: gaussian
|
| 48 |
+
SPLIT_IMAGE: False
|
| 49 |
+
DATA:
|
| 50 |
+
TYPE: frames
|
| 51 |
+
SAMPLES_PER_VIDEO:
|
| 52 |
+
ACTIVE: True
|
| 53 |
+
TRAIN: 8
|
| 54 |
+
VAL: 8
|
| 55 |
+
TEST: 32
|
| 56 |
+
TRAIN:
|
| 57 |
+
NAME: custom_dataset
|
| 58 |
+
ROOT: ./datasets/train/
|
| 59 |
+
FROM_FILE: False
|
| 60 |
+
FAKETYPE: [fake]
|
| 61 |
+
LABEL_FOLDER: [real, fake]
|
| 62 |
+
|
| 63 |
+
VAL:
|
| 64 |
+
NAME: custom_dataset
|
| 65 |
+
ROOT: ./datasets/test/
|
| 66 |
+
FROM_FILE: False
|
| 67 |
+
FAKETYPE: [fake]
|
| 68 |
+
LABEL_FOLDER: [real, fake]
|
| 69 |
+
TEST:
|
| 70 |
+
NAME: custom_dataset
|
| 71 |
+
ROOT: ./datasets/test/
|
| 72 |
+
FROM_FILE: False
|
| 73 |
+
FAKETYPE: [fake]
|
| 74 |
+
LABEL_FOLDER: [real, fake]
|
| 75 |
+
TRANSFORM:
|
| 76 |
+
geometry:
|
| 77 |
+
type: GeometryTransform
|
| 78 |
+
resize: [384, 384, 0] #h, w, p=probability. If no affine transform, set p=1
|
| 79 |
+
normalize: 0
|
| 80 |
+
horizontal_flip: 0.5
|
| 81 |
+
cropping: [0.15, 0.5] #Format: [crop_limit, prob]
|
| 82 |
+
scale: [0.15, 0.5] #Format: [scale_limit, prob]
|
| 83 |
+
rand_erasing: [0.5, 1] #Format: [p, max_count]
|
| 84 |
+
color:
|
| 85 |
+
type: ColorJitterTransform
|
| 86 |
+
clahe: 0.0
|
| 87 |
+
colorjitter: 0.3
|
| 88 |
+
gaussianblur: 0.3
|
| 89 |
+
gaussnoise: 0.3
|
| 90 |
+
jpegcompression: [0.5, 40, 100] # prob, lower and upper quality respectively
|
| 91 |
+
rgbshift: 0.3
|
| 92 |
+
randomcontrast: 0.0
|
| 93 |
+
randomgamma: 0.5
|
| 94 |
+
randombrightness: 1
|
| 95 |
+
huesat: 1
|
| 96 |
+
normalize:
|
| 97 |
+
mean: [0.5, 0.5, 0.5]
|
| 98 |
+
std: [0.5, 0.5, 0.5]
|
| 99 |
+
|
| 100 |
+
TRAIN:
|
| 101 |
+
resume: True
|
| 102 |
+
gpus: [0]
|
| 103 |
+
pretrained_model: './logs/27-03-2025/PoseEfficientNet_custom_laanet_model_final.pth'
|
| 104 |
+
batch_size: 32
|
| 105 |
+
lr: 0.00005
|
| 106 |
+
epochs: 150
|
| 107 |
+
begin_epoch: 100
|
| 108 |
+
warm_up: 6
|
| 109 |
+
every_val_epochs: 1
|
| 110 |
+
loss:
|
| 111 |
+
type: CombinedFocalLoss
|
| 112 |
+
use_target_weight: False
|
| 113 |
+
cls_lmda: 1
|
| 114 |
+
dst_hm_cls_lmda: 0
|
| 115 |
+
offset_lmda: 0
|
| 116 |
+
hm_lmda: 100
|
| 117 |
+
cstency_lmda: 100
|
| 118 |
+
mse_reduction: sum
|
| 119 |
+
ce_reduction: mean
|
| 120 |
+
optimizer: SAM
|
| 121 |
+
distributed: False
|
| 122 |
+
tensorboard: False
|
| 123 |
+
resume: True
|
| 124 |
+
lr_scheduler:
|
| 125 |
+
# type: MultiStepLR
|
| 126 |
+
milestones: [5, 15, 20, 25]
|
| 127 |
+
gamma: 0.5
|
| 128 |
+
freeze_backbone: True
|
| 129 |
+
debug:
|
| 130 |
+
active: False
|
| 131 |
+
save_hm_gt: True
|
| 132 |
+
save_hm_pred: True
|
| 133 |
+
|
| 134 |
+
TEST:
|
| 135 |
+
gpus: [0]
|
| 136 |
+
subtask: 'eval'
|
| 137 |
+
test_file: ''
|
| 138 |
+
vis_hm: True
|
| 139 |
+
threshold: 0.5
|
| 140 |
+
flip_test: True
|
| 141 |
+
video_level: True
|
| 142 |
+
pretrained: './training/weights/final_model.pth'
|
configs/detector/efn4_fpn_hm_adv.yaml
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TASK: EFN_hm10_EFPN_NoBasedCLS_Focal_C2_256Cst100_32FXRayv2_SAM(Adam)_ADV_Era3_OutSoftMax_5e5_div4_FZ
|
| 2 |
+
PRECISION: float64
|
| 3 |
+
METRICS_BASE: binary
|
| 4 |
+
SEED: 317
|
| 5 |
+
DATA_RELOAD: True
|
| 6 |
+
DATASET:
|
| 7 |
+
type: HeatmapFaceForensic
|
| 8 |
+
TRAIN: True #Switch to True for training mode, False for testing mode
|
| 9 |
+
COMPRESSION: c0
|
| 10 |
+
IMAGE_SUFFIX: png
|
| 11 |
+
NUM_WORKERS: 7
|
| 12 |
+
PIN_MEMORY: True
|
| 13 |
+
IMAGE_SIZE: [384, 384]
|
| 14 |
+
HEATMAP_SIZE: [96, 96] #[IMAGE_SIZE//4, IMAGE_SIZE//4]
|
| 15 |
+
SIGMA: 2
|
| 16 |
+
ADAPTIVE_SIGMA: True
|
| 17 |
+
HEATMAP_TYPE: gaussian
|
| 18 |
+
SPLIT_IMAGE: False
|
| 19 |
+
DATA:
|
| 20 |
+
TYPE: frames
|
| 21 |
+
SAMPLES_PER_VIDEO:
|
| 22 |
+
ACTIVE: True
|
| 23 |
+
TRAIN: 32 # Dynamically random number of frames in each epoch
|
| 24 |
+
VAL: 32
|
| 25 |
+
TEST: 32
|
| 26 |
+
TRAIN:
|
| 27 |
+
NAME: FF++ # This field to define datasets that can be used to train/in-dataset/cross-dataset evaluation
|
| 28 |
+
ROOT: /home/users/<user>/data/FaceForensics++/c0/
|
| 29 |
+
# ROOT: /data/deepfake_cluster/datasets_df/FaceForensics++/c0/
|
| 30 |
+
FROM_FILE: True
|
| 31 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 32 |
+
# ANNO_FILE: train/frames/FaceXRay/train_FF_FaceXRay.json
|
| 33 |
+
ANNO_FILE: processed_data/c0/dynamic_trainBI_FFv2.json
|
| 34 |
+
LABEL_FOLDER: [real, fake]
|
| 35 |
+
VAL:
|
| 36 |
+
NAME: FF++ # This field to define datasets that can be used to train/in-dataset/cross-dataset evaluation
|
| 37 |
+
ROOT: /Deep/datasets/
|
| 38 |
+
FROM_FILE: True
|
| 39 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures] # Choosing Deepfake techniques to be loaded for dataloader
|
| 40 |
+
# ANNO_FILE: val/frames/FaceXRay/val_FF_FaceXRay.json
|
| 41 |
+
ANNO_FILE: processed_data/c0/dynamic_valBI_FFv2.json
|
| 42 |
+
LABEL_FOLDER: [real, fake]
|
| 43 |
+
TEST:
|
| 44 |
+
NAME: DFW
|
| 45 |
+
# ROOT: /home/users/<user>/data/FaceForensics++/c0/
|
| 46 |
+
# ROOT: /home/users/<user>/data/Celeb-DFv1/
|
| 47 |
+
# ROOT: /data/deepfake_cluster/datasets_df/Celeb-DFv1/
|
| 48 |
+
# ROOT: /home/users/<user>/data/Celeb-DFv2/
|
| 49 |
+
# ROOT: /home/users/<user>/data/DFDCP/
|
| 50 |
+
# ROOT: /home/users/<user>/data/DFDC/
|
| 51 |
+
# ROOT: /home/users/<user>/data/DFD/
|
| 52 |
+
ROOT: /home/users/<user>/data/DFW/
|
| 53 |
+
FROM_FILE: False
|
| 54 |
+
# FAKETYPE: [original, Deepfakes]
|
| 55 |
+
# FAKETYPE: [original, Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 56 |
+
# FAKETYPE: [Celeb-real, Celeb-synthesis, YouTube-real]
|
| 57 |
+
# FAKETYPE: [method_A, method_B, original_videos]
|
| 58 |
+
# FAKETYPE: [fake, real]
|
| 59 |
+
# FAKETYPE: [DeepFakeDetection_original, DeepFakeDetection]
|
| 60 |
+
FAKETYPE: [real_test, fake_test]
|
| 61 |
+
ANNO_FILE: FaceXRay/test/test_FF_Xray.json
|
| 62 |
+
LABEL_FOLDER: [real, fake]
|
| 63 |
+
TRANSFORM:
|
| 64 |
+
geometry:
|
| 65 |
+
type: GeometryTransform
|
| 66 |
+
resize: [384, 384, 0] #h, w, p=probability. If no affine transform, set p=1
|
| 67 |
+
normalize: 0
|
| 68 |
+
horizontal_flip: 0.5
|
| 69 |
+
cropping: [0.15, 0.5] #Format: [crop_limit, prob]
|
| 70 |
+
scale: [0.15, 0.5] #Format: [scale_limit, prob]
|
| 71 |
+
rand_erasing: [0.5, 1] #Format: [p, max_count]
|
| 72 |
+
color:
|
| 73 |
+
type: ColorJitterTransform
|
| 74 |
+
clahe: 0.0
|
| 75 |
+
colorjitter: 0.3
|
| 76 |
+
gaussianblur: 0.3
|
| 77 |
+
gaussnoise: 0.3
|
| 78 |
+
jpegcompression: [0.5, 40, 100] # prob, lower and upper quality respectively
|
| 79 |
+
rgbshift: 0.3
|
| 80 |
+
randomcontrast: 0.0
|
| 81 |
+
randomgamma: 0.5
|
| 82 |
+
randombrightness: 1
|
| 83 |
+
huesat: 1
|
| 84 |
+
normalize:
|
| 85 |
+
mean: [0.5, 0.5, 0.5]
|
| 86 |
+
std: [0.5, 0.5, 0.5]
|
| 87 |
+
DEBUG: False
|
| 88 |
+
DYNAMIC_FXRAY: True
|
| 89 |
+
MODEL:
|
| 90 |
+
type: PoseEfficientNet
|
| 91 |
+
model_name: efficientnet-b4
|
| 92 |
+
num_layers: B4
|
| 93 |
+
include_top: False
|
| 94 |
+
include_hm_decoder: True
|
| 95 |
+
head_conv: 64
|
| 96 |
+
use_c2: False
|
| 97 |
+
use_c3: True
|
| 98 |
+
use_c4: True
|
| 99 |
+
use_c51: True
|
| 100 |
+
efpn: True
|
| 101 |
+
tfpn: False
|
| 102 |
+
se_layer: False
|
| 103 |
+
heads:
|
| 104 |
+
hm: 1
|
| 105 |
+
cls: 1
|
| 106 |
+
cstency: 256
|
| 107 |
+
INIT_WEIGHTS:
|
| 108 |
+
pretrained: True
|
| 109 |
+
advprop: True
|
| 110 |
+
TRAIN:
|
| 111 |
+
gpus: [0]
|
| 112 |
+
batch_size: 16
|
| 113 |
+
lr: 0.00005
|
| 114 |
+
epochs: 100
|
| 115 |
+
begin_epoch: -1
|
| 116 |
+
warm_up: 6
|
| 117 |
+
every_val_epochs: 1
|
| 118 |
+
loss:
|
| 119 |
+
type: CombinedFocalLoss
|
| 120 |
+
use_target_weight: False
|
| 121 |
+
cls_lmda: 1
|
| 122 |
+
dst_hm_cls_lmda: 0
|
| 123 |
+
offset_lmda: 0
|
| 124 |
+
hm_lmda: 10
|
| 125 |
+
cstency_lmda: 100
|
| 126 |
+
mse_reduction: sum
|
| 127 |
+
ce_reduction: mean
|
| 128 |
+
optimizer: SAM
|
| 129 |
+
distributed: False
|
| 130 |
+
pretrained: '~/Deep/training/weights/LALALAND1.pth'
|
| 131 |
+
tensorboard: True
|
| 132 |
+
resume: True
|
| 133 |
+
lr_scheduler:
|
| 134 |
+
# type: MultiStepLR
|
| 135 |
+
milestones: [5, 15, 20, 25]
|
| 136 |
+
gamma: 0.5
|
| 137 |
+
freeze_backbone: True
|
| 138 |
+
debug:
|
| 139 |
+
active: False
|
| 140 |
+
save_hm_gt: True
|
| 141 |
+
save_hm_pred: True
|
| 142 |
+
TEST:
|
| 143 |
+
gpus: [0]
|
| 144 |
+
subtask: 'eval'
|
| 145 |
+
test_file: ''
|
| 146 |
+
vis_hm: True
|
| 147 |
+
threshold: 0.5
|
| 148 |
+
flip_test: True
|
| 149 |
+
video_level: True
|
| 150 |
+
pretrained: '~/Deep/training/weights/LALALAND1.pth'
|
| 151 |
+
PREPROCESSING:
|
| 152 |
+
DATASET: FaceForensics
|
| 153 |
+
SPLIT: train
|
| 154 |
+
ROOT: ~/Deep/datasets/
|
| 155 |
+
FAKETYPE: [Deepfakes, Face2Face, FaceSwap, NeuralTextures]
|
| 156 |
+
IMAGE_SUFFIX: jpg
|
| 157 |
+
DATA_TYPE: images
|
| 158 |
+
LABEL: [real, fake]
|
| 159 |
+
DEBUG: False
|
configs/get_config.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#-*- coding: utf-8 -*-
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from yaml import load, dump
|
| 5 |
+
try:
|
| 6 |
+
from yaml import CLoader as Loader, CDumper as Dumper
|
| 7 |
+
except ImportError:
|
| 8 |
+
from yaml import Loader, Dumper
|
| 9 |
+
from box import Box as edict
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def load_config(cfg):
|
| 13 |
+
with open(cfg) as f:
|
| 14 |
+
config = load(f, Loader=Loader)
|
| 15 |
+
|
| 16 |
+
return edict(config)
|
configs/test_config.yaml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mode: test
|
| 2 |
+
lmdb: False
|
| 3 |
+
rgb_dir: '/ssd_scratch/deep_fake_dataset/'
|
| 4 |
+
lmdb_dir: '/ssd_scratch/deep_fake_dataset/datasets_lmdbs/'
|
| 5 |
+
dataset_json_folder: './preprocessing/dataset_json_v6/'
|
| 6 |
+
label_dict:
|
| 7 |
+
# DFD
|
| 8 |
+
DFD_fake: 1
|
| 9 |
+
DFD_real: 0
|
| 10 |
+
# FF++ + FaceShifter(FF-real+FF-FH)
|
| 11 |
+
FF-SH: 1
|
| 12 |
+
FF-F2F: 1
|
| 13 |
+
FF-DF: 1
|
| 14 |
+
FF-FS: 1
|
| 15 |
+
FF-NT: 1
|
| 16 |
+
FF-FH: 1
|
| 17 |
+
FF-real: 0
|
| 18 |
+
# CelebDF
|
| 19 |
+
CelebDFv1_real: 0
|
| 20 |
+
CelebDFv1_fake: 1
|
| 21 |
+
CelebDFv2_real: 0
|
| 22 |
+
CelebDFv2_fake: 1
|
| 23 |
+
# DFDCP
|
| 24 |
+
DFDCP_Real: 0
|
| 25 |
+
DFDCP_FakeA: 1
|
| 26 |
+
DFDCP_FakeB: 1
|
| 27 |
+
# DFDC
|
| 28 |
+
DFDC_Fake: 1
|
| 29 |
+
DFDC_Real: 0
|
| 30 |
+
# DeeperForensics-1.0
|
| 31 |
+
DF_fake: 1
|
| 32 |
+
DF_real: 0
|
| 33 |
+
# UADFV
|
| 34 |
+
UADFV_Fake: 1
|
| 35 |
+
UADFV_Real: 0
|
| 36 |
+
# Roop
|
| 37 |
+
roop_Real: 0
|
| 38 |
+
roop_Fake: 1
|
configs/train_config copie.yaml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mode: train
|
| 2 |
+
lmdb: False
|
| 3 |
+
dry_run: False
|
| 4 |
+
rgb_dir: '/ssd_scratch/deep_fake_dataset/'
|
| 5 |
+
lmdb_dir: '/ssd_scratch/deep_fake_dataset/datasets_lmdbs/'
|
| 6 |
+
dataset_json_folder: './preprocessing/dataset_json_v6/'
|
| 7 |
+
SWA: False
|
| 8 |
+
save_avg: True
|
| 9 |
+
log_dir: ./logs/training/
|
| 10 |
+
# label settings
|
| 11 |
+
label_dict:
|
| 12 |
+
# DFD
|
| 13 |
+
DFD_fake: 1
|
| 14 |
+
DFD_real: 0
|
| 15 |
+
# FF++ + FaceShifter(FF-real+FF-FH)
|
| 16 |
+
FF-SH: 1
|
| 17 |
+
FF-F2F: 1
|
| 18 |
+
FF-DF: 1
|
| 19 |
+
FF-FS: 1
|
| 20 |
+
FF-NT: 1
|
| 21 |
+
FF-FH: 1
|
| 22 |
+
FF-real: 0
|
| 23 |
+
# CelebDF
|
| 24 |
+
CelebDFv1_real: 0
|
| 25 |
+
CelebDFv1_fake: 1
|
| 26 |
+
CelebDFv2_real: 0
|
| 27 |
+
CelebDFv2_fake: 1
|
| 28 |
+
# DFDCP
|
| 29 |
+
DFDCP_Real: 0
|
| 30 |
+
DFDCP_FakeA: 1
|
| 31 |
+
DFDCP_FakeB: 1
|
| 32 |
+
# DFDC
|
| 33 |
+
DFDC_Fake: 1
|
| 34 |
+
DFDC_Real: 0
|
| 35 |
+
# DeeperForensics-1.0
|
| 36 |
+
DF_fake: 1
|
| 37 |
+
DF_real: 0
|
| 38 |
+
# UADFV
|
| 39 |
+
UADFV_Fake: 1
|
| 40 |
+
UADFV_Real: 0
|
| 41 |
+
# Roop
|
| 42 |
+
roop_Real: 0
|
| 43 |
+
roop_Fake: 1
|
configs/train_config.yaml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mode: train
|
| 2 |
+
lmdb: False
|
| 3 |
+
dry_run: False
|
| 4 |
+
rgb_dir: '/ssd_scratch/deep_fake_dataset/'
|
| 5 |
+
lmdb_dir: '/ssd_scratch/deep_fake_dataset/datasets_lmdbs/'
|
| 6 |
+
dataset_json_folder: './preprocessing/dataset_json_v6/'
|
| 7 |
+
SWA: False
|
| 8 |
+
save_avg: True
|
| 9 |
+
log_dir: ./logs/training/
|
| 10 |
+
# label settings
|
| 11 |
+
label_dict:
|
| 12 |
+
# iFakeFaceDB labels
|
| 13 |
+
real: 0
|
| 14 |
+
fake: 1
|
| 15 |
+
# DFD
|
| 16 |
+
DFD_fake: 1
|
| 17 |
+
DFD_real: 0
|
| 18 |
+
# FF++ + FaceShifter(FF-real+FF-FH)
|
| 19 |
+
FF-SH: 1
|
| 20 |
+
FF-F2F: 1
|
| 21 |
+
FF-DF: 1
|
| 22 |
+
FF-FS: 1
|
| 23 |
+
FF-NT: 1
|
| 24 |
+
FF-FH: 1
|
| 25 |
+
FF-real: 0
|
| 26 |
+
# CelebDF
|
| 27 |
+
CelebDFv1_real: 0
|
| 28 |
+
CelebDFv1_fake: 1
|
| 29 |
+
CelebDFv2_real: 0
|
| 30 |
+
CelebDFv2_fake: 1
|
| 31 |
+
# DFDCP
|
| 32 |
+
DFDCP_Real: 0
|
| 33 |
+
DFDCP_FakeA: 1
|
| 34 |
+
DFDCP_FakeB: 1
|
| 35 |
+
# DFDC
|
| 36 |
+
DFDC_Fake: 1
|
| 37 |
+
DFDC_Real: 0
|
| 38 |
+
# DeeperForensics-1.0
|
| 39 |
+
DF_fake: 1
|
| 40 |
+
DF_real: 0
|
| 41 |
+
# UADFV
|
| 42 |
+
UADFV_Fake: 1
|
| 43 |
+
UADFV_Real: 0
|
| 44 |
+
# Roop
|
| 45 |
+
roop_Real: 0
|
| 46 |
+
roop_Fake: 1
|
loss/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
current_file_path = os.path.abspath(__file__)
|
| 4 |
+
parent_dir = os.path.dirname(os.path.dirname(current_file_path))
|
| 5 |
+
project_root_dir = os.path.dirname(parent_dir)
|
| 6 |
+
sys.path.append(parent_dir)
|
| 7 |
+
sys.path.append(project_root_dir)
|
| 8 |
+
|
| 9 |
+
from metrics.registry import LOSSFUNC
|
| 10 |
+
|
| 11 |
+
from .cross_entropy_loss import CrossEntropyLoss
|
loss/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (837 Bytes). View file
|
|
|
loss/__pycache__/abstract_loss_func.cpython-312.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
loss/__pycache__/cross_entropy_loss.cpython-312.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
loss/abstract_loss_func.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch.nn as nn
|
| 2 |
+
|
| 3 |
+
class AbstractLossClass(nn.Module):
|
| 4 |
+
"""Abstract class for loss functions."""
|
| 5 |
+
def __init__(self):
|
| 6 |
+
super(AbstractLossClass, self).__init__()
|
| 7 |
+
|
| 8 |
+
def forward(self, pred, label):
|
| 9 |
+
"""
|
| 10 |
+
Args:
|
| 11 |
+
pred: prediction of the model
|
| 12 |
+
label: ground truth label
|
| 13 |
+
|
| 14 |
+
Return:
|
| 15 |
+
loss: loss value
|
| 16 |
+
"""
|
| 17 |
+
raise NotImplementedError('Each subclass should implement the forward method.')
|
loss/cross_entropy_loss.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch.nn as nn
|
| 2 |
+
from .abstract_loss_func import AbstractLossClass
|
| 3 |
+
from metrics.registry import LOSSFUNC
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@LOSSFUNC.register_module(module_name="cross_entropy")
|
| 7 |
+
class CrossEntropyLoss(AbstractLossClass):
|
| 8 |
+
def __init__(self):
|
| 9 |
+
super().__init__()
|
| 10 |
+
self.loss_fn = nn.CrossEntropyLoss()
|
| 11 |
+
|
| 12 |
+
def forward(self, inputs, targets):
|
| 13 |
+
"""
|
| 14 |
+
Computes the cross-entropy loss.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
inputs: A PyTorch tensor of size (batch_size, num_classes) containing the predicted scores.
|
| 18 |
+
targets: A PyTorch tensor of size (batch_size) containing the ground-truth class indices.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A scalar tensor representing the cross-entropy loss.
|
| 22 |
+
"""
|
| 23 |
+
# Compute the cross-entropy loss
|
| 24 |
+
loss = self.loss_fn(inputs, targets)
|
| 25 |
+
|
| 26 |
+
return loss
|
metrics/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
current_file_path = os.path.abspath(__file__)
|
| 4 |
+
parent_dir = os.path.dirname(os.path.dirname(current_file_path))
|
| 5 |
+
project_root_dir = os.path.dirname(parent_dir)
|
| 6 |
+
sys.path.append(parent_dir)
|
| 7 |
+
sys.path.append(project_root_dir)
|
metrics/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (719 Bytes). View file
|
|
|
metrics/__pycache__/base_metrics_class.cpython-312.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
metrics/__pycache__/registry.cpython-312.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
metrics/__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (4.43 kB). View file
|
|
|
metrics/base_metrics_class.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from sklearn import metrics
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_accracy(output, label):
|
| 8 |
+
_, prediction = torch.max(output, 1) # argmax
|
| 9 |
+
correct = (prediction == label).sum().item()
|
| 10 |
+
accuracy = correct / prediction.size(0)
|
| 11 |
+
return accuracy
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_prediction(output, label):
|
| 15 |
+
prob = nn.functional.softmax(output, dim=1)[:, 1]
|
| 16 |
+
prob = prob.view(prob.size(0), 1)
|
| 17 |
+
label = label.view(label.size(0), 1)
|
| 18 |
+
#print(prob.size(), label.size())
|
| 19 |
+
datas = torch.cat((prob, label.float()), dim=1)
|
| 20 |
+
return datas
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def calculate_metrics_for_train(label, output):
|
| 24 |
+
if output.size(1) == 2:
|
| 25 |
+
prob = torch.softmax(output, dim=1)[:, 1]
|
| 26 |
+
else:
|
| 27 |
+
prob = output
|
| 28 |
+
|
| 29 |
+
# Accuracy
|
| 30 |
+
_, prediction = torch.max(output, 1)
|
| 31 |
+
correct = (prediction == label).sum().item()
|
| 32 |
+
accuracy = correct / prediction.size(0)
|
| 33 |
+
|
| 34 |
+
# Average Precision
|
| 35 |
+
y_true = label.cpu().detach().numpy()
|
| 36 |
+
y_pred = prob.cpu().detach().numpy()
|
| 37 |
+
ap = metrics.average_precision_score(y_true, y_pred)
|
| 38 |
+
|
| 39 |
+
# AUC and EER
|
| 40 |
+
try:
|
| 41 |
+
fpr, tpr, thresholds = metrics.roc_curve(label.squeeze().cpu().numpy(),
|
| 42 |
+
prob.squeeze().cpu().numpy(),
|
| 43 |
+
pos_label=1)
|
| 44 |
+
except:
|
| 45 |
+
# for the case when we only have one sample
|
| 46 |
+
return None, None, accuracy, ap
|
| 47 |
+
|
| 48 |
+
if np.isnan(fpr[0]) or np.isnan(tpr[0]):
|
| 49 |
+
# for the case when all the samples within a batch is fake/real
|
| 50 |
+
auc, eer = None, None
|
| 51 |
+
else:
|
| 52 |
+
auc = metrics.auc(fpr, tpr)
|
| 53 |
+
fnr = 1 - tpr
|
| 54 |
+
eer = fpr[np.nanargmin(np.absolute((fnr - fpr)))]
|
| 55 |
+
|
| 56 |
+
return auc, eer, accuracy, ap
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# ------------ compute average metrics of batches---------------------
|
| 60 |
+
class Metrics_batch():
|
| 61 |
+
def __init__(self):
|
| 62 |
+
self.tprs = []
|
| 63 |
+
self.mean_fpr = np.linspace(0, 1, 100)
|
| 64 |
+
self.aucs = []
|
| 65 |
+
self.eers = []
|
| 66 |
+
self.aps = []
|
| 67 |
+
|
| 68 |
+
self.correct = 0
|
| 69 |
+
self.total = 0
|
| 70 |
+
self.losses = []
|
| 71 |
+
|
| 72 |
+
def update(self, label, output):
|
| 73 |
+
acc = self._update_acc(label, output)
|
| 74 |
+
if output.size(1) == 2:
|
| 75 |
+
prob = torch.softmax(output, dim=1)[:, 1]
|
| 76 |
+
else:
|
| 77 |
+
prob = output
|
| 78 |
+
#label = 1-label
|
| 79 |
+
#prob = torch.softmax(output, dim=1)[:, 1]
|
| 80 |
+
auc, eer = self._update_auc(label, prob)
|
| 81 |
+
ap = self._update_ap(label, prob)
|
| 82 |
+
|
| 83 |
+
return acc, auc, eer, ap
|
| 84 |
+
|
| 85 |
+
def _update_auc(self, lab, prob):
|
| 86 |
+
fpr, tpr, thresholds = metrics.roc_curve(lab.squeeze().cpu().numpy(),
|
| 87 |
+
prob.squeeze().cpu().numpy(),
|
| 88 |
+
pos_label=1)
|
| 89 |
+
if np.isnan(fpr[0]) or np.isnan(tpr[0]):
|
| 90 |
+
return -1, -1
|
| 91 |
+
|
| 92 |
+
auc = metrics.auc(fpr, tpr)
|
| 93 |
+
interp_tpr = np.interp(self.mean_fpr, fpr, tpr)
|
| 94 |
+
interp_tpr[0] = 0.0
|
| 95 |
+
self.tprs.append(interp_tpr)
|
| 96 |
+
self.aucs.append(auc)
|
| 97 |
+
|
| 98 |
+
# return auc
|
| 99 |
+
|
| 100 |
+
# EER
|
| 101 |
+
fnr = 1 - tpr
|
| 102 |
+
eer = fpr[np.nanargmin(np.absolute((fnr - fpr)))]
|
| 103 |
+
self.eers.append(eer)
|
| 104 |
+
|
| 105 |
+
return auc, eer
|
| 106 |
+
|
| 107 |
+
def _update_acc(self, lab, output):
|
| 108 |
+
_, prediction = torch.max(output, 1) # argmax
|
| 109 |
+
correct = (prediction == lab).sum().item()
|
| 110 |
+
accuracy = correct / prediction.size(0)
|
| 111 |
+
# self.accs.append(accuracy)
|
| 112 |
+
self.correct = self.correct+correct
|
| 113 |
+
self.total = self.total+lab.size(0)
|
| 114 |
+
return accuracy
|
| 115 |
+
|
| 116 |
+
def _update_ap(self, label, prob):
|
| 117 |
+
y_true = label.cpu().detach().numpy()
|
| 118 |
+
y_pred = prob.cpu().detach().numpy()
|
| 119 |
+
ap = metrics.average_precision_score(y_true,y_pred)
|
| 120 |
+
self.aps.append(ap)
|
| 121 |
+
|
| 122 |
+
return np.mean(ap)
|
| 123 |
+
|
| 124 |
+
def get_mean_metrics(self):
|
| 125 |
+
mean_acc, std_acc = self.correct/self.total, 0
|
| 126 |
+
mean_auc, std_auc = self._mean_auc()
|
| 127 |
+
mean_err, std_err = np.mean(self.eers), np.std(self.eers)
|
| 128 |
+
mean_ap, std_ap = np.mean(self.aps), np.std(self.aps)
|
| 129 |
+
|
| 130 |
+
return {'acc':mean_acc, 'auc':mean_auc, 'eer':mean_err, 'ap':mean_ap}
|
| 131 |
+
|
| 132 |
+
def _mean_auc(self):
|
| 133 |
+
mean_tpr = np.mean(self.tprs, axis=0)
|
| 134 |
+
mean_tpr[-1] = 1.0
|
| 135 |
+
mean_auc = metrics.auc(self.mean_fpr, mean_tpr)
|
| 136 |
+
std_auc = np.std(self.aucs)
|
| 137 |
+
return mean_auc, std_auc
|
| 138 |
+
|
| 139 |
+
def clear(self):
|
| 140 |
+
self.tprs.clear()
|
| 141 |
+
self.aucs.clear()
|
| 142 |
+
# self.accs.clear()
|
| 143 |
+
self.correct=0
|
| 144 |
+
self.total=0
|
| 145 |
+
self.eers.clear()
|
| 146 |
+
self.aps.clear()
|
| 147 |
+
self.losses.clear()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
# ------------ compute average metrics of all data ---------------------
|
| 151 |
+
class Metrics_all():
|
| 152 |
+
def __init__(self):
|
| 153 |
+
self.probs = []
|
| 154 |
+
self.labels = []
|
| 155 |
+
self.correct = 0
|
| 156 |
+
self.total = 0
|
| 157 |
+
|
| 158 |
+
def store(self, label, output):
|
| 159 |
+
prob = torch.softmax(output, dim=1)[:, 1]
|
| 160 |
+
_, prediction = torch.max(output, 1) # argmax
|
| 161 |
+
correct = (prediction == label).sum().item()
|
| 162 |
+
self.correct += correct
|
| 163 |
+
self.total += label.size(0)
|
| 164 |
+
self.labels.append(label.squeeze().cpu().numpy())
|
| 165 |
+
self.probs.append(prob.squeeze().cpu().numpy())
|
| 166 |
+
|
| 167 |
+
def get_metrics(self):
|
| 168 |
+
y_pred = np.concatenate(self.probs)
|
| 169 |
+
y_true = np.concatenate(self.labels)
|
| 170 |
+
# auc
|
| 171 |
+
fpr, tpr, thresholds = metrics.roc_curve(y_true,y_pred,pos_label=1)
|
| 172 |
+
auc = metrics.auc(fpr, tpr)
|
| 173 |
+
# eer
|
| 174 |
+
fnr = 1 - tpr
|
| 175 |
+
eer = fpr[np.nanargmin(np.absolute((fnr - fpr)))]
|
| 176 |
+
# ap
|
| 177 |
+
ap = metrics.average_precision_score(y_true,y_pred)
|
| 178 |
+
# acc
|
| 179 |
+
acc = self.correct / self.total
|
| 180 |
+
return {'acc':acc, 'auc':auc, 'eer':eer, 'ap':ap}
|
| 181 |
+
|
| 182 |
+
def clear(self):
|
| 183 |
+
self.probs.clear()
|
| 184 |
+
self.labels.clear()
|
| 185 |
+
self.correct = 0
|
| 186 |
+
self.total = 0
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
# only used to record a series of scalar value
|
| 190 |
+
class Recorder:
|
| 191 |
+
def __init__(self):
|
| 192 |
+
self.sum = 0
|
| 193 |
+
self.num = 0
|
| 194 |
+
def update(self, item, num=1):
|
| 195 |
+
if item is not None:
|
| 196 |
+
self.sum += item * num
|
| 197 |
+
self.num += num
|
| 198 |
+
def average(self):
|
| 199 |
+
if self.num == 0:
|
| 200 |
+
return None
|
| 201 |
+
return self.sum/self.num
|
| 202 |
+
def clear(self):
|
| 203 |
+
self.sum = 0
|
| 204 |
+
self.num = 0
|
metrics/registry.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Registry(object):
|
| 2 |
+
def __init__(self):
|
| 3 |
+
self.data = {}
|
| 4 |
+
|
| 5 |
+
def register_module(self, module_name=None):
|
| 6 |
+
def _register(cls):
|
| 7 |
+
name = module_name
|
| 8 |
+
if module_name is None:
|
| 9 |
+
name = cls.__name__
|
| 10 |
+
self.data[name] = cls
|
| 11 |
+
return cls
|
| 12 |
+
return _register
|
| 13 |
+
|
| 14 |
+
def __getitem__(self, key):
|
| 15 |
+
return self.data[key]
|
| 16 |
+
|
| 17 |
+
DETECTOR = Registry()
|
| 18 |
+
TRAINER = Registry()
|
| 19 |
+
LOSSFUNC = Registry()
|
metrics/utils.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn import metrics
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def parse_metric_for_print(metric_dict):
|
| 5 |
+
if metric_dict is None:
|
| 6 |
+
return "\n"
|
| 7 |
+
str = "\n"
|
| 8 |
+
str += "================================ Each dataset best metric ================================ \n"
|
| 9 |
+
for key, value in metric_dict.items():
|
| 10 |
+
if key != 'avg':
|
| 11 |
+
str= str+ f"| {key}: "
|
| 12 |
+
for k,v in value.items():
|
| 13 |
+
str = str + f" {k}={v} "
|
| 14 |
+
str= str+ "| \n"
|
| 15 |
+
else:
|
| 16 |
+
str += "============================================================================================= \n"
|
| 17 |
+
str += "================================== Average best metric ====================================== \n"
|
| 18 |
+
avg_dict = value
|
| 19 |
+
for avg_key, avg_value in avg_dict.items():
|
| 20 |
+
if avg_key == 'dataset_dict':
|
| 21 |
+
for key,value in avg_value.items():
|
| 22 |
+
str = str + f"| {key}: {value} | \n"
|
| 23 |
+
else:
|
| 24 |
+
str = str + f"| avg {avg_key}: {avg_value} | \n"
|
| 25 |
+
str += "============================================================================================="
|
| 26 |
+
return str
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_test_metrics(y_pred, y_true, img_names):
|
| 30 |
+
def get_video_metrics(image, pred, label):
|
| 31 |
+
result_dict = {}
|
| 32 |
+
new_label = []
|
| 33 |
+
new_pred = []
|
| 34 |
+
# print(image[0])
|
| 35 |
+
# print(pred.shape)
|
| 36 |
+
# print(label.shape)
|
| 37 |
+
for item in np.transpose(np.stack((image, pred, label)), (1, 0)):
|
| 38 |
+
|
| 39 |
+
s = item[0]
|
| 40 |
+
if '\\' in s:
|
| 41 |
+
parts = s.split('\\')
|
| 42 |
+
else:
|
| 43 |
+
parts = s.split('/')
|
| 44 |
+
a = parts[-2]
|
| 45 |
+
b = parts[-1]
|
| 46 |
+
|
| 47 |
+
if a not in result_dict:
|
| 48 |
+
result_dict[a] = []
|
| 49 |
+
|
| 50 |
+
result_dict[a].append(item)
|
| 51 |
+
image_arr = list(result_dict.values())
|
| 52 |
+
|
| 53 |
+
for video in image_arr:
|
| 54 |
+
pred_sum = 0
|
| 55 |
+
label_sum = 0
|
| 56 |
+
leng = 0
|
| 57 |
+
for frame in video:
|
| 58 |
+
pred_sum += float(frame[1])
|
| 59 |
+
label_sum += int(frame[2])
|
| 60 |
+
leng += 1
|
| 61 |
+
new_pred.append(pred_sum / leng)
|
| 62 |
+
new_label.append(int(label_sum / leng))
|
| 63 |
+
fpr, tpr, thresholds = metrics.roc_curve(new_label, new_pred)
|
| 64 |
+
v_auc = metrics.auc(fpr, tpr)
|
| 65 |
+
fnr = 1 - tpr
|
| 66 |
+
v_eer = fpr[np.nanargmin(np.absolute((fnr - fpr)))]
|
| 67 |
+
return v_auc, v_eer
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
y_pred = y_pred.squeeze()
|
| 71 |
+
# For UCF, where labels for different manipulations are not consistent.
|
| 72 |
+
y_true[y_true >= 1] = 1
|
| 73 |
+
# auc
|
| 74 |
+
fpr, tpr, thresholds = metrics.roc_curve(y_true, y_pred, pos_label=1)
|
| 75 |
+
auc = metrics.auc(fpr, tpr)
|
| 76 |
+
# eer
|
| 77 |
+
fnr = 1 - tpr
|
| 78 |
+
eer = fpr[np.nanargmin(np.absolute((fnr - fpr)))]
|
| 79 |
+
# ap
|
| 80 |
+
ap = metrics.average_precision_score(y_true, y_pred)
|
| 81 |
+
# acc
|
| 82 |
+
prediction_class = (y_pred > 0.5).astype(int)
|
| 83 |
+
correct = (prediction_class == np.clip(y_true, a_min=0, a_max=1)).sum().item()
|
| 84 |
+
acc = correct / len(prediction_class)
|
| 85 |
+
if type(img_names[0]) is not list:
|
| 86 |
+
# calculate video-level auc for the frame-level methods.
|
| 87 |
+
v_auc, _ = get_video_metrics(img_names, y_pred, y_true)
|
| 88 |
+
else:
|
| 89 |
+
# video-level methods
|
| 90 |
+
v_auc=auc
|
| 91 |
+
|
| 92 |
+
return {'acc': acc, 'auc': auc, 'eer': eer, 'ap': ap, 'pred': y_pred, 'video_auc': v_auc, 'label': y_true}
|
models/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
models/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#-*- coding: utf-8 -*-
|
| 2 |
+
from .builder import MODELS, build_model
|
| 3 |
+
from .networks.arcface import (
|
| 4 |
+
SimpleClassificationDF,
|
| 5 |
+
)
|
| 6 |
+
from .networks.mrsa_resnet import (
|
| 7 |
+
PoseResNet, resnet_spec, Bottleneck
|
| 8 |
+
)
|
| 9 |
+
from .networks.pose_hrnet import (
|
| 10 |
+
PoseHighResolutionNet
|
| 11 |
+
)
|
| 12 |
+
from .networks.xception import (
|
| 13 |
+
Xception
|
| 14 |
+
)
|
| 15 |
+
from.networks.pose_efficientNet import (
|
| 16 |
+
PoseEfficientNet
|
| 17 |
+
)
|
| 18 |
+
from .networks.common import *
|
| 19 |
+
from .utils import (
|
| 20 |
+
load_pretrained, freeze_backbone,
|
| 21 |
+
load_model, save_model, unfreeze_backbone,
|
| 22 |
+
preset_model,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__all__=['SimpleClassificationDF', 'PoseResNet', 'MODELS', 'build_model',
|
| 27 |
+
'load_pretrained', 'freeze_backbone', 'resnet_spec',
|
| 28 |
+
'load_model', 'save_model', 'unfreeze_backbone', 'Bottleneck',
|
| 29 |
+
'preset_model', 'PoseHighResolutionNet', 'Xception', 'PoseEfficientNet']
|
models/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (837 Bytes). View file
|
|
|
models/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (918 Bytes). View file
|
|
|
models/__pycache__/builder.cpython-310.pyc
ADDED
|
Binary file (1.68 kB). View file
|
|
|
models/__pycache__/builder.cpython-312.pyc
ADDED
|
Binary file (1.97 kB). View file
|
|
|
models/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (4.06 kB). View file
|
|
|
models/__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (7 kB). View file
|
|
|
models/builder.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#-*- coding: utf-8 -*-
|
| 2 |
+
from typing import Dict, Any, Optional
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
if not os.getcwd() in sys.path:
|
| 7 |
+
sys.path.append(os.getcwd())
|
| 8 |
+
|
| 9 |
+
from torch.nn import Sequential
|
| 10 |
+
|
| 11 |
+
from register.register import Registry, build_from_cfg
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def build_model_from_cfg(cfg, registry, default_args=None):
|
| 15 |
+
"""Build a PyTorch model from config dict(s). Different from
|
| 16 |
+
``build_from_cfg``, if cfg is a list, a ``nn.Sequential`` will be built.
|
| 17 |
+
Args:
|
| 18 |
+
cfg (dict, list[dict]): The config of modules, is is either a config
|
| 19 |
+
dict or a list of config dicts. If cfg is a list, a
|
| 20 |
+
the built modules will be wrapped with ``nn.Sequential``.
|
| 21 |
+
registry (:obj:`Registry`): A registry the module belongs to.
|
| 22 |
+
default_args (dict, optional): Default arguments to build the module.
|
| 23 |
+
Defaults to None.
|
| 24 |
+
Returns:
|
| 25 |
+
nn.Module: A built nn module.
|
| 26 |
+
"""
|
| 27 |
+
if isinstance(cfg, list):
|
| 28 |
+
modules = [
|
| 29 |
+
build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg
|
| 30 |
+
]
|
| 31 |
+
return Sequential(*modules)
|
| 32 |
+
else:
|
| 33 |
+
return build_from_cfg(cfg, registry, default_args)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
MODELS = Registry('model', build_func=build_model_from_cfg)
|
| 37 |
+
HEADS = MODELS
|
| 38 |
+
BACKBONES = MODELS
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def build_model(cfg: Dict,
|
| 42 |
+
model: Registry,
|
| 43 |
+
build_func=build_model_from_cfg,
|
| 44 |
+
default_args: Optional[Dict] = None) -> Any:
|
| 45 |
+
return build_func(cfg, model, default_args)
|
models/networks/__pycache__/arcface.cpython-310.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
models/networks/__pycache__/arcface.cpython-312.pyc
ADDED
|
Binary file (20.8 kB). View file
|
|
|
models/networks/__pycache__/common.cpython-310.pyc
ADDED
|
Binary file (2.66 kB). View file
|
|
|
models/networks/__pycache__/common.cpython-312.pyc
ADDED
|
Binary file (4.62 kB). View file
|
|
|
models/networks/__pycache__/efficientNet.cpython-310.pyc
ADDED
|
Binary file (16.6 kB). View file
|
|
|