diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 9c14da1..a68ed2a 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -732,7 +732,7 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection #--------------------------------- #decide input shape - input_shape = input_shape_x, input_shape_y= functions.find_input_shape(model) + input_shape_x, input_shape_y = functions.find_input_shape(model) #detect and align img = functions.preprocess_face(img = img_path diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index c5c2be0..8cd298c 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -8,14 +8,16 @@ from pathlib import Path from deepface.detectors import FaceDetector import tensorflow as tf -tf_version = int(tf.__version__.split(".")[0]) +tf_version = tf.__version__ +tf_major_version = int(tf_version.split(".")[0]) +tf_minor_version = int(tf_version.split(".")[1]) -if tf_version == 1: +if tf_major_version == 1: import keras from keras.preprocessing.image import load_img, save_img, img_to_array from keras.applications.imagenet_utils import preprocess_input from keras.preprocessing import image -elif tf_version == 2: +elif tf_major_version == 2: from tensorflow import keras from tensorflow.keras.preprocessing.image import load_img, save_img, img_to_array from tensorflow.keras.applications.imagenet_utils import preprocess_input @@ -172,6 +174,16 @@ def find_input_shape(model): else: input_shape = input_shape[1:3] + #---------------------- + #issue 289: it seems that tf 2.5 expects you to resize images with (x, y) + #whereas its older versions expect (y, x) + + if tf_major_version == 2 and tf_minor_version >= 5: + x = input_shape[0]; y = input_shape[1] + input_shape = (y, x) + + #---------------------- + if type(input_shape) == list: #issue 197: some people got array here instead of tuple input_shape = tuple(input_shape)