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
14.35k stars 2.2k forks source link

ValueError occured when I use DeepID to verify faces #705

Closed Imkyeongbin closed 1 year ago

Imkyeongbin commented 1 year ago
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_19024\3726206110.py in 
      3 
      4 for model in models:
----> 5     result = DeepFace.verify(image_paths[0], image_paths[1], detector_backend='mediapipe', model_name=model)
      6     ordered = OrderedDict(result)
      7     ordered.move_to_end('distance')

c:\Users\_\.conda\envs\cp2\lib\site-packages\deepface\DeepFace.py in verify(img1_path, img2_path, model_name, detector_backend, distance_metric, enforce_detection, align, normalization)
    173                 detector_backend="skip",
    174                 align=align,
--> 175                 normalization=normalization,
    176             )
    177 

c:\Users\_\.conda\envs\cp2\lib\site-packages\deepface\DeepFace.py in represent(img_path, model_name, enforce_detection, detector_backend, align, normalization)
    676         if "keras" in str(type(model)):
    677             # new tf versions show progress bar and it is annoying
--> 678             embedding = model.predict(img, verbose=0)[0].tolist()
    679         else:
    680             # SFace and Dlib are not keras models and no verbose arguments

c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\training.py in tf__predict_function(iterator)
     13                 try:
     14                     do_return = True
---> 15                     retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
     16                 except:
     17                     do_return = False

ValueError: in user code:

    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\training.py", line 1845, in predict_function  *
        return step_function(self, iterator)
    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\training.py", line 1834, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\training.py", line 1823, in run_step  **
        outputs = model.predict_step(data)
    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\training.py", line 1791, in predict_step
        return self(x, training=False)
    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
        raise e.with_traceback(filtered_tb) from None
    File "c:\Users\_\.conda\envs\cp2\lib\site-packages\keras\engine\input_spec.py", line 264, in assert_input_compatibility
        raise ValueError(f'Input {input_index} of layer "{layer_name}" is '

    ValueError: Input 0 of layer "model_3" is incompatible with the layer: expected shape=(None, 55, 47, 3), found shape=(None, 47, 55, 3)

I guess it will be needed to add a code to transpose img to the right shape of DeepID in the source.

Environment : python 3.7, windows 10 64bit

serengil commented 1 year ago

would you please use the source code instead of pip version? this should be sorted in source code but not published in pip.

git clone https://github.com/serengil/deepface.git
cd deepface
pip install -e .