mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 03:55:21 +00:00
patch: Greyscale image prediction condition.
This commit is contained in:
parent
8883b212b2
commit
fa4044adae
@ -38,14 +38,15 @@ class Demography(ABC):
|
|||||||
if not self.model_name: # Check if called from derived class
|
if not self.model_name: # Check if called from derived class
|
||||||
raise NotImplementedError("no model selected")
|
raise NotImplementedError("no model selected")
|
||||||
assert img_batch.ndim == 4, "expected 4-dimensional tensor input"
|
assert img_batch.ndim == 4, "expected 4-dimensional tensor input"
|
||||||
# Single image
|
|
||||||
if img_batch.shape[0] == 1:
|
if img_batch.shape[-1] != 3: # Handle grayscale image, check last dimension.
|
||||||
# Check if grayscale by checking last dimension, if not 3, it is grayscale.
|
# Check if grayscale by checking last dimension, if not 3, it is grayscale.
|
||||||
if img_batch.shape[-1] != 3:
|
img_batch = img_batch.squeeze(0) # Remove batch dimension
|
||||||
# Remove batch dimension
|
|
||||||
img_batch = img_batch.squeeze(0)
|
if img_batch.shape[0] == 1: # Single image
|
||||||
# Predict with legacy method.
|
# Predict with legacy method.
|
||||||
return self.model(img_batch, training=False).numpy()[0, :]
|
return self.model(img_batch, training=False).numpy()[0, :]
|
||||||
|
|
||||||
# Batch of images
|
# Batch of images
|
||||||
# Predict with batch prediction
|
# Predict with batch prediction
|
||||||
return self.model.predict_on_batch(img_batch)
|
return self.model.predict_on_batch(img_batch)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user