issue 289

This commit is contained in:
Sefik Ilkin Serengil 2021-07-27 18:50:56 +03:00
parent d3e03c3e5a
commit 3962545c82
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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)