Insightface人脸检测返回空列表问题排查求助
Insightface人脸检测返回空列表问题排查求助
我最近用Insightface做图片人脸检测时碰上个棘手的问题——检测结果直接返回了空列表,完全识别不到图片里的人脸。我检查了代码的基本逻辑,也确认了图片能正常读取,但还是找不到问题根源,想请大家帮忙一起排查下哪里出了问题?
我的代码
import cv2 from insightface.app import FaceAnalysis from insightface.data import get_image app = FaceAnalysis(providers=['CUDAExecutionProvider', 'CPUExecutionProvider']) app.prepare(ctx_id=0, det_size=(640, 640)) img = cv2.imread("face.jpg") faces = app.get(img) print("============================================================") print(faces) print("============================================================")
输入图片
输入的是一张包含正面人脸的图片,人物面部清晰,没有明显遮挡。
运行输出
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CUDAExecutionProvider': {'device_id': '0', 'has_user_compute_stream': '0', 'cudnn_conv1d_pad_to_nc1d': '0', 'user_compute_stream': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'enable_cuda_graph': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'do_copy_in_default_stream': '1', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'tunable_op_tuning_enable': '0', 'tunable_op_max_tuning_duration_ms': '0', 'enable_skip_layer_norm_strict_mode': '0', 'prefer_nhwc': '0', 'use_ep_level_unified_stream': '0', 'use_tf32': '1', 'sdpa_kernel': '0'}, 'CPUExecutionProvider': {}} find model: C:\Users\iii_a/.insightface\models\buffalo_l\1k3d68.onnx landmark_3d_68 ['None', 3, 192, 192] 0.0 1.0 Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CUDAExecutionProvider': {'device_id': '0', 'has_user_compute_stream': '0', 'cudnn_conv1d_pad_to_nc1d': '0', 'user_compute_stream': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'enable_cuda_graph': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'do_copy_in_default_stream': '1', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'tunable_op_tuning_enable': '0', 'tunable_op_max_tuning_duration_ms': '0', 'enable_skip_layer_norm_strict_mode': '0', 'prefer_nhwc': '0', 'use_ep_level_unified_stream': '0', 'use_tf32': '1', 'sdpa_kernel': '0'}, 'CPUExecutionProvider': {}} find model: C:\Users\iii_a/.insightface\models\buffalo_l\2d106det.onnx landmark_2d_106 ['None', 3, 192, 192] 0.0 1.0 Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CUDAExecutionProvider': {'device_id': '0', 'has_user_compute_stream': '0', 'cudnn_conv1d_pad_to_nc1d': '0', 'user_compute_stream': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'enable_cuda_graph': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'do_copy_in_default_stream': '1', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'tunable_op_tuning_enable': '0', 'tunable_op_max_tuning_duration_ms': '0', 'enable_skip_layer_norm_strict_mode': '0', 'prefer_nhwc': '0', 'use_ep_level_unified_stream': '0', 'use_tf32': '1', 'sdpa_kernel': '0'}, 'CPUExecutionProvider': {}} find model: C:\Users\iii_a/.insightface\models\buffalo_l\det_10g.onnx detection [1, 3, '?', '?'] 127.5 128.0 Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CUDAExecutionProvider': {'device_id': '0', 'has_user_compute_stream': '0', 'cudnn_conv1d_pad_to_nc1d': '0', 'user_compute_stream': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'enable_cuda_graph': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'do_copy_in_default_stream': '1', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'tunable_op_tuning_enable': '0', 'tunable_op_max_tuning_duration_ms': '0', 'enable_skip_layer_norm_strict_mode': '0', 'prefer_nhwc': '0', 'use_ep_level_unified_stream': '0', 'use_tf32': '1', 'sdpa_kernel': '0'}, 'CPUExecutionProvider': {}} find model: C:\Users\iii_a/.insightface\models\buffalo_l\genderage.onnx genderage ['None', 3, 96, 96] 0.0 1.0 Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CUDAExecutionProvider': {'device_id': '0', 'has_user_compute_stream': '0', 'cudnn_conv1d_pad_to_nc1d': '0', 'user_compute_stream': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'enable_cuda_graph': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'do_copy_in_default_stream': '1', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'tunable_op_tuning_enable': '0', 'tunable_op_max_tuning_duration_ms': '0', 'enable_skip_layer_norm_strict_mode': '0', 'prefer_nhwc': '0', 'use_ep_level_unified_stream': '0', 'use_tf32': '1', 'sdpa_kernel': '0'}, 'CPUExecutionProvider': {}} find model: C:\Users\iii_a/.insightface\models\buffalo_l\w600k_r50.onnx recognition ['None', 3, 112, 112] 127.5 127.5 set det-size: (640, 640) ============================================================ [] ============================================================
我的运行环境
- 操作系统:Windows 10
- GPU:RTX 4090 24G
- Python版本:3.9.21
- 核心依赖包版本:
Package Version ---------------------- ----------- albucore 0.0.23 albumentations 2.0.0 annotated-types 0.7.0 antlr4-python3-runtime 4.9.3 certifi 2024.12.14 charset-normalizer 3.4.1 colorama 0.4.6 coloredlogs 15.0.1 contourpy 1.3.0 cycler 0.12.1 Cython 3.0.11 easydict 1.13 eval_type_backport 0.2.2 filelock 3.16.1 flatbuffers 24.12.23 fonttools 4.55.3 fsspec 2024.12.0 humanfriendly 10.0 idna 3.10 imageio 2.37.0 importlib_resources 6.5.2 insightface 0.7.3 Jinja2 3.1.5 joblib 1.4.2 kiwisolver 1.4.7 lap 0.5.12 lazy_loader 0.4 MarkupSafe 3.0.2 matplotlib 3.9.4 mpmath 1.3.0 networkx 3.2.1 numpy 2.0.2 omegaconf 2.3.0 onnx 1.17.0 onnxruntime-gpu 1.19.2 opencv-python 4.11.0.86 opencv-python-headless 4.11.0.86 packaging 24.2 pandas 2.2.3 pillow 11.1.0 pip 24.2 prettytable 3.12.0 protobuf 5.29.3 psutil 6.1.1 py-cpuinfo 9.0.0 pydantic 2.10.5 pydantic_core 2.27.2 pyparsing 3.2.1 pyreadline3 3.5.4 python-dateutil 2.9.0.post0 pytz 2024.2 PyYAML 6.0.2 requests 2.32.3 scikit-image 0.24.0 scikit-learn 1.6.1 scipy 1.13.1 seaborn 0.13.2 setuptools 75.1.0 simsimd 6.2.1 six 1.17.0 stringzilla 3.11.3 sympy 1.13.1 threadpoolctl 3.5.0 tifffile 2024.8.30 torch 2.5.1 torchvision 0.20.1 tqdm 4.67.1 typing_extensions 4.12.2 tzdata 2024.2 ultralytics 8.3.64 ultralytics-thop 2.0.14 urllib3 2.3.0 wcwidth 0.2.13 wheel 0.44.0 zipp 3.21.0
我已经确认过cv2.imread("face.jpg")没有返回None,图片确实被正常读取了,模型加载的日志看起来也没有报错,但就是检测不到人脸。有没有朋友遇到过类似情况,或者能给我一些排查的方向?
备注:内容来源于stack exchange,提问作者Nick Wu




