I am having trouble getting image analysis batch processing to work. I would like to send a list of images to DeepFace to get a list of race, gender, and age predictions. I am calling test functions from deepfacemaster/tests/test_analyze.py and the batch specific functions are failing.
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
When I run:
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)
The first 2 non-batch functions work then test_analyze_for_batched_image_as_list_of_string()
fails with:
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'>
The next test is test_analyze_for_batched_image_as_list_of_numpy()
which fails with:
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-master\deepface-master\tests\test_analyze.py", line 190, in test_analyze_for_batched_image_as_list_of_numpy
demography_batch = DeepFace.analyze(img_path=imgs, 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'>
Finally, the last test is test_analyze_for_numpy_batched_image()
which gives me the error too many values to unpack
.
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_numpy_batched_image()
print(logger)
2025-03-11 10:08:44.611222: 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:08:46.439427: 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 13, in <module>
test_analyze_for_numpy_batched_image()
File "c:\Users\mvernick\Documents\deepface-master\deepface-master\tests\test_analyze.py", line 226, in test_analyze_for_numpy_batched_image
demography_batch = DeepFace.analyze(img, 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 88, in extract_faces
height, width, _ = img.shape
^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 3)
What am I doing wrong and how can I remedy these errors?
Batch input support is added recently into deepface. It's available in source code but it's not pushed to pip yet. So, if you are using pip package of deepface instead of source code, then it's normal to have this error.
# uninstall existing deepface package
pip uninstall deepface
# pull the latest source code
git clone https://github.com/serengil/deepface.git
# go to deepface source code folder
cd deepface
# install it from source code instead of pip package
pip install -e .
Then, you can run your tests again.