SCLBD / DeepfakeBench

A comprehensive benchmark of deepfake detection
Other
487 stars 64 forks source link

Key Error in test.py #78

Closed HUiTUi closed 2 months ago

HUiTUi commented 4 months ago

I have run the scripts in the README.md

python3 training/test.py \
--detector_path ./training/config/detector/xception.yaml \
--test_dataset "Celeb-DF-v2" \
--weights_path ./training/weights/xception_best.pth

the error are follows:

['in_channels', 'out_channels', 'kernel_size', 'stride', 'padding', 'dilation', 'groups', 'bias', 'padding_mode', 'device', 'dtype']
spatial_count=0 keep_stride_count=0
Traceback (most recent call last):
  File "/sharefiles/sd/DeepfakeBench-main/training/test.py", line 296, in <module>
    main()
  File "/sharefiles/sd//DeepfakeBench-main/training/test.py", line 274, in main
    test_data_loaders = prepare_testing_data(config)
  File "/sharefiles/sd//DeepfakeBench-main/training/test.py", line 180, in prepare_testing_data
    test_data_loaders[one_test_name] = get_test_data_loader(config, one_test_name)
  File "/sharefiles/sd//DeepfakeBench-main/training/test.py", line 163, in get_test_data_loader
    test_set = DeepfakeAbstractBaseDataset(
  File "/sharefiles/sd//DeepfakeBench-main/training/dataset/abstract_dataset.py", line 94, in __init__
    image_list, label_list, name_list = self.collect_img_and_label_for_one_dataset(one_data)
  File "/sharefiles/sd//DeepfakeBench-main/training/dataset/abstract_dataset.py", line 156, in collect_img_and_label_for_one_dataset
    if not os.path.exists(self.config['dataset_json_folder']):
KeyError: 'dataset_json_folder'

I think that may be an error writing in the yaml, what is the right yaml?

HUiTUi commented 4 months ago

In your xception.yaml, there is no dataset_json_folder

# log dir 
log_dir: ./logs/testing_bench

# model setting
pretrained: ./training/pretrained/xception-b5690688.pth   # path to a pre-trained model, if using one
model_name: xception   # model name
backbone_name: xception  # backbone name

#backbone setting
backbone_config:
  mode: original
  num_classes: 2
  inc: 3
  dropout: false

# dataset
all_dataset: [FaceForensics++, FF-F2F, FF-DF, FF-FS, FF-NT, FaceShifter, DeepFakeDetection, Celeb-DF-v1, Celeb-DF-v2, DFDCP, DFDC, DeeperForensics-1.0, UADFV]
train_dataset: [FaceForensics++]
test_dataset: [FaceForensics++]

compression: c23  # compression-level for videos
train_batchSize: 32   # training batch size
test_batchSize: 32   # test batch size
workers: 8   # number of data loading workers
frame_num: {'train': 32, 'test': 32}   # number of frames to use per video in training and testing
resolution: 256   # resolution of output image to network
with_mask: false   # whether to include mask information in the input
with_landmark: false   # whether to include facial landmark information in the input

# data augmentation
use_data_augmentation: true  # Add this flag to enable/disable data augmentation
data_aug:
  flip_prob: 0.5
  rotate_prob: 0.0
  rotate_limit: [-10, 10]
  blur_prob: 0.5
  blur_limit: [3, 7]
  brightness_prob: 0.5
  brightness_limit: [-0.1, 0.1]
  contrast_limit: [-0.1, 0.1]
  quality_lower: 40
  quality_upper: 100

# mean and std for normalization
mean: [0.5, 0.5, 0.5]
std: [0.5, 0.5, 0.5]

# optimizer config
optimizer:
  # choose between 'adam' and 'sgd'
  type: adam
  adam:
    lr: 0.0002  # learning rate
    beta1: 0.9  # beta1 for Adam optimizer
    beta2: 0.999 # beta2 for Adam optimizer
    eps: 0.00000001  # epsilon for Adam optimizer
    weight_decay: 0.0005  # weight decay for regularization
    amsgrad: false
  sgd:
    lr: 0.0002  # learning rate
    momentum: 0.9  # momentum for SGD optimizer
    weight_decay: 0.0005  # weight decay for regularization

# training config
lr_scheduler: null   # learning rate scheduler
nEpochs: 10   # number of epochs to train for
start_epoch: 0   # manual epoch number (useful for restarts)
save_epoch: 1   # interval epochs for saving models
rec_iter: 100   # interval iterations for recording
logdir: ./logs   # folder to output images and logs
manualSeed: 1024   # manual seed for random number generation
save_ckpt: true   # whether to save checkpoint
save_feat: true   # whether to save features

# loss function
loss_func: cross_entropy   # loss function to use
losstype: null

# metric
metric_scoring: auc   # metric for evaluation (auc, acc, eer, ap)

# cuda

cuda: true   # whether to use CUDA acceleration
cudnn: true   # whether to use CuDNN for convolution operations
emanalattas commented 4 months ago

I faced the same error. This is the solution: In this file: DeepfakeBench/training/config/test_config.yaml

You will find this line: dataset_json_folder: 'preprocessing/dataset_json_V3'

remove ” _V3”

it will work.

bendoesai commented 3 months ago

I faced this issue as well, but what I noticed is that test_config was not referenced in test.py. I added a second file open similar to what train.py does:

with open(args.detector_path, 'r') as f:
    config = yaml.safe_load(f)
with open(os.getcwd()+'\\config\\test_config.yaml', 'r') as f:
    config2 = yaml.safe_load(f)
config.update(config2)