DeepFace批量图像分析测试函数执行失败问题求助
DeepFace批量图像分析测试函数执行失败问题求助
问题描述
我在尝试让DeepFace的图像分析批量处理功能正常工作时遇到了麻烦。我想传入一个图像列表,获取每张图像的种族、性别和年龄预测结果。调用deepfacemaster/tests/test_analyze.py中的测试函数时,非批量的函数能正常运行,但批量相关的函数全部失败了。
环境信息
我使用的Python版本是3.11.9,已安装的依赖包及版本如下:
Package Version ---------------------------- --------- absl-py 2.1.0 albucore 0.0.23 albumentations 2.0.5 annotated-types 0.7.0 astunparse 1.6.3 attrs 25.1.0 beautifulsoup4 4.13.3 blinker 1.6.2 certifi 2025.1.31 cffi 1.17.1 charset-normalizer 3.4.1 click 8.1.6 cmake 3.31.6 colorama 0.4.6 coloredlogs 15.0.1 contourpy 1.3.1 cycler 0.12.1 Cython 3.0.12 deepface 0.0.93 dlib 19.24.6 easydict 1.13 et-xmlfile 1.1.0 exif 1.6.1 extensions 0.4 filelock 3.17.0 fire 0.7.0 Flask 2.3.2 flask-cors 5.0.1 flatbuffers 25.2.10 fonttools 4.56.0 fsspec 2025.3.0 gast 0.6.0 gdown 5.2.0 google-pasta 0.2.0 grpcio 1.70.0 gunicorn 23.0.0 h5py 3.13.0 humanfriendly 10.0 idna 3.10 imageio 2.37.0 insightface 0.7.3 itsdangerous 2.1.2 jax 0.5.2 jaxlib 0.5.1 Jinja2 3.1.2 joblib 1.4.2 keras 3.8.0 kiwisolver 1.4.8 lazy_loader 0.4 libclang 18.1.1 lz4 4.4.3 Markdown 3.7 markdown-it-py 3.0.0 MarkupSafe 2.1.3 matplotlib 3.10.1 mdurl 0.1.2 mediapipe 0.10.21 ml-dtypes 0.4.1 mpmath 1.3.0 mtcnn 1.0.0 names 0.3.0 namex 0.0.8 networkx 3.4.2 numpy 1.26.4 onnx 1.17.0 onnxruntime 1.21.0 opencv-contrib-python 4.11.0.86 opencv-python 4.11.0.86 opencv-python-headless 4.11.0.86 openpyxl 3.1.2 opt_einsum 3.4.0 optree 0.14.1 packaging 24.2 pandas 2.2.3 Pillow 10.1.0 pip 25.0.1 plum-py 0.8.7 prettytable 3.15.1 protobuf 4.25.6 psutil 7.0.0 py-cpuinfo 9.0.0 pycparser 2.22 pydantic 2.10.6 pydantic_core 2.27.2 Pygments 2.19.1 pyparsing 3.2.1 pyreadline3 3.5.4 PySocks 1.7.1 python-dateutil 2.8.2 pytz 2023.3 PyYAML 6.0.2 requests 2.32.3 retina-face 0.0.17 rich 13.9.4 scikit-image 0.25.2 scikit-learn 1.6.1 scipy 1.15.2 seaborn 0.13.2 sentencepiece 0.2.0 setuptools 65.5.0 simsimd 6.2.1 six 1.16.0 sounddevice 0.5.1 soupsieve 2.6 stringzilla 3.12.3 sympy 1.13.1 tensorboard 2.18.0 tensorboard-data-server 0.7.2 tensorflow 2.18.0 tensorflow_intel 2.18.0 tensorflow-io-gcs-filesystem 0.31.0 termcolor 2.5.0 tf_keras 2.18.0 threadpoolctl 3.5.0 tifffile 2025.2.18 torch 2.6.0 torchvision 0.21.0 tqdm 4.67.1 typing 3.7.4.3 typing_extensions 4.12.2 tzdata 2023.3 ultralytics 8.3.86 ultralytics-thop 2.0.14 urllib3 2.3.0 wcwidth 0.2.13 Werkzeug 2.3.6 wheel 0.45.1 wrapt 1.17.2 wsq 0.5
测试代码
我运行了以下测试代码:
from test_analyze import test_standard_analyze, test_analyze_for_preloaded_image, test_analyze_for_batched_image_as_list_of_string, test_analyze_for_batched_image_as_list_of_numpy, test_analyze_for_numpy_batched_image test_standard_analyze() test_analyze_for_preloaded_image() test_analyze_for_batched_image_as_list_of_string() print(logger)
错误信息
前两个非批量函数运行正常,但test_analyze_for_batched_image_as_list_of_string()执行失败,报错如下:
2025-03-11 10:01:44.538586: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-03-11 10:01:48.371800: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. WARNING:tensorflow:From C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead. 2025-03-11 10:02:07.645567: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 25-03-11 10:02:16 - ✅ test standard analyze done 25-03-11 10:02:21 - ✅ test analyze for pre-loaded image done Traceback (most recent call last): File "c:\Users\mvernick\Documents\deepface-master\deepface-master\tests\tests.py", line 9, in <module> test_analyze_for_batched_image_as_list_of_string() File "c:\Users\mvernick\Documents\deepface-master\deepface-master\tests\test_analyze.py", line 162, in test_analyze_for_batched_image_as_list_of_string demography_batch = DeepFace.analyze(img_path=img_paths, silent=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\deepface\DeepFace.py", line 253, in analyze return demography.analyze( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\deepface\modules\demography.py", line 123, in analyze img_objs = detection.extract_faces( ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\deepface\modules\detection.py", line 83, in extract_faces img, img_name = image_utils.load_image(img_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\deepface\commons\image_utils.py", line 81, in load_image raise ValueError(f"img must be numpy array or str but it is {type(img)}") ValueError: img must be numpy array or str but it is <class 'list'>
接着运行test_analyze_for_batched_image_as_list_of_numpy()也失败了,报错如下:
from test_analyze import test_standard_analyze, test_analyze_for_preloaded_image, test_analyze_for_batched_image_as_list_of_string, test_analyze_for_batched_image_as_list_of_numpy, test_analyze_for_numpy_batched_image test_analyze_for_batched_image_as_list_of_numpy() print(logger)
2025-03-11 10:07:14.324483: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-03-11 10:07:16.999841: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. WARNING:tensorflow:From C:\Users\mvernick\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead. Traceback (most recent call last): File "c:\Users\mvernick\Documents\deepface-master\deepface-master\tests\tests.py", line 11, in <module> test_analyze_for_batched_image_as_list_of_numpy() File "c:\Users\mvernick\Documents\deepface-mas
备注:内容来源于stack exchange,提问作者matth3wV
相关产品推荐
相关产品推荐

