minivision-ai / Silent-Face-Anti-Spoofing

静默活体检测(Silent-Face-Anti-Spoofing)
Apache License 2.0
1.36k stars 453 forks source link

训练后的模型使用报错 #124

Open wy353208214 opened 1 year ago

wy353208214 commented 1 year ago
  1. 模型配置
    {
    "lr": 0.1,
    "milestones": [10, 15, 22],
    "gamma": 0.1,
    "epochs": 25,
    "momentum": 0.9,
    "batch_size": 1024,
    "num_classes": 3,
    "input_channel": 3,
    "embedding_size": 128,
    "train_root_path": "./datasets/rgb_image",
    "snapshot_dir_path": "./saved_logs/snapshot",
    "log_path": "./saved_logs/jobs/Anti_Spoofing_2.7_80x80/Oct18_11-21-58 ",
    "board_loss_every": 10,
    "save_every": 30,
    "devices": [0],
    "patch_info": "2.7_80x80",
    "input_size": [80, 80],
    "kernel_size": [5, 5],
    "device": "cpu",
    "ft_height": 10,
    "ft_width": 10,
    "model_path": "./saved_logs/snapshot/Anti_Spoofing_2.7_80x80",
    "job_name": "Anti_Spoofing_2.7_80x80"
    }

生成的模型文件: Snipaste_2023-10-18_11-44-40

  1. 这里的模型需要改文件名吗,替换之后报如下错误:
    Traceback (most recent call last):
    File "/Users/steven/Dev_Project/Python/Silent-Face-Anti-Spoofing/test.py", line 111, in <module>
    test(args.image_name, args.model_dir, args.device_id)
    File "/Users/steven/Dev_Project/Python/Silent-Face-Anti-Spoofing/test.py", line 61, in test
    prediction += model_test.predict(img, os.path.join(model_dir, model_name))
    File "/Users/steven/Dev_Project/Python/Silent-Face-Anti-Spoofing/src/anti_spoof_predict.py", line 88, in predict
    self._load_model(model_path)
    File "/Users/steven/Dev_Project/Python/Silent-Face-Anti-Spoofing/src/anti_spoof_predict.py", line 77, in _load_model
    self.model.load_state_dict(new_state_dict)
    File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2041, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
    RuntimeError: Error(s) in loading state_dict for MiniFASNet:
        Missing key(s) in state_dict: "conv1.conv.weight", "conv1.bn.weight", "conv1.bn.bias", "conv1.bn.running_mean", "conv1.bn.running_var", "conv1.prelu.weight", "conv2_dw.conv.weight", "conv2_dw.bn.weight", "conv2_dw.bn.bias", "conv2_dw.bn.running_mean", "conv2_dw.bn.running_var", "conv2_dw.prelu.weight", "conv_23.conv.conv.weight", "conv_23.conv.bn.weight", "conv_23.conv.bn.bias", "conv_23.conv.bn.running_mean", "conv_23.conv.bn.running_var", "conv_23.conv.prelu.weight", "conv_23.conv_dw.conv.weight", "conv_23.conv_dw.bn.weight", "conv_23.conv_dw.bn.bias", "conv_23.conv_dw.bn.running_mean", "conv_23.conv_dw.bn.running_var", "conv_23.conv_dw.prelu.weight", "conv_23.project.conv.weight", "conv_23.project.bn.weight", "conv_23.project.bn.bias", "conv_23.project.bn.running_mean", "conv_23.project.bn.running_var", "conv_3.model.0.conv.conv.weight", "conv_3.model.0.conv.bn.weight", "conv_3.model.0.conv.bn.bias", "conv_3.model.0.conv.bn.running_mean", "conv_3.model.0.conv.bn.running_var", "conv_3.model.0.conv.prelu.weight", "conv_3.model.0.conv_dw.conv.weight", "conv_3.model.0.conv_dw.bn.weight", "conv_3.model.0.conv_dw.bn.bias", "conv_3.model.0.conv_dw.bn.running_mean", "conv_3.model.0.conv_dw.bn.running_var", "conv_3.model.0.conv_dw.prelu.weight",
wy353208214 commented 1 year ago

参考这里

43

wy353208214 commented 1 year ago

训练后,生成的多个model,选用哪个? Snipaste_2023-10-18_17-23-05