serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
11.82k stars 2.02k forks source link

analyze prompts error on macos #337

Closed foxhlchen closed 2 years ago

foxhlchen commented 3 years ago

Having the following issue when calling DeepFace.analyze on MacOS (M1)

Traceback (most recent call last):
  File "detector.py", line 15, in <module>
    print(d.analyse('/Users/fox/Downloads/face1.jpeg'))
  File "detector.py", line 9, in analyse
    return self.deepface.analyze(image)
  File "/Users/fox/Workspace/topcoder/EdgeNet/src/Detector/deepface/DeepFace.py", line 345, in analyze
    models['emotion'] = build_model('Emotion')
  File "/Users/fox/Workspace/topcoder/EdgeNet/src/Detector/deepface/DeepFace.py", line 61, in build_model
    model = model()
  File "/Users/fox/Workspace/topcoder/EdgeNet/src/Detector/deepface/extendedmodels/Emotion.py", line 72, in loadModel
    model.load_weights(home+'/.deepface/weights/facial_expression_model_weights.h5', ['gender', 'race', 'emotion'])
  File "/Users/fox/miniforge3/envs/tf/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 2231, in load_weights
    hdf5_format.load_weights_from_hdf5_group_by_name(
  File "/Users/fox/miniforge3/envs/tf/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 783, in load_weights_from_hdf5_group_by_name
    raise ValueError('Layer #' + str(k) +' (named "' + layer.name +
ValueError: Layer #0 (named "conv2d_1"), weight <tf.Variable 'conv2d_1/kernel:0' shape=(3, 3, 64, 64) dtype=float32, numpy=
array([[[[-0.02086234, -0.05625644, -0.00626624, ..., -0.03595695,
           0.00585192, -0.05820507],
         [ 0.01381087, -0.06527329, -0.04389848, ...,  0.05507843,
           0.00153869,  0.02327423],
         [-0.0013235 ,  0.06148972, -0.06222842, ..., -0.00972166,
          -0.03019829, -0.01632849],
         ...,
         [-0.0146449 ,  0.01462121,  0.02522282, ...,  0.07199746,
           0.02014837,  0.06149526],
         [ 0.03064628, -0.02091366, -0.06904065, ..., -0.02996105,
           0.01008479, -0.01208215],
         [-0.01613922, -0.02132868, -0.05200129, ...,  0.04752426,
           0.03197227,  0.01768401]],

        [[-0.00015777, -0.00496528, -0.00109995, ...,  0.04904362,
          -0.04940901,  0.05586755],
         [ 0.02598667, -0.01215053, -0.04336546, ...,  0.05514053,
          -0.06938668, -0.0713841 ],
         [ 0.0473077 ,  0.02462931, -0.00883866, ...,  0.06511752,
           0.05405666,  0.0334084 ],
         ...,
         [ 0.01028818, -0.01725108,  0.07028757, ..., -0.02724935,
           0.068536  , -0.0408077 ],
         [-0.00794362,  0.00183721, -0.05948586, ...,  0.0176194 ,
           0.02379876, -0.00659902],
         [ 0.03169453,  0.03774358,  0.0325251 , ...,  0.01469382,
          -0.03394676, -0.00407045]],

        [[-0.0273643 ,  0.00159426,  0.01602215, ...,  0.00718629,
          -0.04424868,  0.00066246],
         [ 0.04139798, -0.02622314, -0.04400505, ..., -0.0658957 ,
          -0.01380349, -0.02427626],
         [-0.0189748 , -0.011688  ,  0.03213952, ...,  0.06120576,
           0.03494547, -0.05004603],
         ...,
         [ 0.02743882,  0.0674942 , -0.00787856, ...,  0.06780922,
          -0.02056105,  0.02191108],
         [-0.00505702, -0.04375469,  0.01821383, ..., -0.02773823,
           0.02162768,  0.01287097],
         [ 0.00075529,  0.07042241,  0.02580325, ...,  0.06476621,
          -0.05675643, -0.06466362]]],

       [[[ 0.04531901, -0.04465649, -0.04315037, ...,  0.05078991,
          -0.0632974 ,  0.06464013],
         [-0.03260736, -0.00052636, -0.01234747, ...,  0.05334353,
           0.06624313, -0.06071911],
         [-0.00611823,  0.0233738 ,  0.01217167, ...,  0.00123748,
          -0.0066421 ,  0.03227782],
         ...,
         [-0.0325602 ,  0.00289994, -0.06535114, ..., -0.05278994,
          -0.04024971, -0.03372858],
         [-0.06775841, -0.03244285,  0.03321224, ...,  0.05261267,
          -0.02126426, -0.03931945],
         [ 0.05411196, -0.06312913, -0.0505017 , ..., -0.03048392,
          -0.03228822, -0.00017051]],

        [[ 0.05060465, -0.02981969, -0.05785975, ...,  0.05826214,
          -0.02868264,  0.01635084],
         [-0.04327108,  0.06924585, -0.0410103 , ..., -0.03816406,
           0.00590227,  0.05128843],
         [ 0.05575742, -0.01187653,  0.0716894 , ...,  0.05663145,
           0.05854973,  0.00168919],
         ...,
         [-0.02872027,  0.04314317,  0.03115655, ..., -0.01340413,
           0.04166206,  0.03583142],
         [ 0.06476054,  0.03876674, -0.01121822, ..., -0.06631366,
           0.06622177, -0.04852439],
         [ 0.03792181, -0.03728428,  0.02922175, ...,  0.02205656,
           0.00835359,  0.05216409]],

        [[ 0.05794103,  0.03292401, -0.03333589, ...,  0.06756775,
          -0.05273232,  0.01171955],
         [-0.01107311,  0.01980612, -0.00672177, ...,  0.04678065,
           0.03335467, -0.04261657],
         [ 0.06494726, -0.00573986, -0.03849258, ..., -0.04550473,
          -0.06634317, -0.04329591],
         ...,
         [ 0.03373116,  0.00695797, -0.00147496, ...,  0.01384521,
           0.02554664,  0.06894864],
         [ 0.03158532, -0.02962082,  0.04331174, ..., -0.0597868 ,
          -0.00276659,  0.02435952],
         [ 0.00810775, -0.0474496 ,  0.02380694, ..., -0.0674839 ,
           0.01164252,  0.00853786]]],

       [[[-0.01134972, -0.0001376 , -0.04601875, ..., -0.04878812,
          -0.03350488, -0.0157208 ],
         [-0.02338841, -0.05685237,  0.02419554, ...,  0.01073109,
           0.01241015, -0.05071238],
         [ 0.06599793,  0.03410888, -0.05681775, ..., -0.05580318,
          -0.05696569, -0.01444257],
         ...,
         [-0.0065506 , -0.02986229,  0.05057219, ...,  0.04816242,
           0.04014563, -0.04819845],
         [ 0.04660761,  0.03184415,  0.05758336, ..., -0.05402254,
           0.00134342,  0.01556195],
         [-0.00594688, -0.01903034,  0.05849493, ..., -0.02801304,
           0.00369975, -0.01489554]],

        [[-0.00390606, -0.0037975 ,  0.0417928 , ..., -0.04689413,
          -0.04641125,  0.04797956],
         [-0.06628647,  0.06784622,  0.03216402, ...,  0.04104353,
          -0.00280688, -0.02106618],
         [ 0.00882947,  0.02383313, -0.03646319, ...,  0.01719814,
          -0.05532967, -0.02235215],
         ...,
         [-0.00905777,  0.00806126,  0.0462992 , ..., -0.04663364,
           0.06330539,  0.07182296],
         [-0.00073963, -0.03628545,  0.05800529, ...,  0.0238594 ,
           0.06832267, -0.04814957],
         [-0.04713637, -0.03325274,  0.00367402, ...,  0.07033014,
          -0.01217351, -0.0465862 ]],

        [[-0.06339995, -0.0576254 , -0.01985993, ...,  0.05367963,
          -0.0121949 ,  0.03212058],
         [-0.04796025,  0.00467728,  0.02538175, ...,  0.02007566,
          -0.07200739, -0.00880686],
         [ 0.01363119,  0.06837857,  0.04744736, ..., -0.06979366,
          -0.06247543, -0.07198586],
         ...,
         [ 0.04068924, -0.01108801, -0.02017355, ...,  0.00821816,
           0.02878902,  0.0211108 ],
         [-0.02688836, -0.01000979,  0.07162219, ..., -0.05771511,
          -0.0334087 ,  0.03025537],
         [-0.02171648,  0.07149892,  0.05364989, ..., -0.05677692,
          -0.01119273,  0.04695574]]]], dtype=float32)> has shape (3, 3, 64, 64), but the saved weight has shape (64, 1, 5, 5).

OS: macOS 11.5.2 20G95 arm64

Packages Installed

Package                       Version
----------------------------- -----------
absl-py                       0.13.0
aiohttp                       3.7.4.post0
appnope                       0.1.2
astor                         0.8.1
astunparse                    1.6.3
async-timeout                 3.0.1
attrs                         21.2.0
backcall                      0.2.0
backports.functools-lru-cache 1.6.4
blinker                       1.4
brotlipy                      0.7.0
cached-property               1.5.2
cachetools                    4.2.2
certifi                       2021.5.30
cffi                          1.14.6
chardet                       4.0.0
charset-normalizer            2.0.0
click                         8.0.1
cryptography                  3.4.7
dataclasses                   0.8
decorator                     5.0.9
filelock                      3.0.12
flatbuffers                   2.0
gast                          0.5.0
gdown                         3.13.0
google-auth                   1.35.0
google-auth-oauthlib          0.4.6
google-pasta                  0.2.0
grpcio                        1.38.1
h5py                          2.10.0
idna                          3.1
importlib-metadata            4.8.1
ipython                       7.27.0
jedi                          0.18.0
keras                         2.6.0
Keras-Preprocessing           1.1.2
Markdown                      3.3.4
matplotlib-inline             0.1.3
multidict                     5.1.0
numpy                         1.21.2
oauthlib                      3.1.1
opencv-python                 4.5.3.56
opt-einsum                    3.3.0
pandas                        1.3.2
parso                         0.8.2
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        8.3.2
pip                           20.2.4
prompt-toolkit                3.0.20
protobuf                      3.17.2
ptyprocess                    0.7.0
pyasn1                        0.4.8
pyasn1-modules                0.2.7
pycparser                     2.20
Pygments                      2.10.0
PyJWT                         2.1.0
pyOpenSSL                     20.0.1
PySocks                       1.7.1
python-dateutil               2.8.2
pytz                          2021.1
pyu2f                         0.1.5
requests                      2.26.0
requests-oauthlib             1.3.0
rsa                           4.7.2
scipy                         1.7.0
setuptools                    58.0.4
six                           1.16.0
tensorboard                   2.6.0
tensorboard-data-server       0.6.0
tensorboard-plugin-wit        1.8.0
tensorflow-addons-macos       0.1a3
tensorflow-estimator          2.5.0
tensorflow-macos              0.1a3
termcolor                     1.1.0
tqdm                          4.62.2
traitlets                     5.1.0
typeguard                     2.12.1
typing-extensions             3.10.0.0
urllib3                       1.26.6
wcwidth                       0.2.5
Werkzeug                      2.0.1
wheel                         0.37.0
wrapt                         1.12.1
yarl                          1.6.3
zipp                          3.5.0
serengil commented 3 years ago

I am currently using macbook pro with intel processor. I will not close this issue because someone with m1 should fix it. I cannot create same environment with you unfortunately.

golubev-n commented 2 years ago

I am using macos on (M1). i tried to use verify() method to compare images by path, it worked well, but it not compare base64 or array: ValueError: ('Invalid arguments passed to verify function: ', "data:image/jpeg;base64,/9j/4AAQSk...........

serengil commented 2 years ago

closed due to its inactivity

serengil commented 2 years ago

You should install m1 compatible tf version. Find out more on https://stackoverflow.com/questions/70324807/illegal-instruction-4-when-running-deepface/70440792?noredirect=1#comment125055180_70440792

foxhlchen commented 2 years ago

You should install m1 compatible tf version. Find out more on https://stackoverflow.com/questions/70324807/illegal-instruction-4-when-running-deepface/70440792?noredirect=1#comment125055180_70440792

I remember I tried but I can't remember how it didn't work. I will verify it if I have time. thanks!